Community编程与开发github.com

并行分派代理

当有 2 个以上独立任务,且这些任务无需共享状态或顺序依赖时,可并行分派专用代理处理。

并行分派代理 是什么?

该技能用于将独立的问题域并行分派给多个专用子代理,每个子代理拥有独立的上下文,不会继承主会话的历史。核心原则是:每个独立的问题域分派一个代理,让它们并发工作。适用场景包括:3 个以上不同根因的测试文件失败、多个子系统独立故障等。不适用于相关故障、需要全局上下文或代理间存在共享状态的情况。技能详细描述了识别独立域、创建聚焦任务、并行分派以及审查整合的四个步骤,并给出了优秀的代理提示结构示例和常见错误对比。支持所有允许子代理分派的平台(如 Claude Code、Cursor、Codex 等)。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/obra/superpowers/tree/main/skills/dispatching-parallel-agents

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

并行分派代理 是做什么的?

概述

你将任务委派给具有隔离上下文的专用代理。通过精确构建它们的指令和上下文,你确保它们专注于自己的任务并取得成功。它们绝不应继承你的会话上下文或历史记录——你精确地构造它们所需的一切。这同时也保留了你自己的上下文用于协调工作。

当你遇到多个不相关的失败(不同的测试文件、不同的子系统、不同的错误)时,按顺序逐个调查会浪费时间。每个调查都是独立的,可以并行进行。

核心原则: 每个独立的问题域分派一个代理。让它们并发工作。

何时使用

digraph when_to_use {
    "多个失败?" [shape=diamond];
    "它们独立吗?" [shape=diamond];
    "单个代理调查所有" [shape=box];
    "每个问题域一个代理" [shape=box];
    "可以并行工作吗?" [shape=diamond];
    "顺序代理" [shape=box];
    "并行分派" [shape=box];

    "多个失败?" -> "它们独立吗?" [label="是"];
    "它们独立吗?" -> "单个代理调查所有" [label="否 - 相关"];
    "它们独立吗?" -> "可以并行工作吗?" [label="是"];
    "可以并行工作吗?" -> "并行分派" [label="是"];
    "可以并行工作吗?" -> "顺序代理" [label="否 - 共享状态"];
}

使用时:

  • 3+ 个测试文件失败的根因各不相同
  • 多个子系统独立故障
  • 每个问题无需其他问题上下文即可理解
  • 各调查之间没有共享状态

不要使用时:

  • 故障相关(修复一个可能修复其他)
  • 需要理解完整的系统状态
  • 代理之间会相互干扰

模式

1. 识别独立域

根据故障内容对失败进行分组:

  • 文件 A 测试:工具审批流程
  • 文件 B 测试:批处理完成行为
  • 文件 C 测试:中止功能

每个域都是独立的——修复工具审批不会影响中止测试。

2. 创建聚焦的代理任务

每个代理获得:

  • 具体范围: 一个测试文件或子系统
  • 明确目标: 让这些测试通过
  • 约束条件: 不要更改其他代码
  • 预期输出: 你发现和修复内容的摘要

3. 并行分派

在同一条回复中发出所有子代理分派——它们并行运行:

子代理(通用):"修复 agent-tool-abort.test.ts 的失败"
子代理(通用):"修复 batch-completion-behavior.test.ts 的失败"
子代理(通用):"修复 tool-approval-race-conditions.test.ts 的失败"
# 三者并行执行。

一条回复中的多个分派调用 = 并行执行。每条回复一个分派调用 = 顺序执行。

4. 审查与整合

当代理返回时:

  • 阅读每份摘要
  • 验证修复不冲突
  • 运行完整的测试套件
  • 整合所有更改

代理提示结构

良好的代理提示应具备:

  1. 聚焦 - 一个清晰的问题域
  2. 自包含 - 理解问题所需的所有上下文
  3. 输出明确 - 代理应该返回什么?
修复 src/agents/agent-tool-abort.test.ts 中的 3 个失败测试:

1. "should abort tool with partial output capture" - 期望消息中包含 'interrupted at'
2. "should handle mixed completed and aborted tools" - 快速工具被中止而不是完成
3. "should properly track pendingToolCount" - 期望 3 个结果但得到 0

这些是时序/竞态条件问题。你的任务:

1. 阅读测试文件,理解每个测试验证的内容
2. 识别根本原因——时序问题还是实际 bug?
3. 修复方法:
   - 用基于事件的等待替代任意超时
   - 如果发现 abort 实现中的 bug 则修复它
   - 如果测试的是已变更行为,则调整测试预期

不要只是增加超时——找到真正的问题。

返回:你发现的内容和修复内容的摘要。

常见错误

❌ 过于宽泛: "修复所有测试"——代理会迷失方向 ✅ 具体: "修复 agent-tool-abort.test.ts"——聚焦的范围

❌ 没有上下文: "修复竞态条件"——代理不知道在哪 ✅ 上下文: 粘贴错误消息和测试名称

❌ 没有约束: 代理可能会重构所有内容 ✅ 约束: "不要更改生产代码" 或 "只修复测试"

❌ 输出模糊: "修复它"——你不知道改变了什么 ✅ 具体: "返回根本原因和更改的摘要"

何时不要使用

相关故障: 修复一个可能修复其他——先一起调查 需要完整上下文: 理解需要查看整个系统 探索性调试: 你还不知道哪里出了问题 共享状态: 代理会相互干扰(编辑同一文件、使用相同资源)

实际会话示例

场景: 重大重构后 6 个测试失败,涉及 3 个文件

失败:

  • agent-tool-abort.test.ts:3 个失败(时序问题)
  • batch-completion-behavior.test.ts:2 个失败(工具未执行)
  • tool-approval-race-conditions.test.ts:1 个失败(执行计数 = 0)

决策: 独立域——中止逻辑与批处理完成逻辑与竞态条件逻辑相互独立

分派:

代理 1 → 修复 agent-tool-abort.test.ts
代理 2 → 修复 batch-completion-behavior.test.ts
代理 3 → 修复 tool-approval-race-conditions.test.ts

结果:

  • 代理 1:用基于事件的等待替代了超时
  • 代理 2:修复了事件结构 bug(threadId 放错了位置)
  • 代理 3:添加了等待异步工具执行完成的逻辑

整合: 所有修复相互独立,无冲突,完整测试套件全部通过

验证

代理返回后:

  1. 审查每份摘要 - 理解发生了什么变化
  2. 检查冲突 - 代理是否编辑了同一代码?
  3. 运行完整套件 - 验证所有修复共同工作
  4. 抽查 - 代理可能犯系统性错误

Individual skills in this repo

This repo contains 14 individual skills — each has its own dedicated page.

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

diagnosing-superpowers

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

executing-plans

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

finishing-a-development-branch

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

receiving-code-review

Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

requesting-code-review

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

subagent-driven-development

Use when executing implementation plans with independent tasks in the current session

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

test-driven-development

Use when implementing any feature or bugfix, before writing implementation code

using-git-worktrees

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback

using-superpowers

Use when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions

verification-before-completion

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

writing-plans

Use when you have a spec or requirements for a multi-step task, before touching code

writing-skills

Use when creating new skills, editing existing skills, or verifying skills work before deployment

相关技能