A team of researchers has introduced a novel inference-time framework called SELFCOMPACT, designed to address one of the most persistent bottlenecks in modern artificial intelligence systems: the accumulation of stale content in long agent traces. Authored by Tianjian Li, Jingyu Zhang, William Jurayj, Xi Wang, Chuanyang Jin, Mehrdad Farajtabar, Eric Nalisnick, and Daniel Khashabi, the new approach enables large language models to autonomously determine when and how to compact their own context windows without requiring costly fine-tuning or external supervision.

As AI agents tackle increasingly complex, multi-step workflows involving intricate chains of thought and external tool calls, they frequently run into memory constraints. Long interaction trajectories accumulate outdated information, intermediate variables, and redundant data that anchor subsequent generations and eventually push the system to outgrow its context window. This phenomenon, often described as context rot or stale content accumulation, severely degrades the reasoning capabilities and efficiency of language models over extended tasks.

Historically, the artificial intelligence community has relied on fixed-interval compaction mechanisms to combat this issue. These conventional scaffolds typically trigger a summarization or truncation protocol whenever a pre-determined token threshold is crossed. However, researchers point out a fundamental flaw in this rigid approach: fixed triggers pay no heed to the underlying trajectory structure of the task. By enforcing compaction at arbitrary token counts, these systems risk discarding critical partial results right in the middle of a complex derivation or an active search phase, thereby derailing the agent’s progress.

To overcome these limitations, the research team developed SELFCOMPACT, a dynamic inference-time scaffold that shifts the responsibility of context management directly to the language model itself. Rather than relying on arbitrary token thresholds, SELFCOMPACT pairs two core components that work in tandem to govern the compaction process. The first element is a specialized compaction tool that the model can invoke whenever necessary to synthesize and summarize its accumulated context. The second element is a lightweight rubric that provides clear behavioral guidelines, specifying precisely when the model should fire the tool—such as when a sub-task has been successfully resolved or when a trajectory is clearly converging—and when it should suppress it, such as during active derivations or when the agent is stuck.

According to the study, both components are strictly necessary for the system to function effectively. On their own, open-weight models display erratic behavior regarding memory management. Without guidance, models use a compaction tool unevenly, often invoking it at unhelpful moments or failing to use it at all. Conversely, a rubric alone lacks the execution capability to alter the model’s active context. When combined, however, the tool and the rubric successfully elicit adaptive, intelligent compaction that responds to the semantic state of the task rather than a mechanical counting of tokens.

The implications of this dual-element approach are profound, particularly regarding the concept of meta-cognition in artificial intelligence. The researchers’ findings expose a notable meta-cognitive gap in contemporary models: while unprompted language models cannot reliably recognize when their own context is rotting or becoming counterproductive, supplying a lightweight rubric entirely closes this gap. This discovery reframes the ability to manage and compact context not as an innate trait that must be baked in through intensive model training, but rather as an adaptive capability that external scaffolds can supply dynamically.

To validate the efficacy of SELFCOMPACT, the research team conducted comprehensive empirical evaluations across six challenging benchmarks—spanning competitive mathematics and complex agentic search tasks—and tested the framework across seven different large language models. The results demonstrate that SELFCOMPACT consistently matches or exceeds the performance of traditional fixed-interval summarization techniques while requiring only a fraction of the computational and token cost.

Specifically, when compared against a baseline model operating with no summarization whatsoever, SELFCOMPACT achieved performance improvements of up to 18.1 points on rigorous mathematical benchmarks. Furthermore, the framework delivered a 5 to 9 point improvement on agentic search tasks. These performance gains were achieved simultaneously with substantial economic and computational savings, cutting per-question operational costs by 30 to 70 percent through the reduction of unnecessary token processing.

These findings arrive at a crucial juncture for the deployment of autonomous AI agents in enterprise and research settings, where operational costs and context limitations remain significant barriers to scale. By demonstrating that effective memory management can be achieved without expensive retraining cycles or complex external supervisory architectures, the introduction of SELFCOMPACT offers a practical, highly efficient pathway toward more reliable and cost-effective generalist AI agents.