A Tool for Better Context Management: Researchers built SelfCompact, an agentic tool and harness that decides what context to keep
Models that make room in their context windows by discarding the oldest context can lose crucial information.
Models that make room in their context windows by discarding the oldest context can lose crucial information. Researchers developed a method that enables an agent to compact the context at meaningful stopping points.
What's new: Tianjian Li and colleagues at Johns Hopkins University and Apple developed SelfCompact, a agentic scaffold that provides a compaction tool a model can invoke and a rubric for its invocation. The approach requires no fine-tuning or external supervision.
Key insight: In an agentic system, the right time to compact a model’s context depends as much on what the agent is doing as the number of tokens that have accumulated in the model’s context window. A well timed compaction can discard obsolete reasoning, while a poorly timed one can discard partial results the model still needs. A tool with instructions bridges this gap.
How it works: SelfCompact adds to an agent’s toolkit a probe that evaluates the system’s traces periodically and a summarization tool. If the probe allows compacting, it invokes the tool to summarize the context. The same model that generates the traces writes the summary. (The authors experimented with Alibaba’s Qwen family.)
- Every 16,000 tokens, the probe appended to the model’s context a prompt that specified when to allow compacting and when to block it and asked the model to judge its own state. It checked whether a sub-task had been completed or the agent was making clear progress toward a definite outcome. If so, the probe allowed compacting. If instead the model was in the middle of a step or stuck, it blocked compacting.
- When compaction occurred, the summarizer condensed the traces (typically 50,000 to 100,000 tokens) into a short summary (roughly 1,000 to 3,000 tokens), and generation resumed based on the summary.
Results: SelfCompact achieved higher accuracy than fixed-interval summarization (invoked when a model filled 30 percent of its context window) and no compaction (a dead stop when a model hit the limit) across six benchmarks.
- On IMO-Answerbench (competition mathematics problems), Qwen3-30B-A3B with SelfCompact achieved 52.1 percent accuracy. Fixed-interval summarization achieved 48.7 percent, and no compaction achieved 45.2 percent.
- On BrowseComp-Plus (questions that require retrieving information from databases), GLM-4.7-Flash with SelfCompact achieved 54.1 percent accuracy. Fixed-interval summarization achieved 50.0 percent, and no compaction achieved 45.6 percent.
- Replacing the rubric with a simpler prompt that simply asked the model whether it wanted to compact the context reduced SelfCompact performance to the level of fixed-interval summarization. This shows that the rubric, not compaction alone, drove the gains.
Why it matters: Most research on adaptive compaction trains models to decide when to compact their contexts via reinforcement learning or supervised fine-tuning. SelfCompact made these decisions effectively without any parameter updates.
We’re thinking: The rubric approach introduces a new agentic design pattern: exposing a tool and giving the model explicit criteria for using it.