An agent working through a long task accumulates everything — every tool result, every intermediate reasoning step, every file it read. By step thirty the prompt is mostly material that mattered at step four and is irrelevant now. Cost per step has climbed steadily, and accuracy has been quietly declining because the model is reading through a large volume of noise to find the parts that matter.
Compaction fixes both at once, which is unusual and worth the implementation effort.
What changed in 2026
- Automatic compaction shipped in agent frameworks. Triggering summarization at a context threshold became a built-in capability rather than something each team implemented.
- Structured summaries beat prose. Compacting into a defined schema with named fields outperformed free-text summarization at preserving what later steps needed.
- Compression got measured. Teams began evaluating compaction quality directly by testing whether post-compaction runs still succeeded, rather than assuming.
- The retrieval alternative clarified. Consensus formed that compression suits conversational state while retrieval suits reference material, and mixing them appropriately beats either alone.
What to preserve
| Content |
Keep after compaction |
| The original task or goal |
Verbatim, always |
| Constraints discovered along the way |
Yes; these are frequently lost and expensive to relearn |
| Decisions made and why |
Yes; prevents relitigating |
| Approaches tried that failed |
Yes; the single most valuable field |
| Current state or progress |
Yes |
| Tool results still relevant |
Summarized |
| Tool results no longer relevant |
Drop |
| Verbatim reasoning traces |
Drop |
| The last few turns |
Keep verbatim, uncompressed |
The failed-approaches row is the one teams omit and then wonder why the agent keeps trying the same broken thing. Without a record of what did not work, a compacted agent cheerfully re-explores dead ends, which costs both tokens and time. It is the same problem as the handoff briefs in AI agent handoff patterns, and the same field fixes it.
Keeping recent turns verbatim matters too. Compressing what just happened loses the immediate detail the next step depends on. Compact the old material; leave the recent window intact.
When to trigger
Fill percentage is the right signal, not turn count or elapsed time. Compact when context reaches a threshold — somewhere well before the model's reliable range ends, since the degradation described in context rot begins long before the window is full.
Compress into a structured schema rather than asking for a summary. A free-text summary drops whatever the summarizing model considered unimportant, and its judgment about that is not yours. A schema with explicit fields for goal, constraints, decisions, failures, and state forces the important categories to be filled.
Then verify. The way to know your compaction works is to run tasks that require post-compaction steps to use pre-compaction information, and check they still succeed. Teams that never test this discover the summary was dropping something critical only when a long run fails mysteriously.
For reference material — documentation, records, anything you might need to look up rather than remember — retrieval is the better tool. Compress conversational state; retrieve reference data.
Common mistakes
- Free-text summaries. Drop things unpredictably; use a schema.
- No failed-attempts field. The agent repeats dead ends.
- Compressing recent turns. Loses the detail the next step needs.
- Triggering on turn count. Fill percentage is what actually matters.
- Never testing compaction. You will not notice loss until a long run fails.
- Compressing reference material. Retrieve it instead.
FAQ
How much can I compress?
Substantially — long transcripts frequently compact to a small fraction of their size with no loss of task-relevant information, because most of the volume is superseded detail.
Does compaction cost a model call?
Yes, one. It pays for itself immediately through cheaper subsequent steps.
Can I compress more than once in a run?
Yes, and compress the previous summary along with newer material rather than chaining summaries of summaries, which degrades.
What about conversations users can scroll back through?
Keep the full transcript for display separately from the context you send the model. They serve different purposes.
Where to go next
For why long context degrades, read context rot explained. For the prompt-level version, prompt compression, and for what compaction costs and saves, AI agent cost per task.