Context Compaction
Lossy compression of a session ribbon to reclaim window capacity.
Moving from a three-bedroom house into a studio forces a hundred quick decisions. The couch stays, the good knife goes, the box of cables gets labeled "misc." A month later you need the one adapter that was in that box, and it's gone. Nobody chose to lose it.
An agent's context window is the studio. A long session keeps adding tool calls, results and reasoning until the window is nearly full. Then the harness, or the agent itself, compacts: it replaces the older part of the session with a summary and carries on. From then on, everything before the summary exists only as the summary describes it.
Compaction is always lossy. A 95,000-token history doesn't fit, so most of it has to go. The design question is what gets kept.
In practice
Here is an illustrative compaction from an agent fixing an invoice export bug. Forty turns became this:
[Summary of turns 1-40]
Working on the invoice export bug. Looked at the CSV writer
and the currency formatter. The issue seems related to locale
handling. Next: fix the formatter and run the export tests.
It reads fine. Here is what those 40 turns had actually established:
goal: EUR invoices export as "1.234,00" in en-US CSVs
verified: bug is in format_money() in money.py
ruled_out: csv_writer.py (escaping checked, correct)
open: does the PDF export call format_money() too?
next: patch, then run tests/test_export.py
Notice the three kinds of loss in the first version. The verified fact became a hedge ("seems related"). The ruled-out file vanished, so the agent may investigate it again. The exact names it needs, the function and the test file, must be found a second time.
Why it matters
After compaction, the summary is the agent's whole memory of the session. It can't check the summary against the turns it replaced, so it trusts it completely. Whatever the summary dropped is lost without the agent knowing. The Guide calls this handoff lossLexicon · 46Handoff LossDisappearance of verified facts and rationale across compaction or delegation., and compaction is its most common source.
Mistakes survive too, and get promoted. A wrong guess from turn 12, written into the summary, returns as background fact that every later turn builds on. An early error re-referenced like this is context poisoningLexicon · 21Context PoisoningAn early hallucination or error repeatedly re-referenced in later turns.. And a summary of a summary loses more each time.
What to do about it
H-14 Memory Metabolism asks for structured compaction contracts: a fixed shape, like the second example, with fields for the goal, verified facts, ruled-out paths and open questions, so the summarizer can't quietly drop them. H-01 Continuous State Anchoring reduces what compaction must carry: if tools can always report the live state of the work, the agent looks it up instead of remembering it.
Related
What compaction compresses is the 1D temporal ribbonLexicon · 081D Temporal RibbonThe linear token stream through which an agent perceives reality., the single stream of tokens that is all the agent sees. It is the forced, all-at-once version of the small, deliberate forgetting in inhale / exhale loopsLexicon · 44Inhale / Exhale LoopsAlternating between acquiring working context and deliberately shedding debris.. What triggers it is context loadLexicon · 13Context LoadTotal tokens competing for attention inside the context window., the total tokens competing for space in the window.