Skip to content

microsoft/SWE-Edit

SWE-Edit

Rethinking Code Editing for Efficient Software Engineering Agents

Paper License: MIT Python


This is the official GitHub repository for the paper "SWE-Edit: Rethinking Code Editing for Efficient SWE-Agent".

Overview

SWE-Edit is a dual-optimization framework that improves both the performance and efficiency of code editing in LLM-based software engineering agents.

Method

SWE-Edit addresses the context coupling problem in traditional code editing interfaces through:

  1. Scaffolding-Level Optimization: Decomposing the code editing interface into specialized subagents

    • Viewer Subagent: Extracts task-relevant code snippets on demand, eliminating context pollution
    • Editor Subagent: Executes modifications from natural language instructions, decoupling reasoning from format-sensitive generation
  2. Model-Level Optimization: Training an adaptive editor with GRPO that learns to select between editing modes (find-replace vs. whole-file rewrite) based on task characteristics

SWE-Edit Framework Architecture
Figure 1: Overview of the SWE-Edit framework showing the dual optimization mechanism with Viewer and Editor subagents.

Results on SWE-bench Verified

Table 1: Main results comparing baseline vs. SWE-Edit on SWE-bench Verified (500 instances, 3 runs).

Configuration Resolved (%) Cost ($) Edit Success (%)
Baseline 69.9 243.7 93.4
SWE-Edit 72.0 (+2.1) 200.1 (-17.9%) 96.9 (+3.5)

SWE-Edit achieves both higher performance and lower cost, breaking the typical accuracy-cost trade-off.

Installation

We use uv for Python environment management.

git clone https://github.com/microsoft/SWE-Edit.git
cd SWE-Edit
uv sync

For SWE-bench evaluation:

uv sync --extra eval

Configuration

Main Agent Configuration

Create a .env file in the project root:

OpenAI:

API_TYPE="OPENAI"
OPENAI_API_KEY=<your-api-key>
MODEL=gpt-4o

Anthropic:

API_TYPE="ANTHROPIC"
ANTHROPIC_API_KEY=<your-api-key>
MODEL=claude-sonnet-4-5-20250929

Azure OpenAI:

API_TYPE="AZURE_OPENAI"
AZURE_API_KEY=<your-api-key>
AZURE_ENDPOINT=<your-endpoint>
DEPLOYMENT=<deployment-name>

Editor/Viewer Subagent Configuration

The editor and viewer subagents can use different (typically smaller and cheaper) models. Configure them in one of two ways:

Option 1: Environment variables (recommended for simple setups)

Add to your .env file with the LLM_EDITOR_ or LLM_VIEWER_ prefixes:

# Main agent uses GPT-4
API_TYPE="OPENAI"
OPENAI_API_KEY=<your-api-key>
MODEL=gpt-4o

# Editor uses GPT-5-mini
LLM_EDITOR_API_TYPE="OPENAI"
LLM_EDITOR_OPENAI_API_KEY=<your-api-key>
LLM_EDITOR_MODEL=gpt-5-mini

# Viewer uses GPT-5-mini
LLM_VIEWER_API_TYPE="OPENAI"
LLM_VIEWER_OPENAI_API_KEY=<your-api-key>
LLM_VIEWER_MODEL=gpt-5-mini

Option 2: JSON configuration files

Create JSON files under ./api_configs/ directory. For example, api_configs/editor/gpt-5-mini.json or api_configs/viewer/gpt-5-mini.json:

{
  "api_type": "OPENAI",
  "api_key": "your-api-key",
  "model": "gpt-4o-mini"
}

Then specify the model type during evaluation (see SWE-bench Evaluation section).

Multi-API Load Balancing

For large-scale evaluation, you can provide multiple API keys by appending _N to environment variables:

API_TYPE_1="OPENAI"
OPENAI_API_KEY_1=<key-1>
MODEL_1=gpt-4o

API_TYPE_2="ANTHROPIC"
ANTHROPIC_API_KEY_2=<key-2>
MODEL_2=claude-sonnet-4-5-20250929

The agent will randomly select a configuration to distribute rate limits.

Quick Start

Run the minimal agent on a simple task to verify your setup:

uv run -m sweedit.main "First run pwd to check the current directory, then create a file called hello.py in that directory with a function that prints 'Hello, World!'"

This runs a minimal agent with basic tools (bash execution, string replacement editor, and finish) to verify your API configuration is working properly. Trajectories are saved to .traj/ for analysis.

SWE-bench Evaluation

We provide complete evaluation scripts for SWE-bench Verified.

First, build the package:

uv build

Then run evaluation (see evaluation/swebench-verified/README.md for details):

uv run python evaluation/swebench-verified/main.py \
  --local_traj_path <path-to-trajectories> \
  --run_name <experiment-name> \
  --agent_type llm-editor \
  --llm_editor_model gpt-5-mini \
  --max_workers <num-workers>

The --llm_editor_model flag specifies which model to use for the editor/viewer subagents (uses LLM_EDITOR_ prefixed env vars or JSON config files in ./api_configs/).

Repository Structure

.
├── src/sweedit/              # Core framework
│   ├── core/                 # Agent scaffolding
│   │   ├── agent.py          # Base agent
│   │   ├── agenthub/         # Agent implementations
│   │   └── llm.py            # LLM interface
│   └── tools/                # Agent tools
│       ├── llm_editor.py           # LLM-backed editing tool
│       ├── llm_file_editor.py      # Editor subagent
│       ├── execute_bash.py         # Shell execution
│       └── ...
└── evaluation/
    └── swebench-verified/    # SWE-bench evaluation scripts

Citation

If you use SWE-Edit in your research, please cite:

@article{zhang2026sweedit,
  title={SWE-Edit: Rethinking Code Editing for Efficient SWE-Agent},
  author={Zhang, Yikai and Pei, Jiaxin and Li, Kenan and Wang, Maoquan and Pan, Jin and Kang, Yu and Fu, Shengyu and Nallipogu, Elsie and Hu, Junjie and Huang, Yufan and Jin, Zijian},
  journal={arXiv preprint},
  year={2026}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.


Developed at Microsoft with University of Wisconsin–Madison

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.

About

Rethinking Code Editing for Efficient Software Engineering Agents

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors