Agents
Compaction
Compaction rewrites accumulated conversation history into a compact state summary so a long session can continue without exceeding its budget or window.
Also written: context compaction, memory compaction
It is the alternative to truncation, which drops the oldest turns and therefore loses exactly the wrong things — the decisions and constraints established early are usually the ones that still matter.
A good compaction prompt keeps decisions, constraints, measured values and anything the user asked to be remembered, and discards pleasantries, restatements and reasoning that led to a decision already recorded.
In practice
Sending an entire conversation on every turn makes cost grow quadratically with length — the twentieth message pays for the nineteen before it, again. Compacting into a state artefact of a few hundred tokens turns that curve flat. What must survive: decisions made, constraints established, numbers measured. What can go: everything that led to a decision already recorded.
Common questions
When should I compact a conversation?
Before the context approaches the window, not at it — compaction under pressure loses more than compaction with room to work. A common trigger is around 60–70% of the window, with the tail kept verbatim.
What should survive compaction?
Decisions made, constraints established, values measured, identifiers exactly as written. What can go: pleasantries, restatements, and reasoning that led to a decision already recorded. Terse notes, not prose.