🤖 AI Summary
This study addresses the challenges of context overflow and state management in long-horizon coding agents, focusing on the critical decisions of when to compress and what information to retain. We propose an autonomous context compression framework that integrates compression decisions directly into the policy network. To construct high-quality trajectories, we employ an LLM-as-a-judge mechanism for data refinement. The encoding and compression policies are jointly optimized through a combination of supervised fine-tuning and reinforcement learning. Our approach achieves an absolute improvement of 9.2% in pass rate on benchmarks such as SWE-bench, effectively mitigating context overflow. This work establishes an efficient new paradigm for context management in long-horizon code generation tasks.
📝 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.