MapReduce 技能使得跨多个 AI 提供商或代理实例的并行任务执行成为可能,随后智能地整合结果。这通过利用不同模型的优势和交叉验证发现,产生更高质量的输出。
MapReduce 技能
技能 ID: mapreduce 目的: 将任务分发到多个提供商/代理,然后整合结果 类别: 编排
概览
MapReduce 技能使得跨多个 AI 提供商或代理实例的并行任务执行成为可能,随后智能地整合结果。这通过利用不同模型的优势和交叉验证发现,产生更高质量的输出。
架构
┌─────────────────────────────────────────────────────────────────────────┐
│ MAIN THREAD (Orchestrator) │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ PHASE 1: MAP (Parallel Fan-Out) │ │
│ │ │ │
│ │ Task(worker-1) ──→ output-1.md │ │
│ │ Task(worker-2) ──→ output-2.md │ │
│ │ Task(worker-3) ──→ output-3.md │ │
│ │ bash(codex) ──→ output-codex.md │ │
│ │ bash(gemini) ──→ output-gemini.md │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ PHASE 2: COLLECT (Timeout-Based) │ │
│ │ │ │
│ │ TaskOutput(worker-1, timeout=120s) │ │
│ │ TaskOutput(worker-2, timeout=120s) │ │
│ │ TaskOutput(worker-3, timeout=120s) │ │
│ │ Verify: output-codex.md, output-gemini.md exist │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ PHASE 3: REDUCE (Consolidation) │ │
│ │ │ │
│ │ Task(reducer) ──→ reads all outputs ──→ consolidated.md │ │
│ └─────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
关键约束
子代理不能生成其他子代理。 所有编排都在主线程中进行。工人和缩减器是操作文件的子代理。
用例
1. 并行规划
将规划任务分发到具有不同战略偏见的多个提供商:
Workers:
- planner-conservative: 低风险,经过验证的模式
- planner-aggressive: 快速通道,现代模式
- planner-security: 安全第一的方法
Reducer: plan-reducer
Output: specs/ROADMAP.md
查看: cookbook/parallel-planning.md
2. 多实现
使用多个模型生成相同功能,选择最佳:
Workers:
- impl-claude: Claude 的实现
- impl-codex: OpenAI 的实现
- impl-gemini: Gemini 的实现
Reducer: code-reducer
Output: src/feature/implementation.ts
查看: cookbook/multi-impl.md
3. 调试共识
获取多个 bug 诊断,验证并选择最佳修复:
Workers:
- debug-claude: Claude 的诊断
- debug-codex: Codex 的诊断
- debug-gemini: Gemini 的诊断
Reducer: debug-reducer
Output: 应用修复 + 文档
查看: cookbook/debug-consensus.md
可用缩减器
| 缩减器 | 代理路径 | 目的 |
|---|---|---|
plan-reducer |
agents/orchestration/reducers/plan-reducer.md |
整合计划 |
code-reducer |
agents/orchestration/reducers/code-reducer.md |
比较/合并代码 |
debug-reducer |
agents/orchestration/reducers/debug-reducer.md |
验证修复 |
提供商集成
Claude 子代理 (通过任务工具)
Task(subagent_type="Plan", prompt="...", run_in_background=true)
外部 CLI 提供商 (通过生成技能)
# Codex
codex -m gpt-5.1-codex -a full-auto "${PROMPT}" > output.md
# Gemini
gemini -m gemini-3-pro "${PROMPT}" > output.md
# Cursor
cursor-agent --mode print "${PROMPT}" > output.md
# OpenCode
opencode --provider anthropic "${PROMPT}" > output.md
查看: skills/spawn/agent/cookbook/ 了解详细的 CLI 模式。
文件约定
所有 MapReduce 操作遵循标准文件约定:
| 类型 | 位置 | 命名 |
|---|---|---|
| 计划输出 | specs/plans/ |
planner-{name}.md |
| 代码输出 | implementations/ |
impl-{name}.{ext} |
| 调试输出 | diagnoses/ |
debug-{name}.md |
| 整合 | 在提示中指定 | ROADMAP.md, implementation.ts |
查看: reference/file-conventions.md
评分标准
每个缩减器使用特定的评分标准:
- 计划: 完整性,可行性,风险,清晰度,创新
- 代码: 正确性,可读性,可维护性,性能,安全
- 调试: 正确性,最小化,安全性,清晰度,根本原因
查看: reference/scoring-rubrics.md
命令
| 命令 | 目的 |
|---|---|
/ai-dev-kit:mapreduce |
完整的 MapReduce 工作流 |
/ai-dev-kit:map |
仅扇出阶段 |
/ai-dev-kit:reduce |
仅整合阶段 |
示例: 完整的 MapReduce
# 在主线程中:
## 第 1 步: MAP
以单条消息启动规划器(启用并行):
Task(subagent_type="Plan", prompt="""
创建用户认证的实施计划
写入: specs/plans/planner-conservative.md
策略: 保守 - 经过验证的模式,最小风险
""", run_in_background=true)
Task(subagent_type="Plan", prompt="""
创建用户认证的实施计划
写入: specs/plans/planner-aggressive.md
策略: 积极 - 快速,现代模式
""", run_in_background=true)
Bash("codex -m gpt-5.1-codex -a full-auto '创建认证计划' > specs/plans/planner-codex.md")
## 第 2 步: COLLECT
TaskOutput(task_id=conservative-id, block=true, timeout=120000)
TaskOutput(task_id=aggressive-id, block=true, timeout=120000)
# 验证 codex 输出存在
Read("specs/plans/planner-codex.md")
## 第 3 步: REDUCE
Task(subagent_type="ai-dev-kit:orchestration:plan-reducer", prompt="""
整合 specs/plans/*.md 中的计划
输出: specs/ROADMAP.md
优先级: 安全高于速度
""")
食谱
parallel-planning.md: 多提供商规划工作流multi-impl.md: 代码生成与选择debug-consensus.md: 多诊断 bug 修复
参考
scoring-rubrics.md: 详细的评分标准file-conventions.md: 输出文件标准
相关技能
spawn: 提供商特定的 CLI 调用模式multi-agent-orchestration: 通用多代理模式research: 并行研究与综合