Self-Compacting Language Model Agents

Tianjian Li, Jingyu Zhang, William Jurayj, Xi Wang, Chuanyang Jin, Mehrdad Farajtabar, Eric Nalisnick, Daniel Khashabi

TL;DR

Long-horizon LLM agents frequently suffer from "context rot"—performance degradation caused by the accumulation of stale reasoning and irrelevant tool outputs in their context window. To solve this, the authors introduce SelfCompact, a training-free scaffold that uses a lightweight rubric to let the agent dynamically decide when and how to compress its own history. This adaptive approach matches or exceeds traditional fixed-interval compression while slashing token costs by 30% to 70%.

What Problem Does This Paper Address?

As LLM agents tackle increasingly complex, long-horizon tasks (like competitive mathematics or deep web research), their generation traces grow exponentially, sometimes reaching tens of thousands of tokens. However, longer contexts carry a hidden tax: context rot. Early mistakes, abandoned search paths, and redundant thoughts remain in the context window, anchoring and distracting subsequent generations.

Existing systems typically handle this using rigid, content-agnostic heuristics—such as summarizing the context every fixed number of tokens or turns. The problem? A fixed clock doesn't care if the agent is in the middle of a crucial derivation or a complex search. Compacting at the wrong moment can wipe out vital intermediate facts, forcing the model to fall back on blind guesses.

Figure 1: Comparison of trajectory-compression strategies on a hard BrowseComp question. The gold answer requires verifying four facts (Agaricus, Bon 1983, Clash 1981, Harryhausen) before composing Medusa mushroom. Baseline (no compression) burns its budget on an unproductive monologue and emits no answer. Fixed-interval compression fires every two search trajectories regardless of reasoning state; the poorly-timed summary wipes verified facts mid-reasoning, leaving the model to guess (Morel Mushroom). SELFCOMPACT (Ours) gates compression on a rubric over closed reasoning units, so each summary fires immediately after a verified fact—all four facts persist and the model returns the correct answer.

Methods

Instead of relying on hardcoded token thresholds, SelfCompact hands the decision of when to compact back to the agent itself using a training-free, inference-time scaffold. It pairs two core elements:

  1. An Inline Compaction Tool ($S$): A prompt-based tool that instructs the model to generate a condensed summary of the accumulated context, preserving key insights and final answers while discarding the "junk."
  2. A Lightweight Rubric Prompt ($P_R$): A task-specific set of binary conditions evaluated at periodic intervals. The rubric explicitly instructs the model to check if a sub-task has successfully resolved (a safe stopping point to COMPRESS) or if it is currently stuck mid-derivation (meaning it should CONTINUE).

Crucially, the system is highly optimized for KV-cache reuse. Rather than re-encoding the entire history for evaluation, the scaffold appends the rubric or summarizer prompt as a user-role message. This keeps the meta-cognitive judging step nearly free in terms of compute, executing a hard reset and resuming from the summary only when a COMPRESS verdict is reached.

Datasets

The authors evaluated SelfCompact across seven models on six challenging benchmarks split into two domains:

  • Multi-turn Competition Math:
  • IMO-Answerbench
  • HMMT Nov 2025
  • HMMT Feb 2026
  • Agentic Search:
  • BrowseComp
  • BrowseComp-Plus
  • DeepSearch QA

Key Insights and Ideas

  • The Meta-Cognitive Gap: Unprompted models are notoriously bad at recognizing when their own context is rotting. However, they don't need expensive fine-tuning to fix this; providing a structured, lightweight rubric at inference time successfully bridges this meta-cognitive gap.
  • Structural vs. Temporal Boundaries: Fixed-interval approaches compress context based purely on time or token counts. SelfCompact naturally aligns its compression with structural boundaries in reasoning (e.g., immediately after a fact is verified or a sub-problem is solved).
  • Firing Earlier is Better: Empirical analysis shows that SelfCompact's rubric-driven summaries consistently trigger earlier than standard 30% context thresholds, preventing stale tokens from polluting the generation loop in the first place.
Figure 2: Distribution of context length when a summary fires in BrowseComp Plus. Top: Fixed- Interval: the policy compresses at a hard 30%-of-max-context budget (red dashed). Bottom: SELF- COMPACT — the rubric fires when the model judges a sub-question resolved. Fixed-Interval triggers compaction at the threshold by construction; SELFCOMPACT spreads them across the budget.

Key Results

SelfCompact demonstrated substantial performance gains and cost reductions across the board:

  • Math Reasoning: On the thinking-enabled Qwen3.5-9B, SelfCompact outperformed the no-compaction baseline by 16.4, 10.0, and 18.1 points on IMO-Answerbench, HMMT Nov, and HMMT Feb, respectively, while matching the token budget of fixed-interval methods.
  • Agentic Search: Across deployed web agents (GLM-4.7-Flash, MiniMax-M2.5, MiMo-V2-Flash), SelfCompact improved absolute accuracy by 5 to 9 points on BrowseComp-Plus.
  • Dramatic Cost Reductions: Because it condenses long trajectories into tight 1k–3k token summaries early on, subsequent LLM calls face much shorter prompts. This resulted in a 30% to 70% reduction in per-question USD costs compared to the baseline.
  • Impact on Hard Problems: The accuracy gains were most pronounced on the hardest subsets of questions that require deep search and heavily accumulate context.
Accuracy by per-question difficulty on BrowseComp Plus for three models.

Limitations and Future Work

  • Open-Weight Focus: The study exclusively evaluated open-weight models. Deployed frontier models (like GPT-5.5 or Claude 4.7) might possess stronger native meta-cognition and could potentially manage context rot without an explicit rubric.
  • Lack of Reinforcement Learning: The current intervention is entirely training-free to isolate the rubric's impact. The authors note that integrating Reinforcement Learning (RL) represents a natural next step, as the rubric could serve as a behavioral target to distill optimal compaction directly into the model's weights.

Summary updated

BibTeX
@inproceedings{li2026self,
  author = {Tianjian Li and Jingyu Zhang and William Jurayj and Xi Wang and Chuanyang Jin and Mehrdad Farajtabar and Eric Nalisnick and Daniel Khashabi},
  title = {{Self-Compacting Language Model Agents}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=21IUMTFqTe},
}
Figure