Loading...
Loading...
Compare original and translation side by side
ALL runSubagent calls MUST be in a SINGLE function_calls block for true parallelism.
所有runSubagent调用必须放在单个function_calls块中才能实现真正的并行。
Message 1: Start Task A
↓ wait for completion
Message 2: Start Task B
↓ wait for completion
Message 3: Start Task C
↓ wait for completion
Total time = A + B + C = 90 seconds (if each takes 30s)消息1:启动任务A
↓ 等待完成
消息2:启动任务B
↓ 等待完成
消息3:启动任务C
↓ 等待完成
总耗时 = A + B + C = 90秒(假设每个任务耗时30秒)Message 1: Start Task A ─┐
Start Task B ─┼─ All run simultaneously
Start Task C ─┘
Total time ≈ max(A, B, C) = 30 seconds消息1:启动任务A ─┐
启动任务B ─┼─ 所有任务同时运行
启动任务C ─┘
总耗时 ≈ max(A, B, C) = 30秒<!-- CORRECT: All tasks in single function_calls block = PARALLEL -->
<function_calls>
<invoke name="runSubagent">
<parameter name="description">Analyze authentication module</parameter>
<parameter name="prompt">Review src/auth for security patterns...</parameter>
</invoke>
<invoke name="runSubagent">
<parameter name="description">Analyze API layer</parameter>
<parameter name="prompt">Review src/api for REST best practices...</parameter>
</invoke>
<invoke name="runSubagent">
<parameter name="description">Analyze database layer</parameter>
<parameter name="prompt">Review src/db for query optimization...</parameter>
</invoke>
</function_calls><!-- 正确做法:所有任务放在单个function_calls块中 = 并行执行 -->
<function_calls>
<invoke name="runSubagent">
<parameter name="description">分析认证模块</parameter>
<parameter name="prompt">审查src/auth中的安全模式...</parameter>
</invoke>
<invoke name="runSubagent">
<parameter name="description">分析API层</parameter>
<parameter name="prompt">审查src/api中的REST最佳实践...</parameter>
</invoke>
<invoke name="runSubagent">
<parameter name="description">分析数据库层</parameter>
<parameter name="prompt">审查src/db中的查询优化...</parameter>
</invoke>
</function_calls>Implementation Plan:
1. Implement auth module
2. Create API endpoints
3. Add database schema
4. Write unit tests
5. Update documentation
Launch 5 parallel subagents:
├─ Subagent 1: Implement auth module
├─ Subagent 2: Create API endpoints
├─ Subagent 3: Add database schema
├─ Subagent 4: Write unit tests
└─ Subagent 5: Update documentation实施计划:
1. 实现认证模块
2. 创建API端点
3. 添加数据库架构
4. 编写单元测试
5. 更新文档
启动5个并行子Agent:
├─ 子Agent 1:实现认证模块
├─ 子Agent 2:创建API端点
├─ 子Agent 3:添加数据库架构
├─ 子Agent 4:编写单元测试
└─ 子Agent 5:更新文档Codebase Structure:
├── src/auth/
├── src/api/
├── src/db/
└── src/ui/
Launch 4 parallel subagents:
├─ Subagent 1: Analyze src/auth
├─ Subagent 2: Analyze src/api
├─ Subagent 3: Analyze src/db
└─ Subagent 4: Analyze src/ui代码库结构:
├── src/auth/
├── src/api/
├── src/db/
└── src/ui/
启动4个并行子Agent:
├─ 子Agent 1:分析src/auth
├─ 子Agent 2:分析src/api
├─ 子Agent 3:分析src/db
└─ 子Agent 4:分析src/uiCode Review Perspectives:
- Security vulnerabilities
- Performance bottlenecks
- Test coverage gaps
- Architecture patterns
Launch 4 parallel subagents:
├─ Subagent 1: Security review
├─ Subagent 2: Performance analysis
├─ Subagent 3: Test coverage review
└─ Subagent 4: Architecture assessment代码审查视角:
- 安全漏洞
- 性能瓶颈
- 测试覆盖缺口
- 架构模式
启动4个并行子Agent:
├─ 子Agent 1:安全审查
├─ 子Agent 2:性能分析
├─ 子Agent 3:测试覆盖审查
└─ 子Agent 4:架构评估Verification Subagents (all parallel):
├─ Syntax & Type Checker
├─ Test Runner
├─ Lint & Style Checker
├─ Security Scanner
└─ Build Validator
Then (sequential, after above complete):
├─ False Positive Filter
├─ Missing Issues Finder
└─ Context Validator验证子Agent(全部并行):
├─ 语法与类型检查器
├─ 测试运行器
├─ 代码规范与样式检查器
├─ 安全扫描器
└─ 构建验证器
然后(顺序执行,需等上述任务完成):
├─ 误报过滤器
├─ 遗漏问题查找器
└─ 上下文验证器in_progressin_progress{
"todos": [
{ "content": "Analyze auth module", "status": "in_progress", "activeForm": "Analyzing auth module" },
{ "content": "Analyze API layer", "status": "in_progress", "activeForm": "Analyzing API layer" },
{ "content": "Analyze database layer", "status": "in_progress", "activeForm": "Analyzing database layer" },
{ "content": "Synthesize findings", "status": "pending", "activeForm": "Synthesizing findings" }
]
}{
"todos": [
{ "content": "分析认证模块", "status": "in_progress", "activeForm": "分析认证模块" },
{ "content": "分析API层", "status": "in_progress", "activeForm": "分析API层" },
{ "content": "分析数据库层", "status": "in_progress", "activeForm": "分析数据库层" },
{ "content": "综合发现结果", "status": "pending", "activeForm": "综合发现结果" }
]
}{
"todos": [
{ "content": "Analyze auth module", "status": "completed", "activeForm": "Analyzing auth module" },
{ "content": "Analyze API layer", "status": "completed", "activeForm": "Analyzing API layer" },
{ "content": "Analyze database layer", "status": "in_progress", "activeForm": "Analyzing database layer" },
{ "content": "Synthesize findings", "status": "pending", "activeForm": "Synthesizing findings" }
]
}{
"todos": [
{ "content": "分析认证模块", "status": "completed", "activeForm": "分析认证模块" },
{ "content": "分析API层", "status": "completed", "activeForm": "分析API层" },
{ "content": "分析数据库层", "status": "in_progress", "activeForm": "分析数据库层" },
{ "content": "综合发现结果", "status": "pending", "activeForm": "综合发现结果" }
]
}| Scenario | Parallel Approach |
|---|---|
| Multiple independent analyses | One subagent per analysis |
| Multi-file processing | One subagent per file/directory |
| Different review perspectives | One subagent per perspective |
| Multiple independent features | One subagent per feature |
| Exploratory research | Multiple search strategies |
| 场景 | 并行方法 |
|---|---|
| 多个独立分析任务 | 每个分析对应一个子Agent |
| 多文件处理 | 每个文件/目录对应一个子Agent |
| 不同审查视角 | 每个视角对应一个子Agent |
| 多个独立功能开发 | 每个功能对应一个子Agent |
| 探索性研究 | 多种搜索策略并行 |
| Scenario | Why Sequential |
|---|---|
| Tasks with dependencies | B needs A's output |
| Same file modifications | Risk of conflicts |
| Sequential workflows | Order matters (commit → push → PR) |
| Shared state | Race conditions |
| Limited resources | Overwhelming the system |
| 场景 | 为何选择顺序执行 |
|---|---|
| 存在依赖关系的任务 | B需要A的输出结果 |
| 修改同一文件 | 存在冲突风险 |
| 顺序工作流 | 执行顺序至关重要(提交 → 推送 → 拉取请求) |
| 共享状态 | 可能出现竞态条件 |
| 资源有限 | 可能导致系统过载 |
| # Parallel Tasks | Sequential Time | Parallel Time | Speedup |
|---|---|---|---|
| 2 | 60s | 30s | 2x |
| 3 | 90s | 30s | 3x |
| 5 | 150s | 30s | 5x |
| 10 | 300s | 30s | 10x |
| 并行任务数量 | 顺序执行时间 | 并行执行时间 | 提速倍数 |
|---|---|---|---|
| 2 | 60s | 30s | 2x |
| 3 | 90s | 30s | 3x |
| 5 | 150s | 30s | 5x |
| 10 | 300s | 30s | 10x |
WRONG (Sequential):
Message 1: "I'll start analyzing the auth module..."
<invoke name="runSubagent">Analyze auth</invoke>
Message 2: "Now let me analyze the API..."
<invoke name="runSubagent">Analyze API</invoke>
RIGHT (Parallel):
Message 1: "I'll analyze all modules in parallel..."
<function_calls>
<invoke name="runSubagent">Analyze auth</invoke>
<invoke name="runSubagent">Analyze API</invoke>
<invoke name="runSubagent">Analyze DB</invoke>
</function_calls>错误示例(顺序执行):
消息1:"我将开始分析认证模块..."
<invoke name="runSubagent">分析认证模块</invoke>
消息2:"现在让我分析API..."
<invoke name="runSubagent">分析API</invoke>
正确示例(并行执行):
消息1:"我将并行分析所有模块..."
<function_calls>
<invoke name="runSubagent">分析认证模块</invoke>
<invoke name="runSubagent">分析API</invoke>
<invoke name="runSubagent">分析数据库</invoke>
</function_calls>WRONG:
"I'm going to launch three parallel tasks to analyze the codebase."
[waits for response]
"Now launching the tasks..."
RIGHT:
"Launching three parallel analysis tasks now:"
<function_calls>
<invoke name="runSubagent">...</invoke>
<invoke name="runSubagent">...</invoke>
<invoke name="runSubagent">...</invoke>
</function_calls>错误示例:
"我将启动三个并行任务来分析代码库。"
[等待响应]
"现在启动任务..."
正确示例:
"现在启动三个并行分析任务:"
<function_calls>
<invoke name="runSubagent">...</invoke>
<invoke name="runSubagent">...</invoke>
<invoke name="runSubagent">...</invoke>
</function_calls>WRONG:
Just dump all task outputs without integration
RIGHT:
After receiving all results, synthesize:
- Identify common themes
- Resolve contradictions
- Prioritize findings
- Create unified recommendations错误示例:
直接输出所有任务的结果而不进行整合
正确示例:
收到所有结果后进行综合:
- 识别共同主题
- 解决矛盾点
- 优先处理关键发现
- 创建统一的建议报告in_progressin_progressundefinedundefined
---
---RULE #1:
ALL runSubagent calls in SINGLE function_calls block = PARALLEL
runSubagent calls in SEPARATE messages = SEQUENTIAL
PATTERNS:
Task-based: One subagent per task
Directory-based: One subagent per directory
Perspective-based: One subagent per viewpoint
Adversarial: Multiple competing reviewers
TODOLIST:
Mark ALL parallel tasks as in_progress BEFORE launching
Mark each as completed AFTER receiving results
SPEEDUP:
N parallel tasks ≈ Nx faster
(5 tasks @ 30s each: 150s → 30s)
CHECKLIST:
☐ Tasks independent?
☐ No shared files?
☐ No dependencies?
☐ All in ONE function_calls block?
☐ Synthesis planned?规则1:
所有runSubagent调用放在单个function_calls块中 = 并行执行
runSubagent调用放在不同消息中 = 顺序执行
模式:
基于任务: 每个任务对应一个子Agent
基于目录: 每个目录对应一个子Agent
基于视角: 每个视角对应一个子Agent
对抗性: 多个相互竞争的审查者
待办事项列表:
启动前将所有并行任务标记为in_progress
收到结果后将每个任务标记为已完成
提速效果:
N个并行任务 ≈ N倍提速
(5个任务各耗时30秒:150秒 → 30秒)
检查清单:
☐ 任务是否独立?
☐ 是否没有共享文件?
☐ 是否没有依赖关系?
☐ 是否都在单个function_calls块中?
☐ 是否已规划结果综合步骤?