From c171f8a54541eac99f9c9f80aabb811b515b0376 Mon Sep 17 00:00:00 2001 From: 123456wda Date: Fri, 15 May 2026 10:59:51 +0800 Subject: [PATCH] fix(s06): wire compact tool's focus parameter into auto_compact The compact tool schema declares a "focus" parameter ("What to preserve in the summary") but the handler ignored it entirely -- the parameter was never passed to auto_compact(). Now the focus value is captured from block.input and included in the summarization prompt so the LLM knows what details to prioritize when compressing the conversation. --- agents/s06_context_compact.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/agents/s06_context_compact.py b/agents/s06_context_compact.py index 0fde70e..79bbe92 100644 --- a/agents/s06_context_compact.py +++ b/agents/s06_context_compact.py @@ -100,7 +100,7 @@ def micro_compact(messages: list) -> list: # -- Layer 2: auto_compact - save transcript, summarize, replace messages -- -def auto_compact(messages: list) -> list: +def auto_compact(messages: list, focus: str = "") -> list: # Save full transcript to disk TRANSCRIPT_DIR.mkdir(exist_ok=True) transcript_path = TRANSCRIPT_DIR / f"transcript_{int(time.time())}.jsonl" @@ -110,12 +110,16 @@ def auto_compact(messages: list) -> list: print(f"[transcript saved: {transcript_path}]") # Ask LLM to summarize conversation_text = json.dumps(messages, default=str)[-80000:] + focus_instruction = "" + if focus: + focus_instruction = f" Pay special attention to preserving details about: {focus}." response = client.messages.create( model=MODEL, messages=[{"role": "user", "content": "Summarize this conversation for continuity. Include: " "1) What was accomplished, 2) Current state, 3) Key decisions made. " - "Be concise but preserve critical details.\n\n" + conversation_text}], + "Be concise but preserve critical details." + f"{focus_instruction}\n\n" + conversation_text}], max_tokens=2000, ) summary = next((block.text for block in response.content if hasattr(block, "text")), "") @@ -215,10 +219,12 @@ def agent_loop(messages: list): return results = [] manual_compact = False + compact_focus = "" for block in response.content: if block.type == "tool_use": if block.name == "compact": manual_compact = True + compact_focus = block.input.get("focus", "") output = "Compressing..." else: handler = TOOL_HANDLERS.get(block.name) @@ -233,7 +239,7 @@ def agent_loop(messages: list): # Layer 3: manual compact triggered by the compact tool if manual_compact: print("[manual compact]") - messages[:] = auto_compact(messages) + messages[:] = auto_compact(messages, focus=compact_focus) return