主题
Claude Code Agent Teams 深度调研
官方文档:https://code.claude.com/docs/en/agent-teams 版本要求:Claude Code v2.1.32+ 状态:实验性功能,默认禁用
一、概念总览
Agent Teams 是 Claude Code 的一种多会话协调机制,允许多个 Claude Code 实例作为一个"团队"协同工作。核心架构如下:
| 组件 | 职责 |
|---|---|
| Team Lead(领队) | 主 Claude Code 会话,负责创建团队、分配任务、综合结果 |
| Teammates(队友) | 独立的 Claude Code 实例,各自拥有独立上下文窗口 |
| Task List(任务列表) | 共享的工作项列表,队友可以认领和完成 |
| Mailbox(邮箱) | Agent 之间的消息通信系统 |
与 Subagent 的核心区别
| 维度 | Subagent | Agent Team |
|---|---|---|
| 上下文 | 自有上下文,结果返回给调用者 | 自有上下文,完全独立 |
| 通信 | 只能向主 agent 汇报结果 | 队友之间可以直接消息通信 |
| 协调方式 | 主 agent 管理所有工作 | 共享任务列表,自协调 |
| 适用场景 | 结果导向的聚焦任务 | 需要讨论和协作的复杂工作 |
| Token 消耗 | 较低(结果摘要返回主上下文) | 较高(每个队友是独立的 Claude 实例) |
总结:Subagent 适合"快速干活汇报结果",Agent Team 适合"共享发现、互相挑战、自主协调"。
二、启用 Agent Teams
方式一:环境变量
bash
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1方式二:settings.json
json
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}三、快速启动第一个 Agent Team
启用后,用自然语言告诉 Claude 创建一个 Agent Team:
text
I'm designing a CLI tool that helps developers track TODO comments across
their codebase. Create an agent team to explore this from different angles: one
teammate on UX, one on technical architecture, one playing devil's advocate.Claude 会自动:
- 创建一个带共享任务列表的团队
- 为每个角色 spawn 一个队友
- 让他们各自探索问题
- 综合发现
- 完成后清理团队
指定队友数量和模型
text
Create a team with 4 teammates to refactor these modules in parallel.
Use Sonnet for each teammate.四、Team Agent 的定义方式
4.1 利用 Subagent 定义作为 Teammate 角色
这是定义可复用 Team Agent 角色的核心方式。你可以定义一个 subagent,然后在创建 team 时引用它的名字:
text
Spawn a teammate using the security-reviewer agent type to audit the auth module.队友会继承该 subagent 定义的:
tools允许列表model模型设定- Markdown body 作为系统提示(追加到队友的系统提示中,而非替换)
注意:subagent 定义中的 skills 和 mcpServers 字段在作为 teammate 时不生效。队友从项目和用户设置中加载 skills 和 MCP 服务器。
团队协调工具(如 SendMessage 和任务管理工具)始终对队友可用,即使 tools 限制了其他工具。
4.2 Subagent 的定义文件格式
Subagent 使用 Markdown 文件 + YAML frontmatter 定义:
markdown
---
name: security-reviewer
description: Reviews code for security vulnerabilities. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a security expert. When invoked, analyze the code for:
1. SQL injection vulnerabilities
2. XSS attack vectors
3. Authentication/authorization flaws
4. Sensitive data exposure
5. Input validation gaps
Provide findings organized by severity: Critical > High > Medium > Low.
Include specific remediation steps for each finding.4.3 Subagent 存放位置和优先级
| 位置 | 作用域 | 优先级 | 创建方式 |
|---|---|---|---|
| Managed settings | 组织级 | 1(最高) | 通过管理员部署 |
--agents CLI flag | 当前会话 | 2 | 启动时 JSON 传入 |
.claude/agents/ | 当前项目 | 3 | 交互式或手动 |
~/.claude/agents/ | 所有项目 | 4 | 交互式或手动 |
Plugin 的 agents/ 目录 | Plugin 启用的地方 | 5(最低) | 随 Plugin 安装 |
4.4 支持的 Frontmatter 字段(完整列表)
| 字段 | 必需 | 说明 |
|---|---|---|
name | 是 | 唯一标识符,小写字母和连字符 |
description | 是 | Claude 何时委托给此 subagent |
tools | 否 | 可用工具允许列表,省略则继承所有工具 |
disallowedTools | 否 | 工具拒绝列表 |
model | 否 | 使用的模型:sonnet/opus/haiku/完整 ID/inherit |
permissionMode | 否 | 权限模式:default/acceptEdits/auto/dontAsk/bypassPermissions/plan |
maxTurns | 否 | 最大 agentic 轮次 |
skills | 否 | 加载到 subagent 的 Skills(注意:作为 teammate 时不生效) |
mcpServers | 否 | MCP 服务器配置(注意:作为 teammate 时不生效) |
hooks | 否 | 生命周期钩子 |
memory | 否 | 持久记忆范围:user/project/local |
background | 否 | 是否后台运行,默认 false |
effort | 否 | 努力级别:low/medium/high/xhigh/max |
isolation | 否 | 设为 worktree 在独立 git worktree 中运行 |
color | 否 | 显示颜色 |
initialPrompt | 否 | 作为 --agent 运行时的初始提示 |
4.5 通过 CLI 动态定义 Subagent
无需文件,通过 --agents flag 动态定义:
bash
claude --agents '{
"code-reviewer": {
"description": "Expert code reviewer. Use proactively after code changes.",
"prompt": "You are a senior code reviewer. Focus on code quality, security, and best practices.",
"tools": ["Read", "Grep", "Glob", "Bash"],
"model": "sonnet"
},
"debugger": {
"description": "Debugging specialist for errors and test failures.",
"prompt": "You are an expert debugger. Analyze errors, identify root causes, and provide fixes."
}
}'4.6 通过 /agents 命令创建
在 Claude Code 中运行 /agents,进入图形化管理界面:
- 切换到 Library tab → Create new agent
- 选择范围(Personal =
~/.claude/agents/,Project =.claude/agents/) - 可选 Generate with Claude 让 AI 生成配置
- 选择工具、模型、颜色、记忆范围
- 保存即生效
五、控制 Agent Team
5.1 显示模式
| 模式 | 说明 | 适用场景 |
|---|---|---|
| In-process(默认) | 所有队友在主终端运行,Shift+Down 切换 | 任何终端 |
| Split panes | 每个队友一个独立面板 | 需要 tmux 或 iTerm2 |
配置 ~/.claude.json:
json
{
"teammateMode": "in-process"
}或启动时指定:
bash
claude --teammate-mode in-process5.2 要求计划审批
对高风险任务,可以要求队友先制定计划再执行:
text
Spawn an architect teammate to refactor the authentication module.
Require plan approval before they make any changes.工作流程:
- 队友在只读 plan 模式下工作
- 完成计划后发送审批请求给领队
- 领队审批 → 队友开始实施
- 领队拒绝 → 队友修改计划重新提交
可以影响领队的审批标准:
text
Only approve plans that include test coverage.
Reject plans that modify the database schema.5.3 直接与队友对话
- In-process 模式:
Shift+Down切换队友,直接输入消息;Enter查看队友会话,Escape中断其当前轮次,Ctrl+T切换任务列表 - Split-pane 模式:点击队友面板直接交互
5.4 任务分配与认领
共享任务列表有三种状态:pending → in progress → completed
支持任务依赖:未完成依赖的任务无法被认领。
两种分配方式:
- 领队分配:告诉领队把哪个任务给哪个队友
- 自动认领:队友完成任务后自动拿下一个未分配、未阻塞的任务
任务认领使用文件锁防止竞争条件。
5.5 队友关闭
text
Ask the researcher teammate to shut down5.6 团队清理
text
Clean up the team必须由领队执行清理,先关闭所有队友。
六、质量门禁:Hooks
Agent Teams 支持三个专用的 Hook 事件:
| Hook 事件 | 触发时机 | 用途 |
|---|---|---|
TeammateIdle | 队友即将空闲 | exit code 2 → 发送反馈让队友继续工作 |
TaskCreated | 创建任务时 | exit code 2 → 阻止创建并返回反馈 |
TaskCompleted | 标记任务完成时 | exit code 2 → 阻止完成并返回反馈 |
示例:TaskCompleted Hook(运行测试门禁)
json
{
"hooks": {
"TaskCompleted": [
{
"hooks": [
{ "type": "command", "command": "./scripts/run-tests-on-completion.sh" }
]
}
]
}
}脚本以 exit code 2 退出时,阻止任务完成并把 stderr 内容作为反馈发给队友。
七、存储与架构细节
本地存储
- 团队配置:
~/.claude/teams/{team-name}/config.json - 任务列表:
~/.claude/tasks/{team-name}/
不要手动编辑 config.json——它保存运行时状态(session ID、tmux pane ID),每次状态更新都会被覆盖。
config.json 结构
包含 members 数组,每个队友的信息:
name:队友名称agentId:Agent IDagentType:Agent 类型
队友可以读取此文件来发现其他团队成员。
权限继承
- 队友继承领队的权限设置
- 领队用
--dangerously-skip-permissions→ 所有队友也是 - spawn 后可以单独修改队友权限模式,但不能在 spawn 时指定
上下文与通信
- 每个队友有独立上下文窗口
- spawn 时加载项目上下文(CLAUDE.md、MCP 服务器、Skills)+ spawn prompt
- 领队的对话历史不会传递给队友
- 消息自动投递,领队不需要轮询
- 空闲通知自动发送给领队
- 消息类型:
message(定向单人)/broadcast(广播全员)
八、最佳实践
8.1 给队友足够的上下文
text
Spawn a security reviewer teammate with the prompt: "Review the authentication module
at src/auth/ for security vulnerabilities. Focus on token handling, session
management, and input validation. The app uses JWT tokens stored in
httpOnly cookies. Report any issues with severity ratings."8.2 合适的团队规模
- 推荐 3-5 个队友
- 每个队友 5-6 个任务 保持高效
- Token 成本线性增长
- 3 个专注的队友 > 5 个分散的队友
8.3 合适的任务粒度
- 太小:协调开销超过收益
- 太大:队友长时间无 check-in,增加浪费风险
- 刚好:自包含单元,产出明确交付物(一个函数、一个测试文件、一份 review)
8.4 避免文件冲突
两个队友编辑同一文件会导致覆盖。让每个队友拥有不同的文件集。
8.5 等待队友完成
如果领队自己开始实现任务:
text
Wait for your teammates to complete their tasks before proceeding8.6 优化 CLAUDE.md
- 描述模块边界,帮助 Claude 自动分配工作
- 提供验证命令
- 提供运行上下文信息
九、经典使用场景
场景一:并行代码审查
text
Create an agent team to review PR #142. Spawn three reviewers:
- One focused on security implications
- One checking performance impact
- One validating test coverage
Have them each review and report findings.场景二:竞争假设调查(Debugging)
text
Users report the app exits after one message instead of staying connected.
Spawn 5 agent teammates to investigate different hypotheses. Have them talk to
each other to try to disprove each other's theories, like a scientific
debate. Update the findings doc with whatever consensus emerges.场景三:重构认证模块(端到端工作流)
text
Create an agent team to refactor the payment module. Spawn three teammates:
- One for API layer changes
- One for database migration
- One for test coverage
Require plan approval before implementation.十、通过 Agent SDK 编程使用
Claude Agent SDK(原 Claude Code SDK)支持编程方式定义和使用 subagent/team:
Python 示例
python
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition
async def main():
async for message in query(
prompt="Use the code-reviewer agent to review this codebase",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Glob", "Grep", "Agent"],
agents={
"code-reviewer": AgentDefinition(
description="Expert code reviewer for quality and security reviews.",
prompt="You are a senior code reviewer...",
tools=["Read", "Grep", "Glob"],
model="sonnet"
)
}
),
):
if hasattr(message, 'result'):
print(message.result)
asyncio.run(main())TypeScript 示例
typescript
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Use the code-reviewer agent to review this codebase",
options: {
allowedTools: ["Read", "Glob", "Grep", "Agent"],
agents: {
"code-reviewer": {
description: "Expert code reviewer for quality and security reviews.",
prompt: "You are a senior code reviewer...",
tools: ["Read", "Grep", "Glob"],
model: "sonnet"
}
}
}
})) {
if ("result" in message) console.log(message.result);
}关键点:allowedTools 中必须包含 "Agent" 才能调用 subagent。
十一、实用 Agent 定义模板
代码审查员
markdown
---
name: code-reviewer
description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability.
tools: Read, Grep, Glob, Bash
model: inherit
---
You are a senior code reviewer ensuring high standards of code quality and security.
When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately
Review checklist:
- Code is clear and readable
- Functions and variables are well-named
- No duplicated code
- Proper error handling
- No exposed secrets or API keys
- Input validation implemented
- Good test coverage
- Performance considerations addressed
Provide feedback organized by priority:
- Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)
Include specific examples of how to fix issues.调试专家
markdown
---
name: debugger
description: Debugging specialist for errors, test failures, and unexpected behavior. Use proactively when encountering any issues.
tools: Read, Edit, Bash, Grep, Glob
---
You are an expert debugger specializing in root cause analysis.
When invoked:
1. Capture error message and stack trace
2. Identify reproduction steps
3. Isolate the failure location
4. Implement minimal fix
5. Verify solution works
For each issue, provide:
- Root cause explanation
- Evidence supporting the diagnosis
- Specific code fix
- Testing approach
- Prevention recommendations
Focus on fixing the underlying issue, not the symptoms.只读数据库查询
markdown
---
name: db-reader
description: Execute read-only database queries. Use when analyzing data or generating reports.
tools: Bash
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-readonly-query.sh"
---
You are a database analyst with read-only access. Execute SELECT queries to answer questions about the data.
You cannot modify data. If asked to INSERT, UPDATE, DELETE, or modify schema,
explain that you only have read access.十二、--agent 模式:将整个会话变为 Agent
bash
claude --agent code-reviewer此模式下:
- subagent 的系统提示完全替换默认 Claude Code 系统提示
CLAUDE.md和项目记忆正常加载- Agent 名称显示为
@code-reviewer - resume 会话时保持 agent 选择
设为项目默认(.claude/settings.json):
json
{
"agent": "code-reviewer"
}十三、限制与注意事项
| 限制 | 说明 |
|---|---|
| 不支持会话恢复 | /resume 和 /rewind 不会恢复 in-process 队友 |
| 任务状态滞后 | 队友有时忘记标记完成,会阻塞依赖任务 |
| 关闭较慢 | 队友需完成当前请求/工具调用后才关闭 |
| 每会话一个团队 | 领队同时只能管理一个团队 |
| 不支持嵌套团队 | 队友不能 spawn 自己的团队 |
| 领队固定 | 不能提升队友为领队或转移领导权 |
| 权限在 spawn 时设定 | 所有队友继承领队权限,spawn 后可单独修改 |
| Split pane 需要 tmux/iTerm2 | VS Code 终端、Windows Terminal、Ghostty 不支持 |
十四、决策指南:何时用什么
单步简单任务 → 主会话直接处理
聚焦、结果导向的侧任务 → Subagent
需要并行 + 互相通信的复杂工作 → Agent Team
手动控制多个会话 → Git Worktrees十五、实战案例:Leader + Codegen(Go/Python) + Check 的多 Agent 架构
场景描述
搭建一个代码生成流水线:
- Leader Agent:路由层,判断用户需求后分发给对应的 codegen agent
- Codegen-Go Agent:专门生成 Go 项目代码
- Codegen-Python Agent:专门生成 Python 项目代码
- Check Agent:编译检查,验证生成的代码是否能正确编译运行
方案 A:Subagent 模式(推荐 —— 顺序执行、低 Token)
适用场景:一次只生成一种语言的代码,不需要 Go/Python 互相通信
文件结构
your-project/
├── .claude/
│ ├── agents/
│ │ ├── codegen-go.md # Go 代码生成 agent
│ │ ├── codegen-python.md # Python 代码生成 agent
│ │ └── check.md # 编译检查 agent
│ └── settings.json # 项目配置
├── CLAUDE.md # 领队/路由指令(主会话提示)
└── scripts/
└── build-check.sh # 编译检查脚本Step 1: 定义 Leader(CLAUDE.md)
Leader 不是 subagent,而是主会话本身。用 CLAUDE.md 来定义它的路由行为:
markdown
# 项目说明
本项目是一个代码生成流水线。你作为 Leader Agent,职责如下:
## 路由规则
收到用户代码生成请求后:
1. **判断编程语言**
- 用户要求生成 Go 代码 → 委派给 `codegen-go` subagent
- 用户要求生成 Python 代码 → 委派给 `codegen-python` subagent
- 用户未指定语言 → 询问用户选择 Go 或 Python
- 用户指定不支持的语言 → 告知仅支持 Go 和 Python
2. **代码生成完成后**,立即委派给 `check` subagent 进行编译检查
3. **检查完成后**,向用户汇报最终结果
## 约束
- 所有代码生成任务禁止自己完成,必须委派给对应 subagent
- 使用中文回复
- 不暴露内部路由决策过程,只输出最终结果Step 2: 定义 codegen-go.md
markdown
---
name: codegen-go
description: Go 代码生成专家。当用户需要生成 Go 项目或 Go 代码时使用。
tools: Read, Write, Edit, Bash, Grep, Glob
model: sonnet
color: blue
---
你是一个 Go 代码生成专家,负责根据用户需求生成完整的 Go 项目。
## 核心职责
- 理解用户的 Go 编程需求
- 生成符合 Go 规范的项目代码
- 创建完整的项目结构(go.mod、main.go、目录结构等)
## 工作流程
### 阶段 1:规划
分析需求,制定项目结构和实现方案。
### 阶段 2:代码生成
生成所有必要的文件,包括:
- go.mod(依赖管理)
- main.go(入口文件)
- 业务逻辑代码
- 配置文件
- Makefile 或 build 脚本
### 阶段 3:总结
输出项目说明和使用方法。
## Go 代码规范
- 遵循 Go 官方代码风格(gofmt)
- 正确处理 error,不忽略返回的 error
- 使用有意义的包名和变量名
- 合理使用 interface 进行抽象Step 3: 定义 codegen-python.md
markdown
---
name: codegen-python
description: Python 代码生成专家。当用户需要生成 Python 项目或 Python 代码时使用。
tools: Read, Write, Edit, Bash, Grep, Glob
model: sonnet
color: green
---
你是一个 Python 代码生成专家,负责根据用户需求生成完整的 Python 项目。
## 核心职责
- 理解用户的 Python 编程需求
- 生成符合 Python 规范的项目代码
- 创建完整的项目结构(pyproject.toml、目录结构等)
## 工作流程
### 阶段 1:规划
分析需求,制定项目结构和实现方案。
### 阶段 2:代码生成
生成所有必要的文件,包括:
- pyproject.toml 或 requirements.txt(依赖管理)
- 主入口文件
- 业务逻辑代码
- __init__.py 文件
- 配置文件
### 阶段 3:总结
输出项目说明和使用方法。
## Python 代码规范
- 遵循 PEP 8 风格指南
- 使用 type hints
- 编写 docstring
- 合理组织包结构Step 4: 定义 check.md
markdown
---
name: check
description: 编译检查专家。代码生成完成后使用,负责编译检查和验证。
tools: Read, Bash, Grep, Glob, Edit
model: sonnet
color: orange
---
你是一个编译检查专家,负责在代码生成完成后进行全面的编译检查。
## 检查流程
### 步骤 1:识别项目类型
读取项目目录,判断是 Go 项目还是 Python 项目:
- 存在 go.mod → Go 项目
- 存在 pyproject.toml / requirements.txt / setup.py → Python 项目
### 步骤 2:执行编译检查(最多 3 轮)
**Go 项目**:
1. 运行 `go build ./...` 检查编译
2. 运行 `go vet ./...` 检查常见问题
3. 如果编译失败,分析错误并修复代码
**Python 项目**:
1. 运行 `python -m py_compile <入口文件>` 检查语法
2. 运行 `python -m compileall . -q` 检查所有文件
3. 如果有语法错误,分析并修复
### 步骤 3:汇报结果
- 检查通过:简要汇报通过信息
- 检查失败(3 轮后仍有问题):列出未解决的问题Step 5: 项目配置 .claude/settings.json
json
{
"permissions": {
"allow": [
"Bash(go build*)",
"Bash(go vet*)",
"Bash(python*)",
"Bash(pip*)",
"Bash(ls*)",
"Bash(cat*)",
"Bash(find*)"
]
}
}使用方式
bash
# 直接启动,主会话就是 Leader
claude
# 然后输入:
> 帮我生成一个 Go 的 HTTP 服务,包含用户注册和登录接口
# Leader 自动路由 → codegen-go → check → 汇报结果
> 帮我生成一个 Python FastAPI 服务,提供 RESTful API
# Leader 自动路由 → codegen-python → check → 汇报结果执行流程图
用户请求
│
▼
┌──────────┐
│ Leader │ ← 主会话 (CLAUDE.md 定义路由规则)
│ (路由) │
└────┬─────┘
│ 判断语言
├─── Go ──────► codegen-go subagent ──┐
│ │
└─── Python ──► codegen-python subagent┤
│
▼
┌──────────────┐
│ check subagent│
│ (编译检查) │
└──────┬───────┘
│
▼
汇报结果给用户方案 B:Agent Teams 模式(Go/Python 并行 + Check 依赖等待)
适用场景:同时生成 Go 和 Python 两个版本,需要 check 等两者都完成后再执行
Step 1: 启用 Agent Teams
bash
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1Step 2: Agent 定义文件
和方案 A 相同的 .claude/agents/ 下的三个文件。
Step 3: CLAUDE.md(Leader 指令 + 团队编排)
markdown
# 代码生成团队
你是代码生成团队的 Leader。
## 团队编排规则
当用户需要同时生成多种语言版本时:
1. 创建一个 agent team
2. 使用 codegen-go agent type 创建一个队友,命名为 "go-dev"
3. 使用 codegen-python agent type 创建一个队友,命名为 "python-dev"
4. 创建任务列表,设置依赖关系:
- task-go: Go 代码生成(分配给 go-dev)
- task-python: Python 代码生成(分配给 python-dev)
- task-check-go: Go 编译检查(依赖 task-go 完成)
- task-check-python: Python 编译检查(依赖 task-python 完成)
5. 等待所有队友完成后,综合汇报结果
当用户只需要单一语言时:
- 退化为 subagent 模式,直接委派,不创建团队Step 4: 使用方式
bash
claude
# 同时生成两种语言版本(触发 Agent Teams)
> 帮我同时生成 Go 和 Python 两个版本的 HTTP 服务,包含用户注册和登录接口
# 单语言生成(退化为 Subagent)
> 帮我生成一个 Go 的 HTTP 服务执行流程图
用户请求(同时 Go + Python)
│
▼
┌────────────────────────────────────────┐
│ Leader (Team Lead) │
│ 创建 Agent Team,分配任务 │
└───────────┬────────────────────────────┘
│
┌───────┴────────┐
│ │
▼ ▼
┌─────────┐ ┌───────────┐
│ go-dev │ │python-dev │ ← 并行执行
│(codegen │ │(codegen │
│ -go) │ │ -python) │
└────┬────┘ └─────┬─────┘
│ │
│ 完成通知 │ 完成通知
│ │
▼ ▼
┌─────────┐ ┌───────────┐
│check-go │ │check-py │ ← 各自的 check(依赖前置任务)
│(check) │ │(check) │
└────┬────┘ └─────┬─────┘
│ │
└──────┬───────┘
│
▼
Leader 综合汇报使用 TaskCompleted Hook 自动触发检查
json
{
"hooks": {
"TaskCompleted": [
{
"matcher": "codegen",
"hooks": [
{
"type": "command",
"command": "./scripts/build-check.sh"
}
]
}
]
}
}方案选择建议
| 考量维度 | 方案 A (Subagent) | 方案 B (Agent Teams) |
|---|---|---|
| 实现复杂度 | 低,定义文件 + CLAUDE.md 即可 | 中,还需启用实验功能 |
| Token 消耗 | 低(subagent 结果摘要返回) | 高(每个队友独立上下文) |
| 并行能力 | 有限(subagent 也可以后台并行) | 原生并行 + 消息通信 |
| 稳定性 | 稳定(正式功能) | 实验性,有已知限制 |
| 任务依赖 | 由 Leader 在 prompt 中控制顺序 | 原生支持 task dependency |
| 适用场景 | 一次一种语言,顺序流水线 | 同时多种语言,并行 + 编排 |
对于你的场景(路由 → codegen → check),推荐方案 A。理由:
- 你的流程是线性的:路由 → 生成 → 检查,不需要 Go/Python 之间通信
- Subagent 模式更成熟稳定
- Token 消耗更低
- 实现更简单
只有在"同时生成多种语言版本 + 需要互相协调"时,才升级到方案 B。