rlm-subagent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSubagent-Driven Execution with Fallback
基于Subagent的执行机制及回退方案
This skill provides parallel subagent execution for RLM Phase 3 (Implementation), Phase 3.5 (Code Review), and Phase 4 (Testing) with automatic fallback to sequential mode when subagents are unavailable.
该技能为RLM第三阶段(开发实现)、3.5阶段(代码审查)和第四阶段(测试验证)提供Subagent并行执行能力,当Subagent不可用时会自动回退至顺序执行模式。
Quick Reference
快速参考
| Scenario | Action |
|---|---|
| Multiple independent sub-phases | Use Parallel Mode (subagents) |
| Single sub-phase or subagents unavailable | Use Sequential Mode (fallback) |
| Code review needed | Use Phase 3.5 (subagent or self-review) |
| Parallel testing | Use Phase 4 parallel dispatch |
| 场景 | 操作 |
|---|---|
| 存在多个独立子阶段 | 使用并行模式(Subagent) |
| 单个子阶段或Subagent不可用 | 使用顺序模式(回退方案) |
| 需要代码审查 | 使用3.5阶段(Subagent审查或自审查) |
| 并行测试 | 使用第四阶段并行调度 |
TODO Discipline for Subagents
Subagent的TODO规范
The Iron Law: NO SUBAGENT COMPLETION REPORT WITHOUT ALL TODOS CHECKED.
铁律:未完成所有TODO项,不得提交Subagent完成报告。
Subagent TODO Requirements
Subagent的TODO要求
Each subagent (implementer, code-reviewer) MUST:
- Include section in their work output
## TODO - Check off items as work progresses
- Verify ALL items checked before reporting completion
每个Subagent(开发实现者、代码审查者)必须:
- 在工作输出中包含章节
## TODO - 随着工作推进勾选已完成项
- 在报告完成前确认所有项已勾选
Implementer Subagent TODO Template
开发实现Subagent的TODO模板
markdown
undefinedmarkdown
undefinedTODO
TODO
- Read and understand assigned SP specification
- Ask clarifying questions (if any)
- Write failing test (RED phase)
- Run test and verify failure
- Implement minimal code (GREEN phase)
- Run test and verify pass
- Refactor while keeping tests green
- Run integration tests
- Self-review against plan
- Document changes made
- Report completion to controller
undefined- 阅读并理解分配的SP规格说明
- 提出澄清问题(如有)
- 编写失败测试用例(RED阶段)
- 运行测试并验证失败结果
- 编写最简实现代码(GREEN阶段)
- 运行测试并验证通过结果
- 在保持测试通过的前提下重构代码
- 运行集成测试
- 对照计划进行自审查
- 记录所做的变更
- 向控制代理报告完成情况
undefinedCode Reviewer Subagent TODO Template
代码审查Subagent的TODO模板
markdown
undefinedmarkdown
undefinedTODO
TODO
- Read original plan (Phase 3)
- Read implementation summary (Phase 3)
- Review git diff (BASE_SHA..HEAD_SHA)
- Verify plan alignment
- Assess code quality
- Check TDD compliance
- Categorize issues (Critical/Important/Minor)
- Document positive findings
- Render verdict
- Report review completion
undefined- 阅读原始计划(第三阶段)
- 阅读开发实现总结(第三阶段)
- 审查git diff(BASE_SHA..HEAD_SHA)
- 验证与计划的一致性
- 评估代码质量
- 检查TDD合规性
- 对问题进行分类(严重/重要/次要)
- 记录正面发现
- 给出审查结论
- 报告审查完成情况
undefinedController TODO Management
控制代理的TODO管理
The controller MUST:
- Verify subagent outputs include completed TODOs
- NOT accept completion reports with unchecked items
- Request subagent to complete remaining items
控制代理必须:
- 验证Subagent的输出中包含已完成的TODO项
- 不接受存在未勾选项的完成报告
- 要求Subagent完成剩余项
Capability Detection
能力检测
At start of Phase 3, detect subagent availability:
IF can invoke "agent" or "Task" tool → Use Parallel Mode
ELSE → Use Sequential Fallback ModeDetection rule: If the platform provides a subagent/task primitive, use parallel mode; otherwise fallback to sequential.
在第三阶段开始时,检测Subagent的可用性:
IF 可调用"agent"或"Task"工具 → 使用并行模式
ELSE → 使用顺序回退模式检测规则: 如果平台提供子代理/任务原语,则使用并行模式;否则回退至顺序模式。
Parallel Mode (Subagents Available)
并行模式(Subagent可用)
Phase 3: Parallel Sub-Phase Implementation
第三阶段:并行子阶段开发实现
Controller responsibilities:
- Read locked Phase 3 plan once
- Extract all sub-phases (SP1, SP2, SP3...)
- Determine dependencies (independent vs sequential)
- Dispatch implementer subagent per independent SP
- Two-stage review after each SP completion
- Integration testing after all approved
Dispatch pattern:
typescript
// Parallel dispatch for independent SPs
await Promise.all([
Task({ description: "Implement SP1", prompt: implementerPrompt(SP1) }),
Task({ description: "Implement SP2", prompt: implementerPrompt(SP2) }),
Task({ description: "Implement SP3", prompt: implementerPrompt(SP3) })
])Two-stage review:
- Spec Review: Verify SP requirements met (plan alignment)
- Code Quality Review: Assess code quality, TDD compliance, standards
控制代理职责:
- 一次性读取锁定的第三阶段计划
- 提取所有子阶段(SP1、SP2、SP3……)
- 确定依赖关系(独立或顺序)
- 为每个独立SP调度开发实现Subagent
- 每个SP完成后进行两阶段审查
- 所有SP通过审查后执行集成测试
调度模式:
typescript
// 为独立SP调度并行任务
await Promise.all([
Task({ description: "Implement SP1", prompt: implementerPrompt(SP1) }),
Task({ description: "Implement SP2", prompt: implementerPrompt(SP2) }),
Task({ description: "Implement SP3", prompt: implementerPrompt(SP3) })
])两阶段审查:
- 规格审查: 验证是否满足SP需求(与计划的一致性)
- 代码质量审查: 评估代码质量、TDD合规性及编码标准
Phase 3.5: Code Review Subagent
3.5阶段:代码审查Subagent
Trigger: After Phase 3 implementation
Action: Dispatch subagent with:
agents/code-reviewer.md- BASE_SHA and HEAD_SHA of changes
- Phase 3 plan for alignment check
- Severity classification (Critical/Important/Minor)
Review loop: Issues found → implementer fixes → re-review
触发条件: 第三阶段开发完成后
操作: 调度子代理,并提供:
agents/code-reviewer.md- 变更的BASE_SHA和HEAD_SHA
- 第三阶段计划(用于一致性检查)
- 问题严重程度分类(严重/重要/次要)
审查循环: 发现问题 → 开发实现者修复 → 重新审查
Phase 4: Parallel Testing
第四阶段:并行测试
Dispatch pattern:
typescript
// Parallel test execution
await Promise.all([
Task({ description: "Run unit tests", prompt: testPrompt("unit") }),
Task({ description: "Run integration tests", prompt: testPrompt("integration") }),
Task({ description: "Run E2E tests", prompt: testPrompt("e2e") })
])Result aggregation:
- Collect results from all subagents
- Summarize pass/fail counts
- Identify any critical failures
调度模式:
typescript
// 并行执行测试任务
await Promise.all([
Task({ description: "Run unit tests", prompt: testPrompt("unit") }),
Task({ description: "Run integration tests", prompt: testPrompt("integration") }),
Task({ description: "Run E2E tests", prompt: testPrompt("e2e") })
])结果汇总:
- 收集所有Subagent的测试结果
- 汇总通过/失败数量
- 识别严重失败项
Sequential Fallback Mode (No Subagents)
顺序回退模式(无Subagent可用)
Trigger: Subagent capability check fails
Characteristics:
- Execute sub-phases sequentially in main agent context
- Extended self-review checklist per sub-phase
- Integration testing between each sub-phase
- Full context preservation
Fallback trigger flow:
markdown
**Subagent Check:** ❌ NOT AVAILABLE
**Reason:** [Tool not found / Platform limitation / User request]
**Action:** Using SEQUENTIAL fallback mode触发条件: Subagent能力检测不通过
特性:
- 在主代理上下文中顺序执行子阶段
- 每个子阶段使用扩展自审查清单
- 子阶段之间执行集成测试
- 完整保留上下文信息
回退触发流程:
markdown
**Subagent检查:** ❌ 不可用
**原因:** [工具未找到 / 平台限制 / 用户要求]
**操作:** 使用顺序回退模式Sequential Execution Pattern
顺序执行模式
For each SP in [SP1, SP2, SP3...]:
1. Execute SP implementation
2. Self-review against plan (extended checklist)
3. Document in Phase 4 artifact
4. Run integration tests
5. Proceed to next SPFor each SP in [SP1, SP2, SP3...]:
1. 执行SP开发实现
2. 对照计划进行扩展自审查
3. 在第四阶段工件中记录
4. 运行集成测试
5. 进入下一个SPSequential Review Pattern
顺序审查模式
Phase 3.5 equivalent:
- Main agent performs extended self-review
- Use comprehensive checklist from
agents/code-reviewer.md - Document findings in Phase 3.5 artifact
等效3.5阶段操作:
- 主代理执行扩展自审查
- 使用中的全面审查清单
agents/code-reviewer.md - 在3.5阶段工件中记录审查结果
Subagent Prompts
Subagent提示词
Implementer Subagent
开发实现Subagent
File:
agents/implementer.mdKey requirements:
- Self-contained context (full SP text provided)
- TDD discipline enforcement
- Question-before-work protocol
- Self-review checklist before completion
Usage:
markdown
You are an Implementer Agent. Implement this sub-phase:
**SP Text:** [full sub-phase text]
**BASE_SHA:** [commit SHA]
**Context:** [relevant files]
Follow the process in agents/implementer.md文件:
agents/implementer.md核心要求:
- 上下文自包含(提供完整SP文本)
- 强制执行TDD规范
- 先提问再工作的流程
- 完成前执行自审查清单
使用方式:
markdown
You are an Implementer Agent. Implement this sub-phase:
**SP Text:** [full sub-phase text]
**BASE_SHA:** [commit SHA]
**Context:** [relevant files]
Follow the process in agents/implementer.mdCode Reviewer Subagent
代码审查Subagent
File:
agents/code-reviewer.mdKey requirements:
- Plan alignment verification
- Code quality assessment
- Severity classification (Critical/Important/Minor)
- Clear verdict (Approved / Changes Required)
Usage:
markdown
You are a Code Reviewer Agent. Review this implementation:
**Plan:** [Phase 3 TO-BE]
**Git Range:** [BASE_SHA..HEAD_SHA]
**Implementation:** [Phase 4 summary]
Follow the process in agents/code-reviewer.md文件:
agents/code-reviewer.md核心要求:
- 验证与计划的一致性
- 评估代码质量
- 问题严重程度分类(严重/重要/次要)
- 明确给出审查结论(通过/需要修改)
使用方式:
markdown
You are a Code Reviewer Agent. Review this implementation:
**Plan:** [Phase 3 TO-BE]
**Git Range:** [BASE_SHA..HEAD_SHA]
**Implementation:** [Phase 4 summary]
Follow the process in agents/code-reviewer.mdArtifact Documentation
工件文档规范
Phase 4 artifact must include:
markdown
undefined第四阶段工件必须包含:
markdown
undefinedExecution Mode
Execution Mode
- Mode: Parallel / Sequential
- Subagents Used: [names and counts]
- Fallback Reason: [if applicable]
- Mode: Parallel / Sequential
- Subagents Used: [names and counts]
- Fallback Reason: [if applicable]
Sub-phase Results
Sub-phase Results
- SP1: [status] - [subagent name or "main agent"]
- SP2: [status] - [subagent name or "main agent"] ...
- SP1: [status] - [subagent name or "main agent"]
- SP2: [status] - [subagent name or "main agent"] ...
**3.5阶段工件(若使用):**
```markdownReview Results
Review Scope
- SP1 Review: [status] - [reviewer name or "self-review"]
- SP2 Review: [status] - [reviewer name or "self-review"] ...
**Phase 3.5 artifact (if used):**
```markdown- Git range: [BASE_SHA..HEAD_SHA]
- Execution Mode: Parallel (subagent) / Sequential (self-review)
- Reviewer: [subagent name / self]
Review Scope
Issues Found
- Git range: [BASE_SHA..HEAD_SHA]
- Execution Mode: Parallel (subagent) / Sequential (self-review)
- Reviewer: [subagent name / self]
- Critical: [count]
- Important: [count]
- Minor: [count]
Issues Found
Verdict
- Critical: [count]
- Important: [count]
- Minor: [count]
[APPROVED / APPROVED WITH NOTES / CHANGES REQUIRED]
**第四阶段工件必须包含:**
```markdownVerdict
Execution Mode
[APPROVED / APPROVED WITH NOTES / CHANGES REQUIRED]
**Phase 4 artifact must include:**
```markdown- Mode: Parallel / Sequential
- Test Suites:
- Unit: [subagent name] / Main agent
- Integration: [subagent name] / Main agent
- E2E: [subagent name] / Main agent
Execution Mode
Results Summary
- Mode: Parallel / Sequential
- Test Suites:
- Unit: [subagent name] / Main agent
- Integration: [subagent name] / Main agent
- E2E: [subagent name] / Main agent
- Total execution time: [X] minutes
- Estimated sequential time: [Y] minutes
- Speedup: [Z]x
undefinedResults Summary
决策树
- Total execution time: [X] minutes
- Estimated sequential time: [Y] minutes
- Speedup: [Z]x
undefinedStarting Phase 4
│
▼
Subagent available? ──NO──► SEQUENTIAL MODE
│ - Execute SPs sequentially
│ - Extended self-review
│ - Document as sequential
│
YES
│
▼
3+ independent SPs? ──NO──► SEQUENTIAL MODE
│ - Single sub-phase
│ - No parallelism benefit
│
YES
│
▼
PARALLEL MODE
- Dispatch implementer per SP
- Two-stage review
- Integration after all doneDecision Tree
质量保障
Starting Phase 4
│
▼
Subagent available? ──NO──► SEQUENTIAL MODE
│ - Execute SPs sequentially
│ - Extended self-review
│ - Document as sequential
│
YES
│
▼
3+ independent SPs? ──NO──► SEQUENTIAL MODE
│ - Single sub-phase
│ - No parallelism benefit
│
YES
│
▼
PARALLEL MODE
- Dispatch implementer per SP
- Two-stage review
- Integration after all done两种模式均强制执行:
- TDD规范
- 工件锁定
- 关卡合规性
- 集成测试
并行模式优势:
- 每个子阶段拥有独立新鲜上下文
- 独立验证机制
- 执行速度更快(3-5倍)
顺序模式优势:
- 不依赖Subagent
- 协调更简单
- 上下文完整累积
Quality Maintenance
常见模式
—
模式1:多领域功能开发
Both modes enforce:
- TDD discipline
- Artifact locking
- Gate compliance
- Integration testing
Parallel Mode advantages:
- Fresh context per sub-phase
- Independent verification
- Faster execution (3-5x)
Sequential Mode advantages:
- No subagent dependency
- Simpler coordination
- Full context accumulation
场景: 功能涉及API、UI和数据库
第三阶段计划:
markdown
undefinedCommon Patterns
Sub-phases
Pattern 1: Multi-Domain Feature
—
Scenario: Feature touches API, UI, and database
Phase 3 plan:
markdown
undefined- SP1: API changes (backend/)
- SP2: UI changes (frontend/)
- SP3: Database migration (migrations/)
**第四阶段执行:**
- SP1、SP2、SP3并行调度(独立领域)
- 每个开发实现Subagent处理独立文件
- 所有完成后执行集成测试Sub-phases
模式2:顺序依赖场景
- SP1: API changes (backend/)
- SP2: UI changes (frontend/)
- SP3: Database migration (migrations/)
**Phase 4 execution:**
- SP1, SP2, SP3 dispatched in parallel (independent domains)
- Each implementer works on isolated files
- Integration testing after all complete场景: SP2依赖SP1的输出
第四阶段执行:
- 调度SP1 → 等待完成 → 审查 → 通过
- 调度SP2(携带SP1上下文) → 等待完成 → 审查 → 通过
- 顺序执行,不使用并行
Pattern 2: Sequential Dependencies
模式3:高风险变更场景
Scenario: SP2 depends on SP1 output
Phase 4 execution:
- Dispatch SP1 → wait → review → approve
- Dispatch SP2 (with SP1 context) → wait → review → approve
- Sequential, not parallel
场景: 关键认证系统变更
第三阶段: 采用TDD方式开发实现
3.5阶段: 强制代码审查
第四阶段: 并行测试(单元测试+集成测试+E2E测试)
Pattern 3: High-Risk Change
故障排查
—
Subagent执行失败
Scenario: Critical auth system change
Phase 4: Implement with TDD
Phase 3.5: Mandatory code review
Phase 4: Parallel testing (unit + integration + E2E)
- 检查提示词是否上下文自包含
- 确认已提供BASE_SHA
- 查看日志排查错误
- 使用更清晰的指令重试
Troubleshooting
并行SP执行后集成测试失败
Subagent fails to complete
—
- Check if prompt was self-contained
- Verify BASE_SHA was provided
- Review logs for errors
- Retry with clearer instructions
- 检查SP之间的文件冲突
- 验证是否存在共享可变状态
- 查看提交历史确认顺序问题
Integration tests fail after parallel SPs
顺序模式执行过慢
- Check for file conflicts between SPs
- Verify no shared mutable state
- Review commit history for ordering issues
- 考虑将计划拆分为更细粒度的SP
- 检查平台是否支持Subagent
- 验证工具检测功能是否正常
Sequential mode too slow
参考资料
- Consider breaking into more granular SPs
- Check if platform supports subagents
- Verify tool detection is working
- 主工作流:
SKILL.md - 开发实现Subagent:
agents/implementer.md - 代码审查Subagent:
agents/code-reviewer.md - 工件模板:
references/artifact-template.md
References
—
- Main workflow:
SKILL.md - Implementer subagent:
agents/implementer.md - Code reviewer subagent:
agents/code-reviewer.md - Artifact templates:
references/artifact-template.md
—