OpenClaw 自学手册(五):精通篇 - 多Agent团队与插件开发

第三部分:精通
多 Agent 团队
多个 Agent 协作可以处理复杂任务,每个 Agent 专精于特定领域。
为什么使用多 Agent?

单 Agent 多 Agent
上下文容易混乱 职责分离
通用而非专精 领域专家
串行处理 并行工作
人格单一 多元化团队

创建 Agent 团队

  1. 添加 Agent
# 添加策略 Agent
openclaw agents add milo \
  --workspace ~/.openclaw/agents/milo \
  --model "anthropic/claude-opus-4-20250514" \
  --bind telegram

# 添加开发 Agent
openclaw agents add dev \
  --workspace ~/.openclaw/agents/dev \
  --model "anthropic/claude-sonnet-4-20250514" \
  --bind telegram
  1. 配置 Agent 人格
    Milo(策略负责人)
# ~/.openclaw/agents/milo/SOUL.md

你是 Milo,团队负责人。

## 性格

- 自信、有远见、有魅力
- 善于战略规划和协调
- 关注大局而非细节

## 职责

- 战略规划和优先级排序
- 协调其他 Agent
- 每周目标设定和 OKR 跟踪
- 综合所有 Agent 的洞察

## 沟通风格

- 简洁有力
- 使用要点列表
- 直接给出建议

Josh(业务分析)

# ~/.openclaw/agents/josh/SOUL.md

你是 Josh,业务分析师。

## 性格

- 务实、直接、数据驱动
- 关注指标和 KPI
- 善于财务分析

## 职责

- 定价策略和竞品分析
- 增长指标和 KPI 跟踪
- 收入建模和单位经济
- 客户反馈分析

Marketing(营销研究)

# ~/.openclaw/agents/marketing/SOUL.md

你是营销研究员。

## 性格

- 创意、好奇、趋势敏感
- 善于内容创作
- 关注社交媒体和 SEO

## 职责

- 内容构思和起草
- 竞品社交媒体监控
- Reddit/HN/X 趋势追踪
- SEO 关键词研究

Dev(开发)

# ~/.openclaw/agents/dev/SOUL.md

你是开发工程师。

## 性格

- 精确、细致、安全意识强
- 代码质量优先
- 关注最佳实践

## 职责

- 编码和架构决策
- 代码审查和质量检查
- Bug 调查和修复
- 技术文档编写
  1. 配置路由
    在主 Agent 的 AGENTS.md 中配置:
# AGENTS.md

## 团队路由

我们在 Telegram 群组 "Team" 中协作:

- `@milo` → 策略负责人
- `@josh` → 业务分析
- `@marketing` → 营销研究
- `@dev` → 开发工程
- `@all` → 广播给所有 Agent
- 无标签 → Milo 默认处理

## 工作流程

1. 收到消息时,检查是否被 @
2. 如果被 @,转发给对应 Agent
3. 如果无 @,Milo 处理或分配
4. 更新共享项目状态
  1. 共享记忆结构
shared/
├── GOALS.md           # OKRs 和优先级
├── DECISIONS.md       # 决策日志
├── PROJECT_STATUS.md  # 项目状态
└── agents/
    ├── milo/          # Milo 私有笔记
    ├── josh/          # Josh 私有笔记
    ├── marketing/     # 营销研究
    └── dev/           # 技术笔记
  1. 配置定时任务
# Milo:早间站会(每天 8:00)
openclaw cron add \
  --name "早间站会" \
  --cron "0 8 * * *" \
  --agent milo \
  --session isolated \
  --message "发布早间站会,总结夜间活动并设定今日优先级" \
  --deliver

# Josh:指标检查(每天 9:00)
openclaw cron add \
  --name "指标检查" \
  --cron "0 9 * * *" \
  --agent josh \
  --session isolated \
  --message "汇总关键业务指标" \
  --deliver

# Marketing:内容创意(每天 10:00)
openclaw cron add \
  --name "内容创意" \
  --cron "0 10 * * *" \
  --agent marketing \
  --session isolated \
  --message "基于热门话题生成 3 个内容创意" \
  --deliver

# Milo:日终总结(每天 18:00)
openclaw cron add \
  --name "日终总结" \
  --cron "0 18 * * *" \
  --agent milo \
  --session isolated \
  --message "发布日终总结,汇报本周目标进展" \
  --deliver

多 Agent 最佳实践
从小开始:先创建 2 个 Agent,然后按需扩展
明确定义:每个 Agent 的职责要清晰
共享上下文:使用共享文件避免信息孤岛
合理分工:为任务选择合适的模型(不用 Opus 做简单任务)
主动调度:用 cron 任务让 Agent 主动工作
插件开发
插件是扩展 OpenClaw 功能的强大方式。
插件 vs 技能

特性 技能 插件
功能 教 Agent 用工具 扩展平台能力
复杂度 简单 复杂
权限 受限 系统级
示例 如何用 Git 新消息渠道

插件结构

my-openclaw-plugin/
├── package.json
├── openclaw.plugin.json
├── src/
│   └── index.ts
├── skills/
│   └── my-skill/
│       └── SKILL.md
└── README.md

创建插件

  1. 初始化项目
mkdir my-openclaw-plugin
cd my-openclaw-plugin
npm init -y
npm install openclaw-plugin-sdk
  1. 配置 package.json
{
  "name": "my-openclaw-plugin",
  "version": "1.0.0",
  "main": "dist/index.js",
  "openclaw": {
    "id": "my-plugin",
    "displayName": "My Plugin",
    "description": "My custom plugin"
  }
}
  1. 创建 openclaw.plugin.json
{
  "id": "my-plugin",
  "displayName": "My Plugin",
  "description": "My custom plugin",
  "version": "1.0.0",
  "entry": "dist/index.js",
  "minOpenClawVersion": "2026.1.0",
  "permissions": [
    "gateway:rpc",
    "agent:lifecycle"
  ],
  "skills": ["skills/my-skill"],
  "config": {}
}
  1. 编写插件代码
// src/index.ts
import { Plugin } from 'openclaw-plugin-sdk';

export default class MyPlugin extends Plugin {
  async onLoad() {
    console.log('MyPlugin loaded!');
  }

  async onUnload() {
    console.log('MyPlugin unloaded!');
  }

  registerHooks() {
    return {
      'before_agent_start': async (context) => {
        console.log('Agent starting:', context.sessionId);
      },
      'after_agent_end': async (context) => {
        console.log('Agent ended:', context.sessionId);
      }
    };
  }
}
  1. 构建和安装
# 构建
npm run build

# 打包
npm pack

# 安装
openclaw plugins install ./my-openclaw-plugin-1.0.0.tgz

# 启用
openclaw plugins enable my-plugin

可用的钩子

// Agent 生命周期
'before_agent_start'
'agent_end'
'session_start'
'session_end'

// 工具调用
'before_tool_call'
'after_tool_call'
'tool_result_persist'

// 消息处理
'message_received'
'message_sending'
'message_sent'

// Gateway
'gateway_start'
'gateway_stop'

// 压缩
'before_compaction'
'after_compaction'

相关文章:

3 个赞

多Agent协作太强了

插件开发门槛不高

1 个赞

团队路由设计很巧妙

从小团队开始试试

@tangzichen 插件开发门槛不高 但维护成本不低 随着OpenClaw版本迭代 插件也要跟着更新 写之前想好长期维护意愿

@kaiyuan_zhushou 从小团队开始试是对的 两三个Agent协作就能覆盖大部分场景 Agent太多反而增加协调成本