NTH

Context Compaction Theory

AuthorsHayder Tirmazi, Sam Markelon, Allison Bishop, Michael Mitzenmacher

August 10, 2026 3 min read
Watch on YouTube
The one-line take

This paper turns the practical problem of squeezing an AI agent’s memory into a limited context window into a formal communication-complexity theory.

Key results

15,000
Recorded URLs

Malicious URLs used in the Claude Opus 4.8 membership-query case study

14.3K
Compacted summary size

Approximate Claude Opus 4.8 summary budget in Kbits for one run

0.505
Compacted membership error

Error rate for one Claude Opus 4.8 compaction run

What the paper found

“Context Compaction Theory” gives a formal framework for how AI agents preserve information when their growing state exceeds an LLM’s usable context window. It defines the Context Selection Game, where systems such as OpenAI’s Codex or Claude Code retain selected items, and the more general Context Generation Game, where Codex, Gemini CLI, or Anthropic’s summarization endpoint can produce an arbitrary bounded message. The central theorem proves that optimal generation-based compaction is exactly equivalent to one-way communication complexity: the minimum context budget for a target error equals the minimum message length needed to answer the induced queries. Selection is strictly weaker; for a constructed query family, it requires a factor of Θ(log n) more budget than generation. The theory also supplies practical lower bounds through approximate membership, where Bloom filters are near-optimal. In a case study, Anthropic’s Claude Opus 4.8 compacted 15,000 URLs into roughly 14.3 Kbits, but membership-query error reached 0.505 across one run, effectively random guessing, while an uncompacted control achieved 0.02 error and a same-size Bloom filter made errors on about one-third of queries. The result suggests that natural-language summaries can discard task-critical information even when the workload is specified in advance, motivating sketch-based compaction, analyses of repeated compaction, and models for adaptive queries.

Original abstract

Large Language Models (LLMs) have a bounded context window. The context window is the maximum input size an LLM can consume for a single inference. AI agents rely on a process called context compaction to fit their state within the context window when calling an LLM. Despite its ubiquity, context compaction has received essentially no formal analysis. In this paper, we initiate a formal study of context compaction. We first introduce a framework consisting of two games that capture the two algorithmic strategies for context compaction used by contemporary AI agents in practice. The Context Selection Game models context compaction algorithms that select a subset of an agent's accumulated state to retain. The Context Generation Game models context compaction algorithms that summarize an agent's state by an arbitrary message of bounded length. We then prove an equivalence between the Context Generation Game and one-way communication complexity. The minimum context compaction budget for answering a set of queries within a target error is equal to the one-way communication complexity of the induced communication problem at the same error. Known bounds from communication complexity therefore transfer directly to context compaction. We also show that the Context Selection Game corresponds to a restricted class of one-way communication protocols. Any gap between selection and generation is therefore a gap between two classes of communication protocols. We prove that there exists a set of queries for which generation needs strictly less budget than selection. The equivalence between the Context Generation Game and one-way communication also lets us measure how well a deployed context compaction algorithm performs on a query relative to the optimal strategy. As an example, we present a case study that evaluates Anthropic's context compaction endpoint on set membership queries.

Read the original paper

More in AI Agents

Browse all 56 papers →
01Agent

LEGO-Anything: Coding Agents for 3D Scene Reconstruction

Xirui Li, Peng Shi, Mingwen Dong, Sheng Zhang, Zhuoyan Xu, Dongkyu Lee, Shuaichen Chang, Yi Xiang, Lin Pan, Jiarong Jiang

LEGO-Anything turns images into editable Blender programs through iterative coding agents, offering a promising but still imperfect route to reconstructable 3D worlds.

Read analysis
02Agent

MILO: Automated Harness Discovery via Orchestrated Multi-Agent Evolution

Prithwish Jana, Mononito Goswami, Hao Liu, Xinyu Li, Langlin Huang, Zhehui Huang, Zhishen Huang, Patrick Blöbaum, Anoop Deoras, Purak Jain, Nikos Kanakaris, Sahika Genc

MILO uses teams of evolving AI agents to automatically discover better harnesses for long-horizon problem-solving systems.

Read analysis
03Agent

Self-Organizing Agent Teams Learn to Reason Together

Aneesh Pappu, Mirac Suzgun, Yongchan Kwon, Federico Bianchi, Batu El, Mykel J. Kochenderfer, Hancheng Cao, James Zou

This work trains AI agents to discover how to divide labor, challenge ideas, and combine reasoning so that teams can solve problems no individual agent could solve alone.

Read analysis