From d9122ac93619237a4dc212db8a10e6c342395d37 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Wed, 11 Mar 2026 05:38:20 -0700 Subject: [PATCH] feat: use Codex-style compaction prompt for context compression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the generic summarization prompt ('Summarize these conversation turns concisely') with a task-oriented handoff prompt inspired by OpenAI's Codex CLI compaction flow (researched in #499). The new prompt frames compression as a 'CONTEXT CHECKPOINT COMPACTION' and instructs the summarization model to produce a structured handoff summary that includes: - Current progress and key decisions - User preferences and constraints discovered - Clear next steps remaining - Critical data (file paths, URLs, error messages, code snippets) - Tool calls made and their key results This produces better summaries because the model understands the summary will be used by another LLM to continue the work, rather than treating it as a generic text compression task. No behavioral change to the compression algorithm itself — same positional protection, same role alternation, same [CONTEXT SUMMARY]: prefix. Only the prompt sent to the summarization model changes. Inspired by PR #776 by @kshitijk4poor. --- agent/context_compressor.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index 01aa2af8049..78b8b5c9093 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -103,22 +103,24 @@ class ContextCompressor: parts.append(f"[{role.upper()}]: {content}") content_to_summarize = "\n\n".join(parts) - prompt = f"""Summarize these conversation turns concisely. This summary will replace these turns in the conversation history. - -Write from a neutral perspective describing: -1. What actions were taken (tool calls, searches, file operations) -2. Key information or results obtained -3. Important decisions or findings -4. Relevant data, file names, or outputs - -Keep factual and informative. Target ~{self.summary_target_tokens} tokens. - ---- -TURNS TO SUMMARIZE: -{content_to_summarize} ---- - -Write only the summary, starting with "[CONTEXT SUMMARY]:" prefix.""" + prompt = ( + "You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff " + "summary for the AI assistant that will resume this conversation.\n\n" + "Include:\n" + "- Current progress and key decisions made\n" + "- Important context, constraints, or user preferences discovered\n" + "- What remains to be done (clear next steps)\n" + "- Any critical data: file paths, variable names, URLs, error messages, " + "or code snippets needed to continue\n" + "- Tool calls made and their key results\n\n" + "Be concise, structured, and focused on helping the assistant seamlessly " + "continue the work without re-doing what's already been done.\n\n" + f"Target roughly {self.summary_target_tokens} tokens.\n\n" + "---\n" + f"TURNS TO SUMMARIZE:\n{content_to_summarize}\n" + "---\n\n" + 'Write only the summary, starting with "[CONTEXT SUMMARY]:" prefix.' + ) # 1. Try the auxiliary model (cheap/fast) if self.client: