mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-06-21 04:33:36 +08:00
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.
This commit is contained in:
@@ -100,7 +100,7 @@ def micro_compact(messages: list) -> list:
|
|||||||
|
|
||||||
|
|
||||||
# -- Layer 2: auto_compact - save transcript, summarize, replace messages --
|
# -- 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
|
# Save full transcript to disk
|
||||||
TRANSCRIPT_DIR.mkdir(exist_ok=True)
|
TRANSCRIPT_DIR.mkdir(exist_ok=True)
|
||||||
transcript_path = TRANSCRIPT_DIR / f"transcript_{int(time.time())}.jsonl"
|
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}]")
|
print(f"[transcript saved: {transcript_path}]")
|
||||||
# Ask LLM to summarize
|
# Ask LLM to summarize
|
||||||
conversation_text = json.dumps(messages, default=str)[-80000:]
|
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(
|
response = client.messages.create(
|
||||||
model=MODEL,
|
model=MODEL,
|
||||||
messages=[{"role": "user", "content":
|
messages=[{"role": "user", "content":
|
||||||
"Summarize this conversation for continuity. Include: "
|
"Summarize this conversation for continuity. Include: "
|
||||||
"1) What was accomplished, 2) Current state, 3) Key decisions made. "
|
"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,
|
max_tokens=2000,
|
||||||
)
|
)
|
||||||
summary = next((block.text for block in response.content if hasattr(block, "text")), "")
|
summary = next((block.text for block in response.content if hasattr(block, "text")), "")
|
||||||
@@ -215,10 +219,12 @@ def agent_loop(messages: list):
|
|||||||
return
|
return
|
||||||
results = []
|
results = []
|
||||||
manual_compact = False
|
manual_compact = False
|
||||||
|
compact_focus = ""
|
||||||
for block in response.content:
|
for block in response.content:
|
||||||
if block.type == "tool_use":
|
if block.type == "tool_use":
|
||||||
if block.name == "compact":
|
if block.name == "compact":
|
||||||
manual_compact = True
|
manual_compact = True
|
||||||
|
compact_focus = block.input.get("focus", "")
|
||||||
output = "Compressing..."
|
output = "Compressing..."
|
||||||
else:
|
else:
|
||||||
handler = TOOL_HANDLERS.get(block.name)
|
handler = TOOL_HANDLERS.get(block.name)
|
||||||
@@ -233,7 +239,7 @@ def agent_loop(messages: list):
|
|||||||
# Layer 3: manual compact triggered by the compact tool
|
# Layer 3: manual compact triggered by the compact tool
|
||||||
if manual_compact:
|
if manual_compact:
|
||||||
print("[manual compact]")
|
print("[manual compact]")
|
||||||
messages[:] = auto_compact(messages)
|
messages[:] = auto_compact(messages, focus=compact_focus)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user