TL;DR
This paper introduces CAT (Context as a Tool), a paradigm that transforms context management from a passive background process into a proactive, learnable skill for AI software engineering agents. By treating context compression as a callable tool and using a structured workspace, the authors' SWE-Compressor model achieves a 57.6% solve rate on SWE-Bench Verified, significantly outperforming standard ReAct agents in long-horizon tasks.
What Problem Does This Paper Address?
Large Language Model (LLM) agents are increasingly used for complex software engineering (SWE) tasks, like fixing bugs in massive repositories. These tasks often require hundreds of interaction rounds. Most current agents use an "append-only" strategy, where every past action and observation is shoved into the prompt.
This leads to three major issues:
- Context Explosion: The prompt quickly exceeds the model's limit.
- Semantic Drift: Important initial instructions get "lost in the middle" of thousands of lines of logs.
- Reasoning Collapse: The model becomes overwhelmed by redundant information, leading to repetitive or nonsensical actions.
While some researchers use "passive" compression (e.g., summarizing the history once it hits a certain token limit), these heuristics are often "dumb"—they don't know when a subtask is finished or which details are actually worth keeping for the next phase of the job.
Methods
The authors propose CAT, which elevates context maintenance to a first-class tool that the agent chooses to invoke.
1. The Structured Context Workspace
Instead of a flat list of messages, CAT organizes context into three functional segments:
- Fixed Segment: Stable anchors like the system prompt and the user's original issue.
- Long-Term Memory: A condensed, high-fidelity summary of the historical trajectory (the "what have I done so far" part).
- Working Memory: The most recent $k$ interaction steps in full detail to provide immediate context for the next move.
2. Context Management as a Tool
The agent is trained to call a condenser tool. When called, the agent summarizes its historical trajectory into a new Long-Term Memory block and clears the Working Memory. This allows the agent to "fold" its context at logical milestones (e.g., after finishing a file search or successfully running a test).
3. CAT-GENERATOR
To teach a model this skill, the authors developed a two-stage pipeline:
- Phase I: Generate "base" trajectories using a teacher model that solves tasks without compression.
- Phase II: Retroactively inject
condensertool calls into those successful trajectories at strategic points (like subtask completion or error recovery). - Fine-Tuning: They then fine-tuned a Qwen2.5-Coder-32B model on this "refactored" data to create SWE-Compressor.
Datasets
- Training: The authors curated CAT-Instruct, a dataset of 20,000 high-quality interaction trajectories derived from SWE-smith and SWE-ReBench.
- Evaluation: The primary benchmark is SWE-Bench Verified, a subset of 500 real-world GitHub issues manually curated for reliability.
Key Insights and Ideas
- Internalizing Context Management: The core "aha" moment is that context management shouldn't be a constraint enforced by a wrapper script; it should be a model capability. If an agent knows it's about to start a new subtask, it is the best judge of how to summarize its previous work.
- Stability over Scalability: While many focus on increasing context windows (e.g., to 1M tokens), this paper argues that density matters more than volume. By keeping the context "lean" (stabilizing at ~35k tokens), the model maintains much higher reasoning quality over 500+ turns.
- Proactive vs. Reactive: Standard agents "saturate" and fail after about 60 rounds because their context gets messy. CAT agents actually get better as they are given more steps because they can effectively manage the information flow.
Key Results
- State-of-the-Art Performance: SWE-Compressor (32B) achieved a 57.6% solve rate on SWE-Bench Verified.
- Efficiency: It outperformed much larger models (like Qwen3-235B) and matched the performance of GLM-4.5-Air, despite being a significantly smaller 32B parameter model.
- Long-Horizon Resilience: In tests allowing up to 500 interaction steps, CAT's performance continued to climb, whereas the standard ReAct baseline's performance actually dropped after 60 steps due to context clutter.
- Token Savings: CAT used significantly fewer total tokens than "Threshold-Compression" baselines while achieving higher accuracy.
Limitations and Future Work
- Summarization Quality: The system's success relies heavily on the model's ability to write accurate summaries. If the model forgets a key detail during a "fold," it can't recover it later.
- Offline Supervision: The current training relies on retrofitting existing trajectories. The authors suggest that Reinforcement Learning (RL) could further optimize when the agent decides to compress, potentially finding even more efficient milestones than the heuristic-injected ones used in this study.
- Generalization: While highly effective for SWE, it remains to be seen how well this "Context as a Tool" approach translates to other long-form agent tasks like legal research or long-term creative writing.
Summary updated