-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Feature Request] Scoped context compaction for exploratory phases #14747
Description
What variant of Codex are you using?
CLI
What feature would you like to see?
A way to compress a specific segment of the conversation history — not the whole thing — when that segment represents a completed exploratory phase.
Problem
Current context management in Codex compresses the entire history when approaching limits. But real agentic sessions have structure:
turns 1–30: initial setup, requirements gathering
turns 31–80: exploring a bug → lots of dead ends, tool calls, false starts
turn 81: conclusion reached: "the issue is in X, fix is Y"
turns 82–...: implementing the fix
When compaction fires, the entire history gets summarized — including turns 1–30 (still relevant setup context) and turns 31–80 (completed exploration). The precise conclusion from turn 81 gets diluted into the global summary, and the setup context from turns 1–30 is unnecessarily compressed too.
Proposed solution
A scoped compaction primitive: compress only a defined range of turns into a conclusion block, leaving the rest of the context intact.
# Agent-callable tool — compress only the exploration phase, leave setup and implementation intact
compact_scope(discard_from=31, summary="root cause: X, fix: Y")The agent could call this autonomously when it detects a phase transition (e.g. "I've finished investigating, now implementing").
Why this matters
- Precision: A narrow-scope summary is more accurate than a global one — the model knows exactly what conclusion was reached
- Continuity: The rest of the session (implementation, tests, etc.) stays fully intact, not re-summarized
- Cost: Exploratory turns are token-heavy but conclusion-light; compressing them early reduces ongoing costs
- Distinct from subagents: This is about the main agent's own session history — subagents are a separate orthogonal concept
Suggested implementation path
Could be built as a layer on top of existing session serialization — select a turn range, run a focused summarization pass, replace with a <conclusion> block, continue. No new API primitives required.
Additional information
No response