Context compaction
A long conversation or agent trace is summarised and the window restarted from the summary, so the loop can continue past the context limit.
The trade is irreversible and invisible to the model: after compaction the summary is the history, so an agent cannot report what was dropped and instead repeats work or reopens settled decisions. Clearing stale tool results is the lighter-touch version, and logging every compaction with its token counts is what makes the failure debuggable.
Explained in depth
Deciding what enters the context window and what stays out: budgeting the prompt, compaction, tool-result handling, and retrieval precision over recall.
Context Window EconomicsContext is a per-request budget, not a capability. Attention cost scaling, long-context price tiers, prompt caching, and why chat history compounds.
Implemented by
- LangGraph
- LangSmith
- Model Context Protocol