RepoPilot: LLM-based Test-Driven Code Repair Agent
RepoPilot 是一个面向 Python 项目的代码修复 Agent。用户上传 .zip 项目后,系统会自动运行 pytest,分析失败测试,读取相关源码,生成最小补丁,重新运行测试,并在前端展示修复前后结果、补丁 diff、修复后的文件预览、下载链接和完整 Agent 执行轨迹。
当前版本适合本地演示和可信代码测试。因为系统会运行上传项目中的
pytest,公开部署前需要加入 Docker 沙箱、资源限制和网络隔离。
- 中文 Streamlit 前端页面
- 上传
.zipPython 项目 - 自动运行修复前 / 修复后
pytest - ReAct-style Agent 工具调用循环
edit_file(path, old_text, new_text)局部补丁编辑- 规则 Reflection + LLM Reflection
- 规则 Replanning + LLM Replanning
- classic 手写循环运行时 + LangGraph 图式运行时
- 自动生成 unified diff
- 前端展示问题诊断与修复说明
- 前端展示修复后的文件内容
- 前端下载修复后的项目 zip
- 前端下载
patch.diff - JSON / Markdown trajectory logging
- 10 个 seeded Python bug benchmark
- 支持评估和 ablation 脚本
RepoPilot/
├── app.py # 中文 Streamlit Web Demo
├── agent/ # Agent Core
│ ├── main.py # classic ReAct loop
│ ├── graph_agent.py # LangGraph runtime
│ ├── tools.py # list_files/read_file/search_code/edit_file/run_tests
│ ├── llm.py # mock + real LLM action decision
│ ├── prompts.py # prompt construction
│ ├── planner.py # planning + LLM replanning
│ ├── reflector.py # reflection + LLM reflection
│ ├── memory.py # reflection memory
│ ├── trace.py # trajectory logging
│ └── evaluate.py # benchmark evaluation
├── backend/
│ ├── workspace.py # zip extraction and workspace management
│ ├── diff_utils.py # unified diff generation
│ └── service.py # repair-job service + runtime switch
├── benchmark/ # generated seeded bugs and zip files
├── scripts/
│ ├── create_benchmark.py
│ ├── check_benchmark.py
│ ├── smoke_test_backend.py
│ └── summarize_reports.py
├── reports/
├── runs/
└── requirements.txt
pip install -r requirements.txt依赖包括:
pytest
openai
streamlit
langgraph
Mock 模式不需要 API Key,默认可以稳定修复 bug_001_divide_zero。
python scripts/create_benchmark.py
python scripts/smoke_test_backend.py --runtime classic期望看到:
Initial Passed: False
Final Passed: True
Modified Files: ['calculator.py']
Patch Diff Path: runs/<job_id>/patch.diff
Repaired Zip Path: runs/<job_id>/repaired_project.zip
测试 LangGraph 运行时:
python scripts/smoke_test_backend.py --runtime langgraph如果提示缺少 langgraph,请运行:
pip install langgraphstreamlit run app.py打开页面后,默认设置为:
Agent 运行时:classic
使用 Mock LLM:开启
启用 Reflection:开启
启用 Planning:开启
上传示例:
benchmark/bug_001_divide_zero.zip
点击:
开始运行 RepoPilot
前端会展示:
- 问题诊断与修复说明
- 哪里出了问题
- 为什么出问题
- Agent 如何修改
- 修复后是否通过测试
- 测试结果:修复前
- 补丁 Diff
- 测试结果:修复后
- 修复后结果
- 修改过的文件
- 修复后文件预览
- 下载修复后的项目 zip
- 下载
patch.diff
- Agent 执行轨迹
OpenAI API:
export OPENAI_API_KEY="your_key"
export OPENAI_MODEL="gpt-4o-mini"
streamlit run app.pyOpenAI-compatible 本地服务:
export OPENAI_API_KEY="dummy"
export OPENAI_BASE_URL="http://localhost:8000/v1"
export OPENAI_MODEL="your-model-name"
streamlit run app.py然后在侧边栏关闭:
使用 Mock LLM
可选打开:
启用 LLM Reflection
启用 LLM Replanning
每次运行会生成一个 job:
runs/{job_id}/
├── upload/ # 上传的 zip
├── repo/ # 修复后的项目
├── before/ # 修复前快照
├── patch.diff # 生成的补丁文件
├── repaired_project.zip # 修复后的项目压缩包
├── repair_report.md # 问题诊断与修复说明
├── traces/
│ ├── {job_id}.json
│ └── {job_id}.md
└── reflection_memory.json
前端底部也会显示本地路径。
生成 benchmark:
python scripts/create_benchmark.py
python scripts/check_benchmark.py运行完整 Agent:
python -m agent.evaluate \
--benchmark benchmark \
--output reports/eval_full.json \
--trace_dir reports/traces/full \
--max_steps 12运行 LLM Reflection + LLM Replanning:
python -m agent.evaluate \
--benchmark benchmark \
--output reports/eval_llm_reflect_replan.json \
--trace_dir reports/traces/llm_reflect_replan \
--max_steps 12 \
--use_llm_reflection \
--use_llm_replanningReAct only:
python -m agent.evaluate \
--benchmark benchmark \
--output reports/eval_react_only.json \
--trace_dir reports/traces/react_only \
--max_steps 12 \
--disable_reflection \
--disable_planningFull Agent:
python -m agent.evaluate \
--benchmark benchmark \
--output reports/eval_full.json \
--trace_dir reports/traces/full \
--max_steps 12汇总结果:
python scripts/summarize_reports.py输出:
reports/ablation_table.md
reports/ablation_table.csv
RepoPilot 会执行上传项目中的 pytest,因此会运行用户代码。当前版本只建议本地运行和可信代码测试。公开部署前应加入:
- Docker 沙箱
- CPU / 内存限制
- 网络隔离
- 文件系统隔离
- 更严格的上传大小和文件类型限制
- 每个 job 独立状态管理
RepoPilot: LLM-based Test-Driven Code Repair Agent
- Built a deployable code repair assistant that accepts Python project zip files, runs pytest, diagnoses failures, generates minimal patches, and verifies fixes automatically.
- Implemented a ReAct-style agent with structured tool calling, safe patch editing, planning, reflection memory, LLM reflection, LLM replanning, and trajectory logging.
- Developed dual runtimes: a classic hand-written ReAct loop and a LangGraph-based state graph runtime.
- Built a Chinese Streamlit interface for project upload, patch diff visualization, repaired file preview, downloadable repaired project zip, pytest results, and agent trajectory inspection.
- Designed a seeded Python bug benchmark and evaluation scripts for repair success rate, average tool steps, invalid actions, and unsafe edit attempts.