AI-powered GitHub Issue Auto-Fix Agent
Automatically analyze, fix, and generate patches for GitHub Issues using a multi-agent pipeline.
Point AutoPatch at any GitHub issue and get a ready-to-apply patch in minutes.
Web UI:
- Enter a repository URL and issue number, then click Run AutoPatch
- Watch the live agent pipeline: Planner → Coder → TestRunner → Reviewer
- Download the generated
.diffor click Create PR to open a pull request directly
CLI:
python autopatch.py https://github.com/daixinwang/bug-test 1
# → patches/issue-1_20260510_120000.diff
# Apply the patch to your local checkout
git apply patches/issue-1_20260510_120000.diffCore capabilities:
- 🔍 Autonomous codebase navigation —
list_directory,search_codebase,find_definition,grep_in_file - ✍️ Automated code repair — Coder agent reads, writes, and verifies files
- 🌐 Multi-language test execution —
pytest,npm test,cargo test,go test,mvn test,make test, and more - 🔄 Review-and-retry loop — Reviewer sends failed patches back to Coder (up to 3 retries, history trimmed automatically)
- 📄 Standard
.diffoutput — Apply withgit apply, no manual editing required - 🌊 Real-time token streaming — LLM output streams character-by-character in the terminal window
New in this release:
- ♻️ Checkpoint resume — Interrupted tasks resume from the last saved state; no need to restart from scratch (requires
DATABASE_URL) - 🔀 Create PR — One-click GitHub Pull Request creation directly from the result page
- 🌐 i18n interface — Web Dashboard supports Chinese / English toggle
- 📋 History sidebar — All tasks are persisted and accessible from a collapsible sidebar
START
│
▼
📋 Planner Analyzes Issue + repo language, produces structured execution plan
│
▼
💻 Coder ◄──────────────────────────────────────────┐
│ │ REJECT
├── tool_calls ──► 🔧 Tools (read/write/search) │ (max 3 retries, history trimmed)
│ │ │
│ └──► Coder (loop) │
│ │
└── done ──► 🧪 TestRunner (multi-language tests) │
│ │
▼ │
🔍 Reviewer ────────────────────────┘
│
└── PASS ──► 📄 .diff file ──► END
Checkpoints are persisted to PostgreSQL after each node — enabling resume after interruption.
AutoPatch includes built-in semantic code retrieval to bridge the vocabulary gap between issue descriptions and source code identifiers (e.g., an issue says "login fails" but the actual function is called authenticate_user).
- AST chunking — Python
.pyfiles in the target repo are parsed by theastmodule and split into function/class/method/module chunks - Vector indexing — Each chunk is embedded with an OpenAI-compatible embedding API and stored in ChromaDB (
.autopatch_cache/rag_index/) - Hybrid retrieval — Vector similarity + BM25 keyword search are fused via Reciprocal Rank Fusion (RRF), returning Top-5 results
- Workflow integration — An
index_builder_noderuns automatically before the Planner; the Coder can callsemantic_search_codebaseas a tool
| Environment Variable | Default | Description |
|---|---|---|
OPENAI_EMBED_API_KEY |
falls back to OPENAI_API_KEY |
Dedicated OpenAI API key for embeddings |
OPENAI_EMBED_BASE_URL |
(official endpoint) | Custom embedding API base URL |
RAG_EMBEDDING_MODEL |
text-embedding-3-small |
Embedding model name |
RAG_EMBEDDING_DIMENSIONS |
0 |
Optional embedding vector dimension; 0 means do not send dimensions |
RAG_CACHE_DIR |
.autopatch_cache |
Root directory for index cache |
- Only Python repositories are indexed; other languages are silently skipped
- The index supports incremental updates — unchanged chunks are not re-embedded on subsequent runs
- If indexing fails for any reason, the pipeline continues without RAG (Coder falls back to grep tools)
semantic_search_codebasecoexists with the existingsearch_codebase(grep) tool — use grep for exact identifier lookups, semantic search for concept-based queries
- Python 3.10+
- Node.js 18+ (for frontend, only if running manually)
- Git
git clone https://github.com/daixinwang/AutoPatch.git
cd AutoPatch
# Backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Frontend (only needed for Option D)
cd frontend && npm installcp .env.example .envEdit .env:
OPENAI_API_KEY=sk-your-chat-api-key-here
GITHUB_TOKEN=ghp_your-github-token-here # Optional, prevents rate limiting
# Optional overrides
PLANNER_MODEL_NAME=claude-haiku-4-5-20251001
CODER_MODEL_NAME=claude-sonnet-4-6
TEST_RUNNER_MODEL_NAME=claude-haiku-4-5-20251001
REVIEWER_MODEL_NAME=claude-sonnet-4-6
OPENAI_BASE_URL=https://your-proxy/v1 # Anthropic-compatible chat endpoint
# Optional embedding overrides
OPENAI_EMBED_API_KEY=sk-your-openai-embedding-key-here
OPENAI_EMBED_BASE_URL=https://api.openai.com/v1
RAG_EMBEDDING_MODEL=text-embedding-3-small
RAG_EMBEDDING_DIMENSIONS=0
# Alibaba Cloud Bailian DashScope compatible embedding example
# OPENAI_EMBED_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
# RAG_EMBEDDING_MODEL=text-embedding-v4
# RAG_EMBEDDING_DIMENSIONS=1024
# Checkpoint resume (optional — enables task resume after interruption)
DATABASE_URL=postgresql://user:password@host:5432/autopatch
# Server options
CORS_ORIGINS=http://localhost:5173 # Comma-separated allowed origins
MAX_CONCURRENT_PATCHES=3 # Max simultaneous pipeline runs (default: 3)
AUTOPATCH_API_KEY=your-secret-key # Optional: enable Bearer token auth
LOG_LEVEL=INFO # DEBUG / INFO / WARNING / ERROR
# Agent tuning (optional)
MAX_REVIEW_RETRIES=3 # Max reviewer reject-and-retry cycles (default: 3)
MAX_CODER_STEPS=40 # Max tool calls per coder attempt (default: 40)Option A — Docker (recommended):
# Starts backend + frontend + PostgreSQL (checkpoint resume enabled automatically)
docker-compose up --build
# Open: http://localhost:8000The Docker image bundles the compiled frontend — no separate frontend process needed.
Option B — CLI (full pipeline):
source .venv/bin/activate
python autopatch.py https://github.com/owner/repo 42Option C — Local workspace debug (skip clone):
python autopatch.py owner/repo 42 --workspace-dir /path/to/local/repo --keep-workspaceOption D — Web Dashboard (manual):
# Terminal 1: start backend
source .venv/bin/activate
uvicorn server:app --reload --port 8000
# Terminal 2: start frontend
npm --prefix frontend run dev
# Open: http://localhost:5173# In your target repository
git apply patches/issue-42_20260402_120000.diffpython autopatch.py <repo_url> <issue_number> [options]
Options:
--output-dir DIR Output directory for .diff files (default: ./patches)
--branch BRANCH Clone a specific branch (default: repo default)
--workspace-dir DIR Use existing local repo (skip clone)
--keep-workspace Keep the cloned temp directory after run
--no-comments Skip fetching issue comments
AutoPatch uses one evaluation protocol for local sanity benchmarks and SWE-bench style cases.
# Validate local fixtures without model calls
python -m eval.unified --dataset sanity-v1 --mode baseline-only
# Run the real agent on richer local sanity cases
python -m eval.unified --dataset sanity-v2 --mode agent
# Run a pinned smoke set of real SWE-bench Lite instances
python -m eval.unified --dataset swebench-smoke --mode agent
# Run selected SWE-bench Lite instances
python -m eval.unified --dataset swebench-lite --mode agent --instance-ids <instance_id>Results are written to eval/results/<run_id>/ with per-case case.json, issue.md, patch.diff, changed-files.json, test logs, and verdict.json.
| Layer | Technology |
|---|---|
| Agent Framework | LangGraph 0.2.x |
| LLM | Anthropic-compatible chat models via langchain-anthropic (ChatAnthropic, token streaming enabled) |
| Embeddings | OpenAI Embeddings API via openai (text-embedding-3-small by default) |
| Code Search | Python AST + re (no external deps) |
| Test Execution | subprocess sandboxed runner — Python, Node.js, Rust, Go, Java, Make |
| GitHub Integration | GitHub REST API v3 (requests) |
| Backend API | FastAPI + Uvicorn (SSE streaming) |
| Checkpoint Storage | PostgreSQL 16 (via langgraph-checkpoint-postgres) |
| Frontend | React 18 + TypeScript + Vite |
| Styling | Tailwind CSS (dark / light / system theme) |
| Icons | lucide-react |
| Internationalization | React Context + JSON translation files (zh/en) |
- Tool permissions are layered: Coder (read+write+search), TestRunner (execute-only), Reviewer (read-only)
- Path traversal protection — all file operations are sandboxed within the workspace directory; absolute paths and
../traversal are rejected - Command execution is sandboxed: whitelist-only (
pytest,python,npm test,cargo test,go test,mvn test,gradle test,make test), timeout limits (max 120s), output truncation (max 8KB) - API authentication — optional Bearer token auth via
AUTOPATCH_API_KEYenv var; protects all mutation endpoints - Task ID validation — UUID format enforced, preventing path injection in task storage
- Concurrency is capped via semaphore (
MAX_CONCURRENT_PATCHES) to prevent resource exhaustion - API keys are loaded via
.env— never committed (.gitignoreenforced)
Made with ❤️ using LangGraph + React


