Intermediate · Systems
Context Compaction
Visual diagram · (in preparation) · Math · (in preparation) · Worked example · 3 difficulty levels.
TL;DR. Compressing accumulated history into a smaller, higher-density representation so an agent can keep working within its token budget.
Technical Definition
Compressing accumulated history into a smaller, higher-density representation so an agent can keep working within its token budget.
How it works
Compaction replaces long transcripts with condensed state: a summary of what was learned, the decisions made and why, the artifacts produced with pointers to them, and the remaining plan. Good compaction is lossy on purpose but preserves invariants — the goal, hard constraints, and irreversible actions already taken. Triggering is typically threshold-based (a fraction of the window) or phase-based (at the end of a sub-task). Poor compaction is a leading cause of agents losing the plot mid-task.
Related Concepts
- Agentic Context Strategies — The repertoire of techniques for filling an agent's window: retrieval, summarization, scratchpads, sub-agents, and offloading to files.
- Context Management — The engineering practice of controlling what goes into a model's context window, in what order, and at what cost.
- Context Drift — The gradual divergence of an agent's working context from the actual task or world state, degrading its decisions over time.
- Context Lifecycle — The stages a piece of context passes through: acquisition, validation, injection, use, compaction, persistence, and expiry.