Adaptive context compaction is the technical mechanism for fighting Context-Rot in long-running AI agents. Rather than cutting old context abruptly — losing information permanently — compaction progressively reduces and summarizes older observations, preserving essential reasoning while shedding low-value noise.

Compaction vs. Truncation

These two strategies share the goal of freeing token budget but differ critically in what they sacrifice:

  • Truncation: Drops tokens beyond a fixed limit. Fast and deterministic, but destroys information permanently. If a prior instruction, decision, or finding is cut, the agent has no recovery path.
  • Compaction: Summarizes or distills older content into condensed representations. The semantic content survives; verbatim detail does not. The agent retains continuity of reasoning without retaining every intermediate artifact.

The distinction matters because Context-Rot is a quality problem, not merely a capacity problem. Truncation solves capacity; compaction addresses quality.

The Adaptive Aspect

“Adaptive” refers to variable compression intensity based on recency and relevance:

  • Recent observations: Kept verbatim — full fidelity, maximum tokens
  • Intermediate history: Lightly summarized — key decisions and outcomes retained
  • Oldest accumulated noise: Aggressively condensed or dropped — failed attempts, redundant tool outputs, superseded intermediate reasoning

Bui (2026) describes this as a five-stage pipeline applied within the Extended ReAct reasoning loop: each stage applies progressively more aggressive reduction to progressively older observations.

Yu et al. (2026) formalize the information-density problem: natural language varies enormously in information density. Uniform compression ratios fail because low-density content (boilerplate, repeated lookups) can be compressed far more aggressively than high-density content (key architectural decisions, critical tool outputs). Their Semi-Dynamic Context Compression framework addresses this with a density-aware ratio selector.

The Adaptive Spectrum Tension

Compaction involves a fundamental tradeoff:

  • Too aggressive: Compacts high-value observations — decision rationale, discovered constraints, task state — causing the agent to re-derive what it already knows or contradict earlier commitments
  • Too lenient: Insufficient reduction; context rot continues; the noise-to-signal ratio rises until reasoning quality degrades

Kang et al. (2025) demonstrate this experimentally: optimized compression guidelines (ACON framework) reduce peak token usage by 26–54% while preserving 95%+ task accuracy — compared to naive compression that degrades performance significantly.

Complementary Techniques

Compaction works alongside related mechanisms, each addressing a different failure mode:

  • Event-driven reminders: Counter instruction fade-out by re-injecting key constraints into current context at trigger points — not compaction, but a proactive signal refresh
  • Progressive-Disclosure-Context: Reduces initial context load by loading instructions and resources on demand — a proactive compaction strategy that prevents accumulation rather than addressing it after the fact
  • External state files: Progress files and structured artifacts (JSON feature lists, git history) offload in-context state to persistent storage, reducing what must survive compaction
  • Sub-agent isolation: Each sub-agent starts with a clean, scoped context — compaction becomes less necessary when context windows are never allowed to accumulate long histories

Sources

  • Bui, Nghi D. Q. (2026). “Building Effective AI Coding Agents for the Terminal: Scaffolding, Harness, Context Engineering, and Lessons Learned.” arXiv preprint, arXiv:2603.05344 [cs.AI]. Available: https://arxiv.org/abs/2603.05344

    • Defines the five-stage adaptive compaction pipeline integrated into the Extended ReAct loop; introduces lazy tool discovery via search_tools as a proactive compaction strategy; covers event-driven system reminders as a complementary mechanism for instruction fade-out
  • Kang, Minki, Wei-Ning Chen, Dongge Han, Huseyin A. Inan, Lukas Wutschitz, Yanzhi Chen, Robert Sim, and Saravan Rajmohan (2025). “ACON: Optimizing Context Compression for Long-horizon LLM Agents.” arXiv preprint, arXiv:2510.00615. Available: https://arxiv.org/abs/2510.00615

    • Empirical demonstration that optimized compression guidelines reduce peak token usage 26–54% while preserving 95%+ accuracy on AppWorld, OfficeBench, and Multi-objective QA; compressors distilled into smaller models preserve accuracy; provides quantitative evidence for the adaptive spectrum tension
  • Yu, Yijiong, Shuai Yuan, Jie Zheng, Huazheng Wang, and Ji Pei (2026). “Density-aware Soft Context Compression with Semi-Dynamic Compression Ratio.” arXiv preprint, arXiv:2603.25926. Available: https://arxiv.org/abs/2603.25926

    • Establishes that uniform compression ratios fail because natural language information density varies enormously; proposes a density-aware discrete ratio selector that predicts compression targets based on intrinsic information density — directly supports the adaptive aspect of compaction
  • Beltagy, Iz, Matthew E. Peters, and Arman Cohan (2020). “Longformer: The Long-Document Transformer.” arXiv preprint, arXiv:2004.05150. Available: https://arxiv.org/abs/2004.05150

    • Foundational architecture for efficient long-context attention via sliding windows; demonstrates that recency-biased attention (lower layers attend locally, higher layers attend globally) is empirically effective — the architectural analog of adaptive compaction’s recency-priority logic
  • Anthropic (2026). “Effective Harnesses for Long-Running Agents.” Anthropic Engineering Blog. Available: https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents

    • Documents that compaction alone is insufficient for multi-session continuity; introduces structured external artifacts (progress files, JSON feature lists, git history) as the complementary mechanism that reduces in-context state requirements; demonstrates practical limits of compaction in production agent deployments

Note

This note was researched and drafted with AI. How these notes are written →