用途
Multi-Agent Orchestrator 是一个多智能体委派与编排系统,灵感来自 ZeroClaw 的 delegate 工具,并扩展了并行执行流水线、智能结果聚合和技能感知的任务路由。它让主智能体能够将复杂任务拆解为可管理的子任务,委派给具有不同配置的专用子智能体,并行执行以提高效率,并将多个智能体的结果聚合为连贯的输出,同时协调带依赖关系的多步骤工作流。
主要能力
- 任务拆解:将复杂任务分解为可管理的子任务。
- 委派:将子任务委派给具有不同配置的专用子智能体。
- 并行执行:并行运行多个子智能体以提高效率。
- 结果聚合:将多个智能体的结果合并为连贯输出。
- 工作流协调:协调带依赖关系的多步骤工作流。
系统新增的工具包括:
delegate_task:将任务委派给单个专用子智能体,返回带置信度分数的结构化结果。parallel_delegates:在任务的不同方面并行运行多个子智能体,支持 aggregate_mode 为 "synthesize"、"concatenate"、"vote"、"merge"。create_workflow:定义带依赖关系的多步骤工作流。run_workflow:执行已定义的工作流。aggregate_results:合并多个智能体的结果,模式包括 "synthesize"、"concatenate"、"vote"、"rank"。spawn_agent:创建临时的专用智能体实例。
结果聚合模式包括:
- synthesize:由 LLM 带推理地合并结果。
- concatenate:简单拼接并加标题。
- vote:基于多数/相似度取最佳。
- rank:按置信度/分数排序。
- diff:突出分歧。
使用方式
安装
cd /job/.pi/skills/multi-agent-orchestrator
npm install
配置
在工作区根目录创建 ORCHESTRATOR.md,定义可用的智能体模板(如 code-specialist、research-analyst、creative-writer),每个模板可指定 system_prompt、model、temperature、skills。默认设置包括 max_parallel_agents、timeout_per_agent、auto_merge_results。
命令行命令
- 委派单个任务:
orchestrator-delegate --agent code-specialist --task "Review this code for bugs" --input file.js - 运行并行任务:
orchestrator-parallel --agents "code-specialist,research-analyst" --task "Analyze authentication approaches" --aggregate "synthesize" - 创建并管理工作流:
orchestrator-workflow create security-audit --file workflow.json,orchestrator-workflow run security-audit --input target-repo/ - 列出活跃智能体:
orchestrator-list - 查看结果:
orchestrator-results --session <session-id>
工具调用示例
委派单个任务:
delegate_task({
agent_type: "code-specialist",
task: "Review this function for security vulnerabilities",
input: "function authenticate(token) { return jwt.verify(token); }",
timeout: 120,
context: { language: "javascript", focus: "security" }
})
并行委派:
parallel_delegates({
tasks: [
{ agent_type: "security-analyst", task: "Check for SQL injection" },
{ agent_type: "perf-analyst", task: "Check for N+1 queries" },
{ agent_type: "style-reviewer", task: "Check code style" }
],
aggregate_mode: "synthesize",
input: codebase_path
})
创建工作流:
create_workflow({
name: "comprehensive-review",
steps: [
{ id: "1", action: "delegate", agent: "security-analyst", task: "Security review" },
{ id: "2", action: "delegate", agent: "perf-analyst", task: "Performance review", depends_on: ["1"] },
{ id: "3", action: "delegate", agent: "style-reviewer", task: "Style review", depends_on: ["1"] },
{ id: "4", action: "aggregate", mode: "synthesize", depends_on: ["2", "3"] }
]
})
运行工作流:
run_workflow({
name: "comprehensive-review",
input: "./src",
variables: { priority: "high", scope: "full" }
})
聚合结果:
aggregate_results({
results: [
{ agent: "security", output: "Found 2 issues..." },
{ agent: "perf", output: "1 optimization needed..." }
],
mode: "synthesize",
context: "Code review for authentication module"
})
生成临时智能体:
spawn_agent({
name: "temp-code-reviewer",
system_prompt: "You are a specialist in...",
model: "claude-sonnet-4",
temperature: 0.3,
timeout: 60
})
工作流定义格式
工作流以 JSON 定义,包含 name、description、steps。每个 step 可指定 id、action(delegate 或 aggregate)、agent、task、output_key、depends_on、mode、context 等。
适用场景
- 任务具有多个不同方面(如安全 + 性能 + 风格)。
- 子任务需要专门的专业知识。
- 工作可以并行化以提高效率。
- 多个视角能改善最终结果。
示例工作流包括:
- 代码审查流水线:安全分析师、性能分析师、风格审查员并行工作,再由合成器合并为最终报告。
- 研究与起草:研究智能体收集信息,大纲智能体创建结构,写作智能体起草内容,编辑智能体润色。
限制
以下情况不建议使用多智能体编排:
- 任务简单且单一。
- 延迟至关重要(编排会增加 5-10 秒开销)。
- 任务需要紧密的反馈循环。
- 成本是主要约束(会成倍增加 API 调用)。
实现说明
- 智能体生成:子智能体作为独立的 Pi 智能体进程生成,具有自定义系统提示、配置的模型和温度、特定技能集以及隔离的工作区目录。
- 并行执行:使用 Promise.all() 实现真正的并行,遵守 max_parallel_agents 限制,每个智能体有独立超时,支持部分失败继续。
- 会话管理:每次编排运行获得唯一会话 ID,跟踪时间戳和持续时间,记录各个智能体结果,保留最终输出,状态为 pending → running → complete/failed。
- 错误处理:部分失败时继续使用可用结果;超时标记超时智能体并继续其他;每个智能体自动重试最多 2 次;合成失败时回退为拼接结果。
性能特征
- 智能体生成时间:约 2-5 秒
- 并行限制:3-5 个智能体(可配置)
- 结果聚合:约 5-15 秒
- 工作流开销:每步约 1 秒
- 会话存储:每个完成的会话约 50KB
文件结构
.pi/skills/multi-agent-orchestrator/
├── SKILL.md
├── package.json
├── lib/
│ ├── orchestrator.js
│ ├── agent-pool.js
│ ├── task-router.js
│ ├── result-aggregator.js
│ ├── session-manager.js
│ └── workflow-engine.js
├── bin/
│ ├── orchestrator-delegate.js
│ ├── orchestrator-parallel.js
│ ├── orchestrator-workflow.js
│ ├── orchestrator-list.js
│ ├── orchestrator-results.js
│ └── orchestrator-spawn.js
├── examples/
│ ├── code-review-workflow.json
│ ├── research-workflow.json
│ └── security-audit-workflow.json
└── tests/
└── orchestrator.test.js
未来扩展
计划中的增强包括:动态智能体创建(智能体根据任务定义自身)、学习(记住哪些智能体类型最适合哪些任务)、智能体协商(智能体之间相互通信)、分层团队(团队负责人管理子团队)。