AutoCompact: Learning When to Compact Context in Long-Horizon Coding Agents
cs.CL
Submitted: 2026-10-01
Updated: 2026-10-01
License: http://creativecommons.org/licenses/by/4.0/
The gist: Coding agents solve repository-level software engineering tasks through long trajectories of code inspection, search, editing, and testing.
Terminology
Abstract
Coding agents solve repository-level software engineering tasks through long trajectories of code inspection, search, editing, and testing. As a task progresses, earlier exploration becomes stale, so managing context is more than avoiding overflow: an agent must decide when to compact, what working state to preserve, and how to continue from it. We introduce AutoCompact, which trains a coding agent to make these decisions as part of its policy. To collect training data, we run the base agent on coding tasks and use a judge to review its compaction decisions, summaries, and actions after compaction. Flawed outputs are replaced with corrected ones before being executed in the environment, so each trajectory continues from the corrected decisions. We use these trajectories for supervised fine-tuning, then jointly optimize coding and compaction through reinforcement learning with task-success rewards. Experiments on SWE-bench Verified and SWE-PolyBench Verified show that AutoCompact improves pass rates over the base model by an absolute 9.2% and 5.0%, respectively. The improvements hold across all evaluated inference budgets, with a 256K context window that never overflows and with a 16K window whose overflow triggers fallback compaction.
Sources
- SWE-MeM: Learning Adaptive Memory Management for Long-Horizon Coding Agents
- Self-Compacting Language Model Agents
- CompactionRL: Reinforcement Learning with Context Compaction for Long-Horizon Agents
- MemGPT: Towards LLMs as Operating Systems
- SWE-PolyBench: A multi-language benchmark for repository level evaluation of coding agents
- DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models
- Scaling Long-Horizon LLM Agent via Context-Folding
- ReSum: Unlocking Long-Horizon Search Intelligence via Context Summarization
- Qwen3 Technical Report
- AgentFold: Long-Horizon Web Agents with Proactive Context Management
Related papers
- Exploring Solution Divergence and Its Effect on Large Language Model Problem Solving
- Ishigaki-IDS-Bench: A Benchmark for Generating Information Delivery Specification from BIM Information Requirements
- Subliminal Steering: Stronger Encoding of Hidden Signals
- MedStruct-S: A Benchmark for Key Discovery, Key-Conditioned QA and Semi-Structured Extraction from OCR Clinical Reports
- The End of Transformers? On Challenging Attention and the Rise of Sub-Quadratic Architectures
- Untangling the Mechanisms of Misleading Context in Medical Question Answering