@@ -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,16 @@ 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 = ""
114+ if focus :
115+ focus_instruction = f" Pay special attention to preserving details about: { focus } ."
113116 response = client .messages .create (
114117 model = MODEL ,
115118 messages = [{"role" : "user" , "content" :
116119 "Summarize this conversation for continuity. Include: "
117120 "1) What was accomplished, 2) Current state, 3) Key decisions made. "
118- "Be concise but preserve critical details.\n \n " + conversation_text }],
121+ "Be concise but preserve critical details."
122+ f"{ focus_instruction } \n \n " + conversation_text }],
119123 max_tokens = 2000 ,
120124 )
121125 summary = next ((block .text for block in response .content if hasattr (block , "text" )), "" )
@@ -215,10 +219,12 @@ def agent_loop(messages: list):
215219 return
216220 results = []
217221 manual_compact = False
222+ compact_focus = ""
218223 for block in response .content :
219224 if block .type == "tool_use" :
220225 if block .name == "compact" :
221226 manual_compact = True
227+ compact_focus = block .input .get ("focus" , "" )
222228 output = "Compressing..."
223229 else :
224230 handler = TOOL_HANDLERS .get (block .name )
@@ -233,7 +239,7 @@ def agent_loop(messages: list):
233239 # Layer 3: manual compact triggered by the compact tool
234240 if manual_compact :
235241 print ("[manual compact]" )
236- messages [:] = auto_compact (messages )
242+ messages [:] = auto_compact (messages , focus = compact_focus )
237243 return
238244
239245
0 commit comments