Source-linked AI summary

SWE-Edit: Rethinking Code Editing for Efficient SWE-Agent

Yikai Zhang, Jiaxin Pei, Kenan Li, Qirui Jin, Maoquan Wang, Jin Pan, Yu Kang, Shengyu Fu, Elsie Nallipogu, Junjie Hu, Yufan Huang, Zijian Jin

arXiv:2604.26102v2cs.SEcs.CL

TL;DR

Standard code-editing interfaces couple inspection, modification planning, and edit execution in one context, where exploration can accumulate irrelevant information alongside format-sensitive editing. SWE-Edit separates inspection and editing into Viewer and Editor subagents, and trains the Editor with GRPO to select an editing mode based on the task. GRPO with a normalized match reward improves edit success by 12.5 pp on the small open-source Qwen3-8B backbone.

  • Problem

    Standard code-editing interfaces couple inspection, modification planning, and edit execution in one context, where exploration can accumulate irrelevant information alongside format-sensitive editing.

    Source: §1 · p. 1
  • Method

    SWE-Edit separates inspection and editing into Viewer and Editor subagents, and trains the Editor with GRPO to select an editing mode based on the task.

    Source: §1 · p. 2, §3.2 · p. 4
  • Results

    GRPO with a normalized match reward improves edit success by 12.5 pp on the small open-source Qwen3-8B backbone.

    Source: §5 · p. 8
  • Takeaways & Limitations

    The scaffold, PR-Edit benchmark, and editor training form a deployable, cost-efficient recipe for code-editing subagents.

    Source: §5 · p. 8

    The editor is trained in isolation with a static reward derived from ground-truth edits, rather than feedback from downstream agent success or failure.

    Source: Limitations · p. 8

Abstract

from arXiv · show

Large language model agents have made strong progress on software engineering, yet current systems suffer from a context coupling problem: the standard code editing interface conflates code inspection, modification planning, and edit execution within a single context window, forcing agents to interleave exploratory viewing with strictly formatted edit generation. Irrelevant context accumulates and edit reliability degrades. We propose SWE-Edit, which decomposes the editing interface into two specialized subagents: a Viewer that extracts task-relevant code on demand, and an Editor that executes modifications from high-level natural language plans -- letting the main agent focus on reasoning while delegating context-intensive operations to clean context windows. On SWE-Bench Verified, this decomposition raises resolve rate by 2.1 pp and cuts inference cost by 17.9%, with consistent gains across multiple reasoning-model families (Kimi-K2, MiniMax-M2.1, GLM-4.7). We further show that effective edit-format selection can be trained into a small model rather than requiring frontier-scale capacity: GRPO training on Qwen3-8B with an adaptive find-replace/whole-file-rewrite policy improves edit success by 12.5 pp and brings an 8B open-source editor to parity with GPT-5-nano on downstream SWE-Bench resolve rate. To enable rapid editor iteration, we release PR-Edit, a lightweight evaluation whose scores correlate strongly with SWE-Bench resolve rate. We release our code at https://github.com/microsoft/SWE-Edit.

1 Introduction

SWE-Edit addresses code-editing interfaces that couple exploratory inspection with format-sensitive editing, separating the Viewer, main agent, and Editor. The paper reports gains in resolve rate and inference cost, alongside an approach to training adaptive editors.

1 Introduction

  • The standard interface couples code inspection, modification planning, and edit execution, forcing exploration and formatted edit generation into one context window.Exploration can retain irrelevant snippets, while reliable editing requires focused attention to precise locations and formats.Source: §1 · p. 1
  • SWE-Edit separates what the agent sees, decides, and executes through a Viewer, an unchanged main agent, and an Editor.The Viewer returns task-relevant code, while the Editor executes modifications from a file path and natural-language instruction.Source: §1 · p. 2
  • SWE-Edit raises SWE-Bench Verified resolve rate by 2.1 pp and cuts inference cost by 17.9%.The framework separates inspection and modification into specialized subagents, leaving the main agent to reason and orchestrate.Source: §1 · p. 2
  • PR-Edit provides a lightweight editor-level evaluation, and the paper trains Qwen3-8B with GRPO to choose editing formats adaptively.The authors report that the trained editor matches GPT-5-nano on PR-Edit and downstream resolve rate; scaling from GPT-5-mini to GPT-5 yields only +0.4 pp resolve rate at 5.8× the editor cost.Source: §1 · pp. 2–3

