Skip to content

Commit 5d1ee5a

Browse files
committed
feat(s06): pass compact tool's focus param to auto_compact summarization
1 parent d882d01 commit 5d1ee5a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

agents/s06_context_compact.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def micro_compact(messages: list) -> list:
100100

101101

102102
# -- Layer 2: auto_compact - save transcript, summarize, replace messages --
103-
def auto_compact(messages: list) -> list:
103+
def auto_compact(messages: list, focus: str = "") -> list:
104104
# Save full transcript to disk
105105
TRANSCRIPT_DIR.mkdir(exist_ok=True)
106106
transcript_path = TRANSCRIPT_DIR / f"transcript_{int(time.time())}.jsonl"
@@ -110,12 +110,14 @@ def auto_compact(messages: list) -> list:
110110
print(f"[transcript saved: {transcript_path}]")
111111
# Ask LLM to summarize
112112
conversation_text = json.dumps(messages, default=str)[-80000:]
113+
focus_instruction = f"\nIMPORTANT: Pay special attention to preserving details about: {focus}" if focus else ""
113114
response = client.messages.create(
114115
model=MODEL,
115116
messages=[{"role": "user", "content":
116117
"Summarize this conversation for continuity. Include: "
117118
"1) What was accomplished, 2) Current state, 3) Key decisions made. "
118-
"Be concise but preserve critical details.\n\n" + conversation_text}],
119+
"Be concise but preserve critical details."
120+
f"{focus_instruction}\n\n" + conversation_text}],
119121
max_tokens=2000,
120122
)
121123
summary = next((block.text for block in response.content if hasattr(block, "text")), "")
@@ -215,11 +217,13 @@ def agent_loop(messages: list):
215217
return
216218
results = []
217219
manual_compact = False
220+
compact_focus = ""
218221
for block in response.content:
219222
if block.type == "tool_use":
220223
if block.name == "compact":
221224
manual_compact = True
222-
output = "Compressing..."
225+
compact_focus = block.input.get("focus", "")
226+
output = "Compressing..." + (f" (focus: {compact_focus})" if compact_focus else "")
223227
else:
224228
handler = TOOL_HANDLERS.get(block.name)
225229
try:
@@ -232,8 +236,8 @@ def agent_loop(messages: list):
232236
messages.append({"role": "user", "content": results})
233237
# Layer 3: manual compact triggered by the compact tool
234238
if manual_compact:
235-
print("[manual compact]")
236-
messages[:] = auto_compact(messages)
239+
print(f"[manual compact{': ' + compact_focus if compact_focus else ''}]")
240+
messages[:] = auto_compact(messages, focus=compact_focus)
237241
return
238242

239243

0 commit comments

Comments
 (0)