Context Compaction Theory
AuthorsHayder Tirmazi, Sam Markelon, Allison Bishop, Michael Mitzenmacher
Resources
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
Malicious URLs used in the Claude Opus 4.8 membership-query case study
Approximate Claude Opus 4.8 summary budget in Kbits for one run
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 paperMore in AI Agents
Browse all 80 papers →GH-AWTrace: A Large-Scale Dataset of GitHub Agentic Workflow Execution Logs
Jasem Khelifi, Hao Li, Ali Ouni, Mohammed Sayagh, Mohamed Aymen Saied
GH-AWTrace collects millions of GitHub agent workflow runs and logs to help researchers investigate how agents execute tasks, use tools, and fail.
Piccolo: Co-Evolving Decision Models and Data through Recursive Self-Improvement
Zhenqing Ling, Qirui Jiao, Daoyuan Chen, Cheng Chen, Xinji Mai, Haowen Gao, Zhuo Zhang, Xuchen Pan, Mengsu Ding, Jiaji Deng, Yuexiang Xie, Xiaoming Qin, Weirui Kuang, Zhaoyang Liu, Yaliang Li, Bolin Ding, Jingren Zhou
Piccolo uses research agents to iteratively improve both its decision models and the data they learn from.
The Resolution Hypothesis: Agent Evolution's Key Is Identifying Improvements
Yuanhao Zeng, Shaocheng Lan, Ao Lu, Kuang Yan, Heng Lin, Xinang Xu, Yuan Luo, Yueting Wang, Yexin Li, Ruo Shan, Kan Ren
Agent evolution may be limited less by generating better ideas than by reliably spotting which ones actually work.