第3章 开源 Code Agent 框架
OpenHands/Aider/Continue.dev/Cline/Roo Code/SWE-Agent/Plandex/Auto-Code-Rover 8 大开源框架架构、核心能力、选型决策树
第3章 🔓 开源 Code Agent 框架
商业产品好用但闭源,开源框架给你三件事:完全可控(自己跑、自己改)、模型自由(挂任何 LLM)、学习样本(读 OpenHands/Aider 源码 = 学习 ACI 设计的最佳路径)。
这一章给 8 大开源选项的架构对比 + 选型决策树。
📑 目录
- 一、开源 Code Agent 全景图
- 二、OpenHands(原 OpenDevin)⭐
- 三、Aider(repo-map 经典)⭐
- 四、Continue.dev(IDE 插件平台)
- 五、Cline / Roo Code(VS Code Plan-Act 双模)
- 六、SWE-Agent(Princeton 论文实现)
- 七、Plandex(自主 Plan 执行)
- 八、其他学术原型
- 九、选型决策树
一、开源 Code Agent 全景图
┌────────────────── 自主长程 Agent ──────────────────┐
│ OpenHands (50K stars) ⭐ — 继承 SWE-Agent │
│ SWE-Agent (Princeton 原版) │
│ Plandex │
│ Auto-Code-Rover / SWE-Search / MAGIS (学术) │
└────────────────────────────────────────────────────┘
┌────────────────── CLI 工具 ─────────────────────┐
│ Aider (30K+ stars) ⭐ — repo map 经典 │
└────────────────────────────────────────────────────┘
┌────────────────── IDE 插件 ─────────────────────┐
│ Continue.dev — VS Code/JetBrains 平台 │
│ Cline (15K+ stars) — VS Code Plan-Act │
│ Roo Code — Cline fork │
└────────────────────────────────────────────────────┘
1.1 5 个核心维度
| 维度 | 含义 |
|---|---|
| Repo 索引 | 是否能感知整个 repo(grep / repo map / 向量索引) |
| 多文件编辑 | 一次任务能改几个文件 |
| 工作流模式 | ReAct / Plan-Act / Plan-Execute |
| Sandbox | 跑代码是否在隔离环境 |
| 模型自由 | 支持哪些 LLM(Anthropic / OpenAI / Local) |
二、OpenHands(原 OpenDevin)⭐
项目地址:https://github.com/All-Hands-AI/OpenHands(50K+ stars,2024-03 起)
核心定位:开源版 Devin,继承并扩展 SWE-Agent 的 ACI 设计。
2.1 架构
┌─────────────────────────────────────────────────┐
│ User │
└────────────────┬────────────────────────────────┘
│ 任务描述
▼
┌─────────────────────────────────────────────────┐
│ OpenHands Agent (LLM) │
│ ┌──────────────────────────────────────────┐ │
│ │ Plan / Act / Reflect / Replan 循环 │ │
│ └──────────────────────────────────────────┘ │
└────────────────┬────────────────────────────────┘
│ Action (tool call)
▼
┌─────────────────────────────────────────────────┐
│ Runtime (sandboxed Docker) │
│ ┌──────────────────────────────────────────┐ │
│ │ bash / file_editor / browser / jupyter │ │
│ └──────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────┐ │
│ │ Repo + Test environment │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
2.2 核心特性
- Sandbox 强:每个任务跑在 Docker 里,隔离干净
- Multi-Agent 协作:可启动 Manager + Coder + Reviewer 三 agent
- Browser Tool 内置:能开浏览器查 Stack Overflow / 文档
- 完整 SDK:Python
openhands.SDK可程序化调用 - Cloud 版本(2026-04 OpenHands Cloud)— 不用自己装 Docker
2.3 与 SWE-Agent 的关系
OpenHands 在 SWE-Agent 之上加了:
- 更完整的 Action 集合(SWE-Agent 只有 6 个,OpenHands 有 20+)
- Multi-agent 框架
- Browser / Jupyter 等扩展工具
- 更工程化的部署(Docker / SDK / Cloud)
学习推荐:读 OpenHands 源码 = 读最完整的开源 Code Agent 实现。重点关注
openhands/agenthub/目录。
2.4 SWE-bench Verified
OpenHands + Claude Sonnet 4.5 ≈ 66%(2026-Q1)。 OpenHands + GPT-5 ≈ 70%。
三、Aider(repo-map 经典)⭐
项目地址:https://github.com/Aider-AI/aider(30K+ stars,2023-08 起)
核心定位:CLI 工具,作者 Paul Gauthier,git-aware 是最大特色。
3.1 核心创新:Repo Map
不像别的工具暴力把整个 repo 塞 LLM(成本爆炸),Aider 用 tree-sitter 解析 repo,生成一个 “代码地图”:
src/main.py:
class App:
def __init__(self, config)
def run(self)
def shutdown()
src/utils/db.py:
class Database:
def connect(url)
def query(sql)
tests/test_main.py:
def test_run_app()
def test_shutdown_clean()
只给 LLM 类名 + 函数签名,不给函数体——成本降 90%+,但 LLM 仍知道 repo 结构。需要看具体实现时,用 read_file(path) tool 拉取。
这是 Aider 的灵魂设计——后来被 Cursor、OpenHands 等大量借鉴。
3.2 核心特性
- Git-aware:每次 edit 自动 commit,你随时可
git revert - 多语言:支持 100+ 语言(tree-sitter parser)
- Aider polyglot benchmark:作者维护的多语言 leaderboard,业界知名
- 配置极简:
pip install aider-chat+ 设 API key 就能用
3.3 工作流
$ aider --model claude-sonnet-4-5 src/main.py src/utils/db.py
> 在 main.py 里加一个 graceful shutdown 钩子,在 db.py 里加 close()
aider> [显示 diff]
aider> Apply? (y/n): y
aider> [git commit] message: "Add graceful shutdown hook"
3.4 SWE-bench Verified
Aider + Claude Sonnet 4.5 ≈ 64%(2026-Q1)。
使用建议:CLI 党、追求极简、想自己控制 git 流程的人——直接 Aider。
四、Continue.dev(IDE 插件平台)
项目地址:https://github.com/continuedev/continue(20K+ stars)
核心定位:VS Code / JetBrains 的开源 AI 插件,可视为”开源版 Cursor 的 Cmd+K + Tab”。
4.1 架构
┌─────────────────────────────────────┐
│ IDE (VS Code / JetBrains) │
│ ┌────────────────────────────┐ │
│ │ Continue Plugin │ │
│ │ ┌──────────────────────┐ │ │
│ │ │ Provider Layer │ │ │
│ │ │ (LLM API Adapter) │ │ │
│ │ └──────────────────────┘ │ │
│ │ ┌──────────────────────┐ │ │
│ │ │ Indexing Layer │ │ │
│ │ │ (repo embedding) │ │ │
│ │ └──────────────────────┘ │ │
│ │ ┌──────────────────────┐ │ │
│ │ │ Context Provider │ │ │
│ │ │ (@-mention 文件/库) │ │ │
│ │ └──────────────────────┘ │ │
│ └────────────────────────────┘ │
└─────────────────────────────────────┘
4.2 核心特性
- 完全 BYOK:支持 OpenAI / Anthropic / Gemini / Ollama / Together.ai 等
- 模型 mix-and-match:补全用 Codestral,Chat 用 Claude,Edit 用 GPT-4o——一个 IDE 内三个角色用不同模型
- 可定制 prompt:
config.json自定义系统 prompt、上下文 provider - 企业自部署:Continue Hub 支持
4.3 局限
- 不是自主 Agent ——没有 Plan-Execute 模式,主要是 Inline 编辑
- 索引 / 补全延迟比 Cursor 略高(本地索引)
使用建议:不想付 Cursor 钱、想用本地 LLM、想自己改插件——选 Continue。
五、Cline / Roo Code(VS Code Plan-Act 双模)
Cline(原 Claude Dev)项目地址:https://github.com/cline/cline(15K+ stars) Roo Code 是 Cline 的 fork,加了更多 customization。
5.1 核心定位
VS Code 插件,Plan-Act 双模——明显比 Continue 更”自主”:
模式 1 — Plan
Agent 先列出待改文件 + 步骤,用户审批
模式 2 — Act
Agent 直接动手,每个 action(写文件、跑命令)需用户 approve
5.2 核心特性
- 每个 action 用户审批:防止误操作(比 OpenHands 更保守)
- MCP 支持:可挂任何 MCP server
- diff 预览强:写文件前显示完整 diff
- 模型自由:OpenAI / Anthropic / Bedrock / Ollama 等
5.3 与 Continue 的差异
| 维度 | Continue | Cline |
|---|---|---|
| 工作模式 | Inline 编辑(类似 Cursor Cmd+K) | Plan-Act 双模(类似简化版 OpenHands) |
| 审批粒度 | 每个 diff | 每个 action(写/读/跑) |
| 自主度 | 低 | 中 |
| 学习曲线 | 平 | 略陡 |
5.4 Roo Code
Roo Code(原 Roo Cline)是 Cline 的 fork,加了:
- 更多 prompt 自定义
- 多 mode(Code / Architect / Ask)
- 更好的 changelog / settings UX
使用建议:VS Code 用户、想要 Plan-Act 自主性、又想保留人审批——选 Cline 或 Roo Code。
六、SWE-Agent(Princeton 论文实现)
项目地址:https://github.com/SWE-agent/SWE-agent(15K+ stars)
核心定位:NeurIPS 2024 论文 SWE-Agent 的官方实现,Code Agent 学术界鼻祖(详见第 4 章论文精读)。
6.1 核心创新:ACI(Agent-Computer Interface)
SWE-Agent 论文最大贡献——专门为 LLM 设计的 6 个 LM-friendly 工具:
| 工具 | 功能 | LM-friendly 在哪 |
|---|---|---|
goto N | 跳到第 N 行 | 比 vim 直接 |
scroll_up/down | 翻页 | 一次显示 100 行,不爆 context |
open <file> | 打开文件 | 自动展示前 100 行 + 总行数 |
search_dir <pat> | 在目录搜索 | 比 grep 输出更结构化 |
edit <line> <new> | 替换某行 | 失败给错误信息(语法/缩进) |
submit | 提交补丁 | 终止信号 |
6.2 局限
- 学术原型,工程化不如 OpenHands(Docker 部署较复杂)
- 后续被 OpenHands 大幅扩展并取代为生产首选
使用建议:做学术研究、想精读论文 + 复现——直接读 SWE-Agent。生产环境直接用 OpenHands(继承自它)。
七、Plandex(自主 Plan 执行)
项目地址:https://github.com/plandex-ai/plandex(13K+ stars)
核心定位:CLI 工具,完全 plan-driven——所有改动都属于一个”plan”,可 rollback、可 branch。
7.1 核心特性
- Plan 是一等公民:每个任务对应一个 plan,plan 内有 step/iteration/git-like 历史
- Branch / Rollback:可分支尝试不同方案
- 多模型路由:不同步骤用不同模型(plan 用 Opus,执行用 Sonnet)
- CLI + Server:可团队共享 plan
7.2 适用场景
适合长程、可能要尝试多种方案的任务,比如重构、迁移。一般小 bug 修不需要这么重。
八、其他学术原型
| 项目 | 论文 | 特色 |
|---|---|---|
| Auto-Code-Rover | arXiv 2404.05427 | repo 上下文检索 + spec 提取 |
| SWE-Search | arXiv 2410.20285 | MCTS 搜索 + 自我反思 |
| MAGIS | arXiv 2403.17927 | Multi-agent for code(Manager + Repository Custodian + Developer + QA Engineer) |
| CodeR | arXiv 2406.01304 | 多代理 + 任务图 |
| AgentLab(Salesforce) | — | Web agent 平台,扩展到 code |
这些大多是研究 baseline,不是日常工具。生产环境用 OpenHands / Aider / Cursor 即可。
九、选型决策树
Q1: 你想要什么类型?
│
├── CLI 工具
│ ├── 极简、git-aware、单/多文件 → Aider ⭐
│ ├── plan-driven、长任务 → Plandex
│ └── 完整 Agent SDK、Multi-agent → OpenHands
│
├── IDE 插件
│ ├── VS Code,Inline 编辑为主 → Continue.dev
│ ├── VS Code,想要 Plan-Act 自主 → Cline / Roo Code
│ └── JetBrains → JetBrains AI(商业)/ Continue.dev
│
└── 学术研究
├── 复现 SWE-Agent 论文 → SWE-Agent 原版
├── 多 agent 研究 → MAGIS / CodeR / OpenHands
└── 搜索增强 → SWE-Search / Auto-Code-Rover
9.1 想”自己跑通 SWE-bench”
→ OpenHands ⭐(支持完整 SWE-bench evaluator,详见第 9 章实战)
9.2 想嵌入产品(SDK)
→ OpenHands SDK(2026-Q1 公开)或 Aider Python API
9.3 想完全本地(离线)
→ Aider 或 Continue.dev + Ollama 本地模型
9.4 想训练自己的 agent
→ OpenHands(SWE-Gym / SWE-RL 都基于它)
✅ 自我检验清单
- 能说出 OpenHands / Aider 各自的核心创新和适用场景
- 能解释 Aider 的 repo map 设计为什么省 token
- 能区分 Continue / Cline / Roo Code 三家 VS Code 插件
- 能说出 OpenHands 与 SWE-Agent 的传承关系
- 能根据”CLI / IDE / 研究”3 个用户画像给出推荐
📚 参考资料
项目主页
- OpenHands — https://github.com/All-Hands-AI/OpenHands
- Aider — https://aider.chat
- Continue.dev — https://continue.dev
- Cline — https://github.com/cline/cline
- SWE-Agent — https://github.com/SWE-agent/SWE-agent
- Plandex — https://github.com/plandex-ai/plandex
- Roo Code — https://github.com/RooCodeInc/Roo-Code
论文(详见第 4 章)
- SWE-Agent (arXiv 2405.15793)
- OpenHands (arXiv 2407.16741)
- Auto-Code-Rover (arXiv 2404.05427)
- SWE-Search (arXiv 2410.20285)
- MAGIS (arXiv 2403.17927)
- CodeR (arXiv 2406.01304)
对比 / 评测
- “Aider vs Cursor — Why I switched”(社区博客系列)
- OpenHands SWE-bench leaderboard 提交
- Aider 自家 polyglot leaderboard
下一章:第4章 SWE-Agent + ACI 论文精读 —— 深度拆解 ACI 设计原则、工具选择哲学,以及 OpenHands / CodeR / SWE-Search / MAGIS 等后续工作的核心 idea。