feat: 添加多 Agent 协作支持
- 新增 agentType 参数:coordinator/specialist/general - coordinator: 协调者,负责任务分解和分发 - specialist: 专职 agent,接收协调者分配的任务 - 生成不同的 AGENTS.md 模板,包含协作说明 - 所有 agent 都可以读取 agents-registry.json 了解其他 agent - 新增 AGENT-COLLABORATION.md 文档,说明游戏策划工作室示例
This commit is contained in:
297
AGENT-COLLABORATION.md
Normal file
297
AGENT-COLLABORATION.md
Normal file
@@ -0,0 +1,297 @@
|
||||
# Agent 协作模式 - 游戏策划工作室示例
|
||||
|
||||
## 场景:游戏策划工作室
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ 策划总监 (Director) │
|
||||
│ - 与用户交流,理解需求 │
|
||||
│ - 分解任务,分发给专职 agent │
|
||||
│ - 整合结果,交付给用户 │
|
||||
│ - 需要知道所有专职 agent 的存在和能力 │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────┼─────────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
|
||||
│ 数值策划 │ │ 剧情策划 │ │ 世界观策划 │
|
||||
│ (Balance) │ │ (Story) │ │ (Lore) │
|
||||
│ - 战斗公式 │ │ - 主线剧情 │ │ - 背景设定 │
|
||||
│ - 经济系统 │ │ - 角色对话 │ │ - 地理历史 │
|
||||
│ - 成长曲线 │ │ - 任务设计 │ │ - 文化体系 │
|
||||
└───────────────┘ └───────────────┘ └───────────────┘
|
||||
```
|
||||
|
||||
## 实现方案
|
||||
|
||||
### 1. 共享 Agent 注册表(已实现)
|
||||
|
||||
所有 agent 都可以读取:`/home/admin/.openclaw/agents-registry.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"agents": [
|
||||
{
|
||||
"id": "game-director",
|
||||
"name": "游戏策划总监",
|
||||
"type": "coordinator",
|
||||
"description": "与用户交流,分解需求,协调各专职 agent",
|
||||
"capabilities": ["需求分析", "任务分解", "结果整合"]
|
||||
},
|
||||
{
|
||||
"id": "game-balance",
|
||||
"name": "数值策划",
|
||||
"type": "specialist",
|
||||
"description": "负责游戏数值系统设计",
|
||||
"capabilities": ["战斗公式", "经济系统", "成长曲线"]
|
||||
},
|
||||
{
|
||||
"id": "game-story",
|
||||
"name": "剧情策划",
|
||||
"type": "specialist",
|
||||
"description": "负责剧情和任务设计",
|
||||
"capabilities": ["主线剧情", "角色对话", "任务设计"]
|
||||
},
|
||||
{
|
||||
"id": "game-lore",
|
||||
"name": "世界观策划",
|
||||
"type": "specialist",
|
||||
"description": "负责世界观和文化设定",
|
||||
"capabilities": ["背景设定", "地理历史", "文化体系"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 协调者 Agent 的 AGENTS.md
|
||||
|
||||
```markdown
|
||||
# AGENTS.md - 游戏策划总监
|
||||
|
||||
## 你的角色
|
||||
|
||||
你是**策划总监**,负责:
|
||||
1. 与用户交流,理解游戏策划需求
|
||||
2. 将需求分解为子任务
|
||||
3. 分发给专职 agent(数值/剧情/世界观)
|
||||
4. 整合各 agent 的结果,交付给用户
|
||||
|
||||
## 可用的专职 Agent
|
||||
|
||||
读取 `/home/admin/.openclaw/agents-registry.json` 获取完整列表。
|
||||
|
||||
### 专职 Agent 列表
|
||||
|
||||
| Agent ID | 名称 | 职责 | 何时使用 |
|
||||
|----------|------|------|----------|
|
||||
| `game-balance` | 数值策划 | 战斗公式、经济系统、成长曲线 | 涉及数值计算时 |
|
||||
| `game-story` | 剧情策划 | 主线剧情、角色对话、任务设计 | 涉及剧情内容时 |
|
||||
| `game-lore` | 世界观策划 | 背景设定、地理历史、文化体系 | 涉及世界观设定时 |
|
||||
|
||||
## 任务分发流程
|
||||
|
||||
### 步骤 1:理解需求
|
||||
|
||||
与用户交流,明确需求:
|
||||
- 游戏类型
|
||||
- 具体要设计的内容
|
||||
- 期望的输出格式
|
||||
|
||||
### 步骤 2:分解任务
|
||||
|
||||
将需求分解为专职 agent 可以处理的子任务。
|
||||
|
||||
**示例:**
|
||||
用户:"帮我设计一个 RPG 游戏的战斗系统"
|
||||
|
||||
分解:
|
||||
- → `game-balance`: 设计战斗公式、伤害计算、属性成长
|
||||
- → `game-lore`: 设计战斗背景、世界观设定
|
||||
- → `game-story`: 设计战斗相关的剧情和任务
|
||||
|
||||
### 步骤 3:发送任务
|
||||
|
||||
使用 `sessions_send` 工具发送任务给专职 agent:
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "sessions_send",
|
||||
"agentId": "game-balance",
|
||||
"message": "任务:设计 RPG 战斗系统的数值框架\n\n要求:\n1. 设计伤害计算公式\n2. 设计属性成长曲线\n3. 输出 Markdown 格式\n\n上下文:[游戏类型、背景等]"
|
||||
}
|
||||
```
|
||||
|
||||
### 步骤 4:收集结果
|
||||
|
||||
等待各 agent 返回结果,使用 `sessions_yield` 接收。
|
||||
|
||||
### 步骤 5:整合交付
|
||||
|
||||
将各 agent 的结果整合为一份完整的文档,交付给用户。
|
||||
|
||||
## 协作技巧
|
||||
|
||||
### 并行处理
|
||||
|
||||
可以同时向多个 agent 发送任务:
|
||||
|
||||
```
|
||||
发送 → game-balance
|
||||
发送 → game-lore
|
||||
发送 → game-story
|
||||
↓
|
||||
等待所有结果
|
||||
↓
|
||||
整合输出
|
||||
```
|
||||
|
||||
### 链式处理
|
||||
|
||||
某些任务需要顺序执行:
|
||||
|
||||
```
|
||||
game-lore (世界观) → game-story (剧情) → game-balance (数值)
|
||||
```
|
||||
|
||||
### 上下文传递
|
||||
|
||||
给专职 agent 发送任务时,提供足够的上下文:
|
||||
- 项目背景
|
||||
- 用户需求
|
||||
- 其他 agent 的输出(如果相关)
|
||||
|
||||
## 示例工作流
|
||||
|
||||
### 示例:设计一个手游项目
|
||||
|
||||
**用户输入:**
|
||||
"帮我设计一个二次元卡牌手游的核心系统"
|
||||
|
||||
**你的处理流程:**
|
||||
|
||||
1. **分解任务:**
|
||||
- 数值策划 → 卡牌养成系统、战斗数值
|
||||
- 剧情策划 → 主线剧情框架、角色设定
|
||||
- 世界观策划 → 游戏背景、世界观设定
|
||||
|
||||
2. **发送任务:**
|
||||
```
|
||||
→ game-balance: "设计卡牌养成和战斗数值..."
|
||||
→ game-story: "设计主线剧情和角色..."
|
||||
→ game-lore: "设计世界观和背景..."
|
||||
```
|
||||
|
||||
3. **等待结果并整合**
|
||||
|
||||
4. **交付给用户:**
|
||||
```
|
||||
# 二次元卡牌手游设计方案
|
||||
|
||||
## 世界观设定 (by game-lore)
|
||||
...
|
||||
|
||||
## 剧情框架 (by game-story)
|
||||
...
|
||||
|
||||
## 数值系统 (by game-balance)
|
||||
...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**记住:** 你是协调者,不是执行者。你的价值在于理解需求、分解任务、整合结果。
|
||||
```
|
||||
|
||||
### 3. 专职 Agent 的 AGENTS.md
|
||||
|
||||
```markdown
|
||||
# AGENTS.md - 数值策划
|
||||
|
||||
## 你的角色
|
||||
|
||||
你是**数值策划专家**,负责:
|
||||
- 战斗公式设计
|
||||
- 经济系统平衡
|
||||
- 角色/装备成长曲线
|
||||
- 数值验证和调优
|
||||
|
||||
## 你的上级
|
||||
|
||||
**策划总监:** `game-director`
|
||||
|
||||
- 接收来自 `game-director` 的任务分配
|
||||
- 将结果返回给 `game-director`
|
||||
- 不直接与用户交流(除非特别授权)
|
||||
|
||||
## 可用的协作 Agent
|
||||
|
||||
读取 `/home/admin/.openclaw/agents-registry.json` 获取完整列表。
|
||||
|
||||
### 何时需要协作
|
||||
|
||||
- 需要剧情背景 → 询问 `game-story`
|
||||
- 需要世界观设定 → 询问 `game-lore`
|
||||
- 需要整合交付 → 返回给 `game-director`
|
||||
|
||||
## 工作模式
|
||||
|
||||
### 接收任务
|
||||
|
||||
等待 `game-director` 通过 `sessions_send` 发送任务。
|
||||
|
||||
### 执行任务
|
||||
|
||||
1. 理解任务需求和上下文
|
||||
2. 调用相关 skills(如 feishu-bitable 做数值表)
|
||||
3. 输出专业文档
|
||||
|
||||
### 返回结果
|
||||
|
||||
使用 `sessions_send` 返回结果给 `game-director`:
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "sessions_send",
|
||||
"agentId": "game-director",
|
||||
"message": "任务完成:战斗公式设计\n\n[详细数值文档]"
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
## 技能增强
|
||||
|
||||
### 创建协调者 Agent
|
||||
|
||||
使用 `agent-creator-with-binding` 创建时,指定为协调者类型:
|
||||
|
||||
```bash
|
||||
openclaw skills run agent-creator-with-binding -- \
|
||||
--agent-id game-director \
|
||||
--agent-name "游戏策划总监" \
|
||||
--binding-mode account \
|
||||
--new-bot \
|
||||
--app-id cli_xxx \
|
||||
--app-secret yyy \
|
||||
--dm-policy allowlist \
|
||||
--agent-type coordinator
|
||||
```
|
||||
|
||||
### 创建专职 Agent
|
||||
|
||||
```bash
|
||||
openclaw skills run agent-creator-with-binding -- \
|
||||
--agent-id game-balance \
|
||||
--agent-name "数值策划" \
|
||||
--binding-mode none \
|
||||
--agent-type specialist \
|
||||
--coordinator game-director
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 下一步
|
||||
|
||||
1. **更新 agent-creator-with-binding**:添加 `--agent-type` 和 `--coordinator` 参数
|
||||
2. **生成专用模板**:为 coordinator 和 specialist 生成不同的 AGENTS.md
|
||||
3. **添加任务分发 skill**:帮助 coordinator 管理任务队列和进度
|
||||
120
index.js
120
index.js
@@ -188,18 +188,49 @@ function generateAgentFiles(options) {
|
||||
|
||||
// 生成 SOUL.md 内容
|
||||
function generateSoulContent(options) {
|
||||
const { agentName, description, bindingMode } = options;
|
||||
const agentType = bindingMode === 'none' ? '后台 Agent' : '前台 Agent';
|
||||
const { agentName, description, bindingMode, agentType, coordinator } = options;
|
||||
const displayType = agentType === 'coordinator' ? '协调者 Agent'
|
||||
: agentType === 'specialist' ? '专职 Agent'
|
||||
: bindingMode === 'none' ? '后台 Agent' : '前台 Agent';
|
||||
|
||||
// 根据职责生成 Skills 推荐
|
||||
const recommendedSkills = getRecommendedSkills(options);
|
||||
|
||||
// 协调者专属内容
|
||||
const coordinatorSection = agentType === 'coordinator' ? `
|
||||
|
||||
## 多 Agent 协作
|
||||
|
||||
你是**协调者**,负责:
|
||||
1. 与用户交流,理解需求
|
||||
2. 将需求分解为子任务
|
||||
3. 分发给专职 agent
|
||||
4. 整合结果,交付给用户
|
||||
|
||||
**重要:** 读取 \`/home/admin/.openclaw/agents-registry.json\` 了解所有可用 agent!
|
||||
` : '';
|
||||
|
||||
// 专职 agent 专属内容
|
||||
const specialistSection = agentType === 'specialist' ? `
|
||||
|
||||
## 多 Agent 协作
|
||||
|
||||
你是**专职 Agent**,负责:
|
||||
1. 接收协调者 (\`${coordinator || 'game-director'}\`) 分配的任务
|
||||
2. 执行专业领域的工作
|
||||
3. 将结果返回给协调者
|
||||
|
||||
**重要:**
|
||||
- 主要与 \`${coordinator || 'game-director'}\` 协作
|
||||
- 读取 \`/home/admin/.openclaw/agents-registry.json\` 了解其他 agent
|
||||
` : '';
|
||||
|
||||
return `# SOUL.md - ${agentName}
|
||||
|
||||
## 身份
|
||||
- **名称:** ${agentName}
|
||||
- **职责:** ${description || '帮助用户完成任务'}
|
||||
- **类型:** ${agentType}
|
||||
- **类型:** ${displayType}${coordinatorSection}${specialistSection}
|
||||
|
||||
## 行为准则
|
||||
1. 遵循 OpenClaw 规范
|
||||
@@ -224,12 +255,66 @@ ${recommendedSkills}
|
||||
|
||||
// 生成 AGENTS.md 内容
|
||||
function generateAgentsContent(options) {
|
||||
const { agentName, description, bindingMode } = options;
|
||||
const { agentName, description, bindingMode, agentType, coordinator } = options;
|
||||
|
||||
const responsibilities = generateResponsibilities(bindingMode, description);
|
||||
const workflow = generateWorkflow(bindingMode);
|
||||
const toolsUsage = generateToolsUsage(options);
|
||||
|
||||
// 协调者专属内容
|
||||
const coordinatorSection = agentType === 'coordinator' ? `
|
||||
## 多 Agent 协作
|
||||
|
||||
### 你的角色
|
||||
|
||||
你是**协调者**,负责与用户交流并分解任务给专职 agent。
|
||||
|
||||
### 可用的专职 Agent
|
||||
|
||||
读取 \`/home/admin/.openclaw/agents-registry.json\` 获取完整列表和实时状态。
|
||||
|
||||
### 任务分发流程
|
||||
|
||||
1. **理解需求** - 与用户交流,明确需求
|
||||
2. **分解任务** - 将需求分解为专职 agent 可以处理的子任务
|
||||
3. **发送任务** - 使用 \`sessions_send\` 工具发送给专职 agent
|
||||
4. **收集结果** - 等待各 agent 返回结果
|
||||
5. **整合交付** - 将结果整合为完整文档,交付给用户
|
||||
|
||||
### 示例
|
||||
|
||||
\`\`\`json
|
||||
{
|
||||
"action": "sessions_send",
|
||||
"agentId": "game-balance",
|
||||
"message": "任务:设计 RPG 战斗系统的数值框架\\n\\n要求:..."
|
||||
}
|
||||
\`\`\`
|
||||
` : '';
|
||||
|
||||
// 专职 agent 专属内容
|
||||
const specialistSection = agentType === 'specialist' ? `
|
||||
## 多 Agent 协作
|
||||
|
||||
### 你的上级
|
||||
|
||||
**协调者:** \`${coordinator || 'game-director'}\`
|
||||
|
||||
- 接收来自 \`${coordinator || 'game-director'}\` 的任务分配
|
||||
- 将结果返回给 \`${coordinator || 'game-director'}\`
|
||||
- 不直接与用户交流(除非特别授权)
|
||||
|
||||
### 可用的协作 Agent
|
||||
|
||||
读取 \`/home/admin/.openclaw/agents-registry.json\` 获取完整列表。
|
||||
|
||||
### 工作模式
|
||||
|
||||
1. **接收任务** - 等待协调者通过 \`sessions_send\` 发送任务
|
||||
2. **执行任务** - 理解需求,调用工具,输出专业文档
|
||||
3. **返回结果** - 使用 \`sessions_send\` 返回给协调者
|
||||
` : '';
|
||||
|
||||
return `# AGENTS.md - ${agentName} 工作指令
|
||||
|
||||
## 职责范围
|
||||
@@ -242,11 +327,12 @@ ${responsibilities}
|
||||
${workflow}
|
||||
|
||||
## 工具使用
|
||||
${toolsUsage}
|
||||
${toolsUsage}${coordinatorSection}${specialistSection}
|
||||
|
||||
## 依赖读取
|
||||
- 项目上下文:\`/home/admin/.openclaw/projects/<项目名>/context.md\`
|
||||
- 任务追踪:\`/home/admin/.openclaw/projects/<项目名>/tasks.json\`
|
||||
- **Agent 注册表:** \`/home/admin/.openclaw/agents-registry.json\` ⭐
|
||||
|
||||
## 输出文件
|
||||
- 输出到:\`/home/admin/.openclaw/projects/<项目名>/<职责目录>/\`
|
||||
@@ -444,7 +530,9 @@ function updateAgentsRegistry(options) {
|
||||
name: options.agentName || options.agentId,
|
||||
description: options.description || `${options.agentName || options.agentId} agent`,
|
||||
workspace: `/home/admin/.openclaw/workspace-${options.agentId}/`,
|
||||
type: options.bindingMode === 'none' ? 'backend' : 'frontend',
|
||||
type: options.agentType || (options.bindingMode === 'none' ? 'backend' : 'general'),
|
||||
coordinator: options.coordinator || null,
|
||||
capabilities: options.capabilities ? options.capabilities.split(',').map(s => s.trim()) : [],
|
||||
binding: options.bindingMode !== 'none' ? {
|
||||
channel: 'feishu',
|
||||
accountId: options.accountId,
|
||||
@@ -631,8 +719,22 @@ async function interactiveMode() {
|
||||
const bindingMode = modeChoice.toLowerCase() === 'a' ? 'account'
|
||||
: modeChoice.toLowerCase() === 'b' ? 'group' : 'none';
|
||||
|
||||
// 步骤 2b:选择 Agent 类型(多 Agent 协作)
|
||||
log.step(2.5, 6, '选择 Agent 类型');
|
||||
console.log('\nAgent 类型说明:');
|
||||
console.log(' - general: 通用 Agent,独立工作(默认)');
|
||||
console.log(' - coordinator: 协调者,负责分解任务给其他 agent');
|
||||
console.log(' - specialist: 专职 agent,接收协调者分配的任务');
|
||||
const typeChoice = await question('选择 Agent 类型(general/coordinator/specialist,默认 general): ') || 'general';
|
||||
const agentType = typeChoice.toLowerCase();
|
||||
|
||||
let coordinator = null;
|
||||
if (agentType === 'specialist') {
|
||||
coordinator = await question('你的协调者 Agent ID(如 game-director): ');
|
||||
}
|
||||
|
||||
// 步骤 3:根据绑定模式收集信息
|
||||
let options = { agentId, agentName, description, bindingMode };
|
||||
let options = { agentId, agentName, description, bindingMode, agentType, coordinator };
|
||||
|
||||
if (bindingMode === 'account') {
|
||||
log.step(3, 6, '配置飞书机器人');
|
||||
@@ -834,6 +936,8 @@ ${colors.bold}选项:${colors.reset}
|
||||
--dm-policy <policy> DM 策略:allowlist/open/pairing(默认 allowlist)
|
||||
--allow-from <users> 白名单用户,逗号分隔(如:ou_xxx,ou_yyy)
|
||||
--group-policy <policy> 群聊策略:open/allowlist/disabled(默认 open)
|
||||
--agent-type <type> Agent 类型:coordinator/specialist/general(默认 general)
|
||||
--coordinator <agent-id> 协调者 ID(specialist 类型时需要)
|
||||
--skip-confirm 跳过确认
|
||||
--skip-restart 跳过重启
|
||||
|
||||
@@ -875,6 +979,8 @@ ${colors.bold}示例:${colors.reset}
|
||||
agentName: options.agentname || options.agentid,
|
||||
description: options.description,
|
||||
bindingMode: options.bindingmode || 'account',
|
||||
agentType: options.agenttype || 'general',
|
||||
coordinator: options.coordinator,
|
||||
newBot: options.newbot === 'true',
|
||||
appId: options.appid,
|
||||
appSecret: options.appsecret,
|
||||
|
||||
Reference in New Issue
Block a user