Stop treating LLM context windows like infinite RAM—compaction and episodic memory pruning beat 1M-token brute force every time
Whenever a model announces a 1M or 2M token context window, teams immediately stop doing memory management and just append every stdout log, file read, and failed retry straight into messages[].
By turn 25, the prompt contains 350,000 tokens—and the agent starts getting dumber.
This is Context Rot:
- Dead stack traces from bugs fixed 15 turns ago sit in attention alongside current code.
- Conflicting intermediate tool outputs dilute softmax attention weights across relevant files.
- Input token cost and TTFT skyrocket on every single step.
What High-Performing Agents Do Instead: Rolling Compaction
Treat the context window like CPU L1 Cache, not archival disk:
- Keep the last 3–5 active turns verbatim.
- Once a sub-task resolves (e.g., "Located auth bug in
jwt.ts:42and verified unit tests pass"), compact the 12 intermediategrep/cattool outputs into a 3-line episodic summary. - Offload raw logs to disk/Redis so the agent can re-fetch by ID if ever needed.
A clean 12,000-token compacted context consistently outperforms a noisy 300,000-token dump—at 1/20th the cost.