A new method called AutoCompact trains coding agents to decide when to compact their context during extended programming tasks, and what information to preserve. In tests on repository-level software engineering benchmarks, it improved task success rates over the base model.
These tasks involve inspecting code, searching for relevant locations, editing files, and running tests. As work progresses, earlier exploration can become stale. AutoCompact therefore treats context compaction as more than a way to prevent a context window from filling up: the agent must summarize its working state and continue from that summary.
To create training data, the researchers first ran a base agent on coding tasks. A judge reviewed its compaction choices, summaries, and actions after compaction. Flawed outputs were corrected before the task continued in the environment. The resulting trajectories were used for supervised fine-tuning, followed by reinforcement learning that jointly optimized coding and compaction using task-success rewards.
On SWE-bench Verified and SWE-PolyBench Verified, AutoCompact raised pass rates over the base model by 9.2 and 5.0 percentage points, respectively. The gains held across all evaluated inference budgets. A 256K context window never overflowed, while overflow with a 16K window triggered fallback compaction. The paper provides further details on the training setup and results: https://arxiv.org/abs/2610.02163v1