TL;DR
Current LLM-based software engineering agents suffer from "context coupling," where code exploration and precise edit generation fight for space in the same context window. SWE-Edit solves this by decomposing the editing interface into two specialized subagents—a Viewer and an Editor—boosting task resolution rates while significantly cutting inference costs. Furthermore, the authors show that choosing the right edit format is a learnable skill that can be trained into a small 8B model using reinforcement learning, matching frontier-model performance.
What Problem Does This Paper Address?
When AI agents tackle real-world software engineering tasks, they typically use a monolithic interface to inspect files and apply changes. This creates a fundamental structural tension called context coupling.
To debug effectively, an agent must explore broadly, viewing multiple files and tracing dependencies. However, every snippet viewed remains trapped in the LLM's context window. This accumulated "context pollution" degrades the agent's performance when it needs to switch gears and generate highly precise code edits.
Furthermore, standard editing formats present a double-edged sword: find-and-replace blocks are token-efficient but incredibly brittle to minor whitespace mismatches, while whole-file rewrites avoid matching errors but incur prohibitive token costs for long files. Monolithic agents struggle to balance these conflicting demands.
Methods
The authors introduce SWE-Edit, a two-stage optimization framework that decouples reasoning from execution at both the scaffolding and model levels.
1. Scaffolding Optimization
Instead of a single agent handling everything, SWE-Edit splits the code editing interface into two specialized subagents operating in clean, independent context windows (see Figure 1):
- Viewer Subagent: Receives a file path and a natural language query, then extracts and returns only the task-relevant code blocks, shielding the main agent from context pollution.
- Editor Subagent: Receives high-level natural language edit instructions from the main agent and executes the modifications directly.
Both subagents run on smaller, cost-efficient models (like GPT-5-mini), leaving the high-capacity main agent free to focus purely on orchestration and problem-solving.
2. Model Optimization (Adaptive Editing)
Rather than sticking statically to one editing format, the Editor is trained to dynamically choose between two modes based on the task's complexity (see Figure 2):
- Find-and-Replace: For precise, localized changes.
- Whole-File Rewrite: For complex, multi-line structural restructuring.
The authors fine-tune an open-source backbone (Qwen3-8B) using Group Relative Policy Optimization (GRPO). The model learns an adaptive policy optimized by a normalized match reward that compares the generated code against ground truth after stripping comments and whitespace.
Datasets
- SWE-Bench Verified: A curated benchmark of 500 real-world GitHub issues used to evaluate downstream agent performance.
- PR-Edit Benchmark: A new, lightweight intermediate benchmark introduced by the authors consisting of 500 held-out test instances derived from open-source GitHub pull requests. It serves as a fast, inexpensive proxy for editor quality, showing a strong correlation ($r=0.98$) with full SWE-Bench resolve rates (see Figure 4).
- Training Data: 3.5K curated examples from open-source GitHub PRs, completely isolated from SWE-Bench repositories to prevent data leakage.
Key Insights and Ideas
- Exploration and Precision are at Odds: Forcing a single model to simultaneously optimize for comprehensive codebase understanding and strict syntax formatting is inherently inefficient.
- Format Selection is a Learnable Skill, Not an Emergent Property of Scale: You don't need a frontier-scale model to generate reliable code formats. Through GRPO reinforcement learning, a small 8B model can learn when to rewrite a file versus when to use find-and-replace, outperforming static baselines.
- Synergistic Cost-Performance Gains: Splitting tasks among subagents usually introduces inference overhead. However, SWE-Edit breaks this trade-off. The Viewer reduces the main agent's context window size, and the Editor eliminates costly formatting retries, shifting the entire Pareto frontier toward higher accuracy and lower cost (see Figure 3).
Key Results
- Performance Boost & Cost Reduction: On SWE-Bench Verified, SWE-Edit raises the issue resolve rate by 2.1 percentage points (pp) while cutting total inference costs by 17.9% (see Table 1).
- Model Agnostic Generalization: The scaffolding benefits transfer seamlessly across diverse reasoning models, including Kimi-K2, MiniMax-M2.1, and GLM-4.7, yielding edit success rate improvements between +12.8 pp and +18.3 pp (see Table 2).
- Small Model Parity: The GRPO-trained Qwen3-8B editor improved its edit success rate by 12.5 pp, bringing it to parity with GPT-5-nano on downstream SWE-Bench resolve rates at a fraction of the cost.
Limitations and Future Work
Currently, the editor subagent is trained in isolation using a static reward signal from ground-truth edits. The authors note that a valuable next step would be training the editor within an end-to-end agentic reinforcement learning loop. This would allow the editor to receive direct feedback from the main agent's downstream successes or failures, helping it learn to produce edits that are not just syntactically correct, but also easier for the main agent to verify and debug. Additionally, the intermediate PR-Edit benchmark relies on a GPT Grader, which could be upgraded to an "agent-as-a-judge" utilizing broader repository context.
Summary updated