2 Related Work

Prior work spans code-completion and repository-level agents, task-level multi-agent decomposition, and training or adaptation of SWE agents. SWE-Edit instead redesigns the editing interface and isolates the editor for targeted training.

2 Related Work

  • Earlier work spans code completion, code editing, repository-level engineering, staged pipelines, and tool-using agents.SWE-Edit redesigns the code editing interface itself.Source: §2 · p. 3
  • Prior SWE multi-agent systems divide tasks into roles, whereas SWE-Edit separates interface operations to address inspection pollution and format-sensitive editing.Aider Architect separates reasoning from edit formatting but does not address context pollution from prior exploration.Source: §2 · p. 3
  • Unlike parallel SWE-agent training efforts, SWE-Edit keeps the main agent unchanged, trains only the editor subagent, and uses PR-Edit for iteration.Its interface-level scaffolding can be applied to closed-source API models without retraining.Source: §2 · p. 3

3 Method: The SWE-Edit Framework

SWE-Edit uses a two-stage optimization framework: interface-level decomposition separates inspection from modification, and editor training adapts the editing mode to task characteristics.

3.1 Scaffolding Optimization

  • The Viewer returns task-relevant code and the Editor executes natural-language edit instructions, each in a specialized context while the main agent focuses on problem-solving.Both subagents use smaller, cost-efficient models; the Viewer prompt asks for complete logical blocks with surrounding context, and the main agent can refine retrieval requests.Source: §3.1 · pp. 3–4

3.2 Model Optimization

  • Find-and-replace is token-efficient for localized changes but brittle to whitespace mismatches, while whole-file rewrite is robust for restructuring but costly and error-prone on long files.The Editor jointly selects an editing mode and generates its output from file contents and an edit instruction, trained with GRPO using a normalized match reward.Source: §3.2 · p. 4

4 Experiments

The experiments test interface decomposition and adaptive editor training, reporting improvements in cost-performance and edit reliability. They evaluate the scaffolding on SWE-Bench Verified and train an editor to select editing modes by task.

4.1 General Setup

  • Evaluation uses SWE-Bench Verified’s 500 real-world GitHub issues, with three runs per configuration and resolve rate, cost, edit success, and tool calls as metrics.Scaffolding experiments use GPT-5 as main agent and GPT-5-mini for both subagents; model-level experiments train Qwen3-8B with GRPO.Source: §4.1 · p. 4

4.2 Scaffolding-Level Results: Decomposition Yields Cost-Performance Synergy

  • 72.0% resolve rate at $200.1 cost gives SWE-Edit the highest resolve rate and lowest cost, improving over baseline by 2.1 pp and reducing cost by 17.9%.Edit success reaches 96.9% (+3.5 pp); non-cached main-agent input falls 34.5%, from 276.7K to 181.3K tokens.Source: Table 1 · p. 5, §4.2 · p. 6, Figure 3 · p. 6

Generalization to Diverse Reasoning Models

  • Across Kimi-K2, MiniMax-M2.1, and GLM-4.7, SWE-Edit raises resolve rate by 1.6–4.1 pp and edit success by 12.8–18.3 pp.Configurations change only the main-agent model; each is run twice on the first 100 SWE-Bench Verified instances.Source: Generalization to Diverse Reasoning… · p. 6, Table 2 · p. 6

4.3 Model-Level Results: Training Adaptive Editors

  • Qwen3-8B is trained with GRPO as an adaptive editor using 3.5K natural-language edit examples generated from open-source pull requests.The examples are split at the pull-request level into 2.8K training, 200 validation, and 500 test instances; the training uses 520 rollout steps.Source: §4.3 · p. 6, §4.3.1 · pp. 6–7

4.3.1 Training Setup

  • PR-Edit is a cheaper, faster editor evaluation whose scores predict downstream SWE-Bench model ordering (Pearson r=0.98 across four editor models).The authors treat this small-sample correlation primarily as a model-selection signal, not a precise estimate.Source: §4.3.1 · p. 7

