Context compaction
When the context fills up, summarise the old parts and keep going.
What it is
Near the context limit, older turns are replaced with a summary that keeps the plan, decisions, open problems and file paths; tool outputs are dropped first.
When to use it
- Long sessions: big features, migrations, debugging marathons
When to skip it
- Summaries that drop the constraints ("don't touch the API"): pin them
Why (the trade-off)
Without it, long tasks fail when the rules from the start fall out of the window.
Where it sits
Control layer, between turns.
What it needs first
- Agent loopit manages the loop's context
What can be added to it
- pairs withSubagentskeep noisy exploration out of the main context entirely
Effect of adding it
- cost —
- latency —
- reliability ↑↑
- safety —
Risks it handles
- The context fills up · full
- A context window fills up · full
Learn first (AI Engineering)
depth 4+1 production note with numbers.