X-02Context Compaction

/context/context-compaction

When the window fills, compress the trajectory into a summary plus explicitly preserved state.

Step-by-step walkthrough2 variants · 10 steps

Careful

  1. A long trajectory: reads, edits, failures, and two easily-missed critical facts.
  2. The window is nearly full. Something has to go.
  3. The compactor reads everything…
  4. …emits a short summary plus explicitly preserved state.
  5. 8.4k → 1.9k tokens. The constraint and the key path survived by design, not luck.

Naive

  1. Same trajectory, same two critical facts buried in it.
  2. A generic “summarize this” pass compresses by salience — and constraints aren’t salient.
  3. The summary preserves the gist.
  4. The constraint and the key path silently vanish.
  5. Twenty steps later the agent violates a rule it no longer knows exists.
Key insight

Compaction is a write policy, not a summary: decide what must survive (constraints, decisions, open questions, current diffs) and preserve it verbatim — summarize only the rest.

Failure mode

Salience-based summarization drops exactly the things that matter most: user constraints and one-line facts are rarely “salient”, until they’re violated.

Further reading

Elsewhere in the atlas