feat: use Codex-style compaction prompt for context compression - #915
Closed
teknium1 wants to merge 1 commit into
Closed
feat: use Codex-style compaction prompt for context compression#915teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
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.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the generic summarization prompt in
ContextCompressor._generate_summary()with a task-oriented handoff prompt inspired by OpenAI's Codex CLI compaction flow (researched in #499).What exactly changes
Before — the prompt sent to the summarization model was:
After — the new prompt is:
Why this is better
The old prompt treated compression as generic text summarization. The new prompt frames it as a handoff between LLMs — the summarization model understands the output will be consumed by another model to continue the work. This produces summaries that better preserve:
What does NOT change
[CONTEXT SUMMARY]:prefix on inserted summariesFile changed
agent/context_compressor.py— prompt text in_generate_summary()only (18 insertions, 16 deletions)Inspired by PR #776 by @kshitijk4poor and the research in #499.