SWE-agent
Princeton NLP
An autonomous AI software engineer agent developed by the Princeton NLP team, focused on resolving GitHub issues.
Overview
SWE-agent is an LLM-based autonomous agent developed by the Princeton NLP team. It is specifically designed to solve real-world software engineering problems, such as fixing GitHub issues and implementing new features. The core innovation of SWE-agent is the Agent-Computer Interface (ACI), an interaction interface designed specifically for LLMs that enables the agent to efficiently browse and edit code. In the SWE-bench benchmark, SWE-agent achieved a 12.29% resolution rate.
Installation
SWE-agent can be installed via pip or Docker. Docker is recommended to ensure environment consistency. Python 3.9+ and Docker are required before installation. After installation, you need to configure an OpenAI API key or a key from another LLM provider.
# Install with pip
pip install swe-agent
# Or use Docker
docker pull sweagent/swe-agent:latest
# Configure API key
export OPENAI_API_KEY=your-api-key-hereConfiguration
SWE-agent is configured via configuration files, allowing you to customize the LLM model, ACI behavior, tool configuration, and more. Configuration files support YAML format and offer flexible adjustment of the agent's behavior. Users can configure different command templates, edit formats, and search strategies.
# config.yaml example
agent:
model:
name: gpt-4
api_base: https://api.openai.com/v1
tools:
- name: search
- name: edit
- name: view
max_steps: 100Running Tasks
Running SWE-agent to solve a task requires providing the problem description and the target codebase. The agent will automatically browse the code, locate the problem, write the fix, and verify it. You can run a single task or batch process multiple issues.
# Run a single task
swe-agent \
--model_name gpt-4 \
--data_path https://github.com/owner/repo/issues/123 \
--repo_path /path/to/repo \
--config_file config.yaml
# Batch run
swe-agent --data_path swe-bench.jsonl --apply_suiteGitHub Integration
SWE-agent can fetch tasks directly from GitHub issues and automatically create PRs to submit fixes. Through the GitHub API, the agent can read issue content, clone repositories, submit changes, and create pull requests. This achieves end-to-end automation from issue to PR.
# Run from a GitHub issue
swe-agent \
--data_path https://github.com/owner/repo/issues/42 \
--repo_path /path/to/clone \
--output_dir ./results \
--action_type submitCustom Tools
SWE-agent supports custom tool extensions. Users can define new ACI commands, such as custom search, language-specific parsers, and more. By extending the toolset, you can optimize the agent's capabilities for specific projects or tech stacks.
# Custom tool example
class CustomSearchTool:
def __init__(self):
self.name = "custom_search"
self.description = "Search with custom patterns"
def run(self, query: str):
# Implement search logic
return resultsBenchmarks
SWE-agent performs excellently on the SWE-bench benchmark, which contains 2,294 real GitHub issues. SWE-agent's resolution rate is significantly higher than other general LLM agents. Benchmark results can be used to compare the effects of different configurations and models.
Advanced Usage
Advanced usage includes: using custom models, configuring multi-step reasoning, adjusting ACI behavior, integrating custom toolchains, and more. SWE-agent supports locally deployed open-source models such as Llama and Mistral, providing inference services via vLLM or Ollama.
# Use a local model
swe-agent \
--model_name custom-llama \
--api_base http://localhost:8000/v1 \
--config_file config.yamlTroubleshooting
Common issues include: API rate limits, Docker permission issues, model output format errors, and more. It is recommended to check API key configuration, Docker installation, and network connectivity. For complex tasks, you can adjust the max_steps parameter and model temperature. Reviewing log files helps diagnose problems.
More AI Guides
Claude Code
A terminal-native AI coding agent from Anthropic that autonomously understands codebases, edits files, runs commands, and completes multi-step development tasks.
OpenAI Codex
An official command-line AI coding assistant from OpenAI, built on the GPT model family and optimized for code generation and development workflows.
Trae
ByteDance's AI-native IDE—the first of its kind in China—deeply integrates LLMs such as Doubao and DeepSeek, supporting natural-language interaction and multimodal collaboration.
Cursor
A next-generation AI code editor from Anysphere with a built-in Composer agent that can run multiple coding tasks in parallel.
GitHub Copilot
An AI coding assistant co-developed by GitHub and OpenAI, offering code completion, chat, and an Agent mode.
Windsurf
An AI-native IDE from Codeium with a built-in Cascade agent that deeply couples the terminal and editor.