4.3.2 Evaluation of Adaptive Editor Training

  • GRPO-trained Qwen3-8B raises SWE-Bench edit success from 68.6% to 81.1% (+12.5 pp) and resolve rate from 68.5% to 69.9% (+1.4 pp).On PR-Edit, format success rises from 76.8% to 90.4% (+13.6 pp) and GPT Grader accuracy from 56.0% to 68.4% (+12.4 pp); the trained model exceeds GPT-5-nano across all metrics.Source: §4.3.2 · p. 7, Table 4 · p. 7, Table 3 · p. 7

4.4 Ablation Studies

  • Adaptive format selection outperforms fixed find-replace on PR-Edit and SWE-Bench by matching localized edits to find-replace and complex refactoring to whole-file rewrite.The adaptive policy initially trails fixed find-replace in validation reward, then surpasses it.Source: Figure 2 · p. 5, §4.4 · p. 8, Table 5 · p. 8
  • Replacing GPT-5-mini with GPT-5 as editor improves resolve rate by only 0.4% at 5.8× the cost, while the viewer performs identically with either model.The results indicate that editor format-level decision-making can be learned in a much smaller model rather than emerging only at scale.Source: §4.4 · p. 8

5 Conclusion

SWE-Edit presents a pipeline of modular scaffolding, lightweight editor evaluation, and reinforcement-learning-based editor training. The trained Qwen3-8B editor improves edit success by 12.5 pp.

5 Conclusion

  • The scaffold improves SWE-task performance while saving inference cost, and PR-Edit offers a lightweight signal for downstream agent performance.End-to-end SWE-Bench iteration costs about $200 and several hours per run.Source: §5 · p. 8
  • 12.5 pp improvement in edit success on Qwen3-8B comes from GRPO with a normalized match reward.The conclusion says this substantially exceeds what model scaling alone provides.Source: §5 · p. 8
  • The paper presents scaffolding, benchmarking, and editor training as a deployable, cost-efficient recipe for code-editing subagents.SWE-Edit is framed as a two-stage optimization framework for the code editing interface.Source: §5 · p. 8

Limitations

The current editor training setup uses an isolated model and a static reward derived from ground-truth edits; the authors identify end-to-end agentic training as a natural extension.

Limitations

  • The editor is trained in isolation with a static reward signal derived from ground-truth edits.This is the stated limitation of the current approach.Source: Limitations · p. 8
  • An end-to-end agentic reinforcement-learning loop could provide feedback from the main agent’s downstream success or failure.The authors describe this as a natural extension.Source: Limitations · p. 8
  • The proposed loop could train for collaboration qualities such as edits that are easier for the main agent to verify or debug.These qualities go beyond formatting correctness.Source: Limitations · p. 8
  • A complementary evaluation direction is an agent-as-a-judge using broader repository context instead of comparing two diffs in isolation.Source: Limitations · p. 8

A Implementation Details

The appendix describes the baseline tools, SWE-Edit’s delegated file interface, and the shared task prompt used in experiments.

A.1 Baseline Agent Scaffolding

  • The baseline scaffolding uses execute_bash for shell commands and str_replace_editor for file operations via exact string replacement.The editor supports viewing, creating, and editing files.Source: §A.1 · p. 10

A.2 SWE-Edit Agent Scaffolding

  • SWE-Edit replaces the baseline file editor with a unified llm_editor that delegates viewing and editing to subagents, while execute_bash remains unchanged.The tool supports file viewing, creation, and editing; the Viewer returns relevant line ranges and the Editor can use search-replace or rewrite the file.Source: §A.2 · pp. 10–11
  • The Viewer prompt asks for relevant line ranges as JSON, while the Editor prompt permits exact search-replace blocks or a whole-file rewrite.The Editor uses an empty SEARCH block to trigger a full rewrite.Source: §A.2 · pp. 10–11

A.3 System Prompt

  • Both agent variants receive the same task prompt, which asks for minimal non-test changes, reproduction and verification, and consideration of edge cases.The prompt’s steps include exploring the repository, reproducing the error, editing source code, and rerunning the reproduction script.Source: §A.3 · pp. 12–13

B Full Experiment Results

The appendix reports run-to-run variation, clarifies how editor formats are selected in the main experiments, and defines the normalized-match reward’s role in training.

B.1 Per-Run Variance

  • 72.0 vs. 69.9 resolve rate separates SWE-Edit from the baseline, and SWE-Edit has identical resolve rate (±0.0) across three runs.The reported per-run standard deviations are small relative to the resolve-rate gap.Source: §B.1 · p. 13

B.2 Editor Format Selection in Main Experiments

  • GPT-5-mini selects between search-replace and whole-file rewrite per task, while the GRPO-trained Qwen3-8B editor learns the same adaptive selection.Source: §B.2 · p. 13

C.1 Code Normalization

  • The normalized match reward canonicalizes whitespace and removes comments before comparing model output with ground truth, serving as an execution-free proxy for edit correctness.Source: §C.1 · p. 13

C.2 GPT-4.1 Equivalence Grading

This block describes GPT-4.1 equivalence grading, the PR-Edit example format, open-source model selection, and inference configuration. The grader judges logical equivalence while tolerating cosmetic differences; evaluation uses selected reasoning models with configured inference settings.

C.2 GPT-4.1 Equivalence Grading

  • GPT-4.1 assesses whether model and ground-truth edits are logically equivalent, ignoring cosmetic differences such as formatting, comments, and variable naming.The grader receives the original code and both diffs.Source: §C.2 · p. 13

C.3 Dataset Example

  • PR-Edit instances pair pre-merge file content, post-merge ground truth, and a natural-language edit query.The example requires coordinated import and function-call changes.Source: §C.3 · pp. 14–15

D.1 Model Selection

  • The open-source evaluation uses Kimi-K2-Thinking, MiniMax-M2.1, and GLM-4.7, selected for reasoning capability and substantial agentic training.Source: §D.1 · p. 15

D.2 Inference Configuration

  • Inference uses Fireworks AI and official model settings where available, with 16,384 maximum new tokens and top-p 1.0 as common hyperparameters.The evaluation enables Interleaved Thinking and Preserved Thinking for all three models.Source: §D.2 · p. 15, Table 8 · p. 15

D.3 Evaluation Protocol

The evaluation uses the first 100 SWE-Bench Verified instances, running each configuration twice. On held-out PR-Edit instances, the LLM viewer leads retrieval baselines in recall and F1 while reducing context.

D.3 Evaluation Protocol

  • The SWE-Bench Verified evaluation uses the first 100 of 500 instances, with each baseline and SWE-Edit configuration run twice to reduce variance.Source: §D.3 · p. 15

E.1 Viewer vs. Retrieval Baselines

  • 93.8% recall and 0.272 F1: the LLM viewer leads retrieval baselines on 50 held-out PR-Edit instances while reducing context by 60.3%.BM25 has 64.4% context reduction but 53.7% recall; the viewer advantage is most pronounced on files over 300 lines.Source: Table 9 · p. 16, §E.1 · p. 16

E.2 Training Dynamics

Adaptive format selection overtakes fixed find-replace training in final validation reward by learning when to use whole-file rewrite.

E.2 Training Dynamics

  • Adaptive training reaches higher final validation reward than fixed find-replace by learning to invoke whole-file rewrite when find-replace struggles.Fixed find-replace starts higher because it is simpler and most training examples involve localized edits.Source: §E.2 · p. 16

E.3 Scaling the Editor Model

Scaling the editor yields little resolve-rate improvement relative to its added cost, while adaptive training improves edit success on a smaller model. Scaling the viewer produces nearly identical resolve rates at matched cost.

E.3 Scaling the Editor Model

  • 12.5 pp higher edit success on Qwen3-8B with GRPO contrasts with only 0.4 pp higher resolve rate when scaling GPT-5-mini to GPT-5 at 5.8× editor cost.The GPT-5 comparison is 72.0% to 72.4%, with editor cost rising from $5.4 to $31.2 per run.Source: Table 10 · p. 16, §E.3 · p. 16

E.4 Scaling the Viewer Model

  • 70.2% versus 70.3% SWE-Bench resolve rate: replacing GPT-5-mini with GPT-5 as viewer is within run-to-run variance at matched total cost of $225.Source: §E.4 · p. 16
Loading 2604.26102v2…