乐于分享
好东西不私藏

OpenClaw 多 Agent 配置完全指南:让 AI 团队协同工作

OpenClaw 多 Agent 配置完全指南:让 AI 团队协同工作

OpenClaw 多 Agent 配置完全指南

2026 年 3 月 · 让 AI 团队协同工作

单个 Agent 能力有限?来配置多个 Agent 协同工作!本文详解 OpenClaw 多 Agent 配置、协作模式和实战示例。


一、为什么需要多 Agent?

单 Agent 的局限

❌ 技能太多容易冲突 ❌ 一个模型无法胜任所有任务 ❌ 权限无法隔离 ❌ 无法专业化分工

多 Agent 的优势

专业化 - 每个 Agent 专注特定领域 ✅ 权限隔离 - 不同 Agent 有不同技能权限 ✅ 模型分离 - 不同任务使用不同模型 ✅ 效率提升 - 并行处理复杂任务


二、基础配置结构

openclaw.json 配置

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "bailian/qwen3.5-plus"
      },
      "models": {
        "bailian/qwen3.5-plus": {},
        "bailian/qwen3-coder-next": {}
      }
    },
    "items": [
      {
        "id": "main",
        "model": {
          "primary": "bailian/qwen3.5-plus"
        },
        "skills": {
          "allow": ["*"]
        },
        "bindings": [
          {
            "channel": "feishu",
            "accountId": "main"
          }
        ]
      },
      {
        "id": "coding-agent",
        "model": {
          "primary": "bailian/qwen3-coder-next"
        },
        "skills": {
          "allow": ["coding-agent", "github"]
        }
      }
    ]
  }
}

配置说明

字段 说明
agents.defaults 默认配置,所有 Agent 共享
agents.items 多个 Agent 的定义数组
id Agent 唯一标识符
model.primary 主模型,可不同
skills.allow 允许的技能列表
bindings 绑定的渠道/账号

三、4 种协作模式

模式一:主从模式(推荐)

架构:

用户 → Main Agent → 子 Agent → Main Agent → 用户

配置示例:

{
  "agents": {
    "items": [
      {
        "id": "main",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["*"]}
      },
      {
        "id": "coding-agent",
        "model": {"primary": "bailian/qwen3-coder-next"},
        "skills": {"allow": ["coding-agent", "github"]}
      },
      {
        "id": "search-agent",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["baidu-search", "searxng"]}
      }
    ]
  }
}

协作流程:

  1. 用户问 Main:"搜索最新 AI 工具并写对比报告"
  2. Main 调用 Search Agent 搜索
  3. Search Agent 返回结果
  4. Main 调用 Coding Agent 写报告
  5. Coding Agent 生成报告
  6. Main 整合回复用户

代码示例:

// Main Agent 派发任务
sessions_spawn(
  agentId="search-agent",
  task="搜索最新 AI 编程工具",
  runtime="subagent"
)

sessions_spawn(
  agentId="coding-agent",
  task="写对比报告",
  runtime="subagent"
)

模式二:任务链模式

架构:

用户 → Agent-1(分析) → Agent-2(执行) → Agent-3(审核) → 回复

配置示例:

{
  "agents": {
    "items": [
      {
        "id": "analyst",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["baidu-search", "analysis"]}
      },
      {
        "id": "writer",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["content-creation", "humanizer"]}
      },
      {
        "id": "reviewer",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["quality-check", "self-improving-agent"]}
      }
    ]
  }
}

实战示例:写公众号文章

1. analyst → 搜索素材
2. writer → 撰写初稿
3. reviewer → 审核润色
4. 回复用户

模式三:渠道分离模式

架构:

飞书用户 → Feishu-Agent
微信用户 → WeChat-Agent
Web 用户 → Web-Agent

配置示例:

{
  "agents": {
    "items": [
      {
        "id": "feishu-agent",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "bindings": [{"channel": "feishu"}]
      },
      {
        "id": "wechat-agent",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "bindings": [{"channel": "wechat"}]
      }
    ]
  }
}

适用场景:

  • 不同渠道有不同用户群体
  • 需要定制化回复风格
  • 渠道间需要隔离

模式四:技能隔离模式

架构:

通用任务 → General-Agent
图片任务 → Image-Agent
编码任务 → Coding-Agent

配置示例:

{
  "agents": {
    "items": [
      {
        "id": "general",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["search", "chat", "summary"]}
      },
      {
        "id": "image-specialist",
        "model": {"primary": "bailian/qwen3.5-plus"},
        "skills": {"allow": ["qwen-image", "diagram-generator"]}
      },
      {
        "id": "coding-specialist",
        "model": {"primary": "bailian/qwen3-coder-next"},
        "skills": {"allow": ["coding-agent", "github"]}
      }
    ]
  }
}

实战示例:生成 AI 编程图片

1. general 收到请求
2. general → sessions_spawn(image-specialist, "生成 AI 编程图片")
3. image-specialist 生成图片
4. general → 回复用户

四、Agent 间通信方式

方式一:sessions_spawn(推荐)

适用场景: 派发独立任务

sessions_spawn(
  agentId="coding-agent",
  task="帮我修复这个 bug",
  runtime="subagent",
  mode="run"
)

特点:

  • 子代理独立运行
  • 完成后自动返回结果
  • 适合耗时任务

方式二:sessions_send

适用场景: 发送消息/查询

sessions_send(
  agentId="reviewer",
  message="请审核这段代码"
)

特点:

  • 即时发送
  • 适合短消息
  • 需要等待回复

方式三:共享记忆

配置:

{
  "memory": {
    "path": "~/.openclaw/workspace/memory"
  }
}

特点:

  • 多个 Agent 共享记忆
  • 适合长期协作
  • 需要配置相同路径

五、实战示例

示例 1:智能客服团队

配置:

{
  "agents": {
    "items": [
      {
        "id": "receptionist",
        "skills": {"allow": ["chat", "faq"]}
      },
      {
        "id": "tech-support",
        "skills": {"allow": ["technical-docs", "troubleshooting"]}
      },
      {
        "id": "manager",
        "skills": {"allow": ["escalation", "reporting"]}
      }
    ]
  }
}

流程:

用户咨询 → receptionist 接待
         ↓ (技术问题)
    tech-support 处理
         ↓ (复杂问题)
    manager 介入

示例 2:内容创作团队

配置:

{
  "agents": {
    "items": [
      {
        "id": "researcher",
        "skills": {"allow": ["baidu-search", "searxng"]}
      },
      {
        "id": "writer",
        "skills": {"allow": ["content-creation", "humanizer"]}
      },
      {
        "id": "editor",
        "skills": {"allow": ["proofreading", "seo-optimization"]}
      }
    ]
  }
}

流程:

主题 → researcher 搜集素材
      ↓
   writer 撰写初稿
      ↓
   editor 审核优化
      ↓
   发布文章

示例 3:DevOps 团队

配置:

{
  "agents": {
    "items": [
      {
        "id": "monitor",
        "skills": {"allow": ["healthcheck", "cron-mastery"]}
      },
      {
        "id": "deployer",
        "skills": {"allow": ["docker-essentials", "git"]}
      },
      {
        "id": "debugger",
        "skills": {"allow": ["coding-agent", "log-analysis"]}
      }
    ]
  }
}

流程:

monitor 发现异常
   ↓
debugger 分析问题
   ↓
deployer 修复部署
   ↓
monitor 验证恢复

六、高级技巧

技巧 1:动态任务分发

// 根据任务类型选择 Agent
function dispatchTask(task) {
  if (task.includes("代码") || task.includes("编程")) {
    return sessions_spawn(agentId="coding-agent", task)
  }
  if (task.includes("图片") || task.includes("生成")) {
    return sessions_spawn(agentId="image-agent", task)
  }
  return sessions_spawn(agentId="main", task)
}

技巧 2:Agent 负载均衡

{
  "agents": {
    "items": [
      {"id": "worker-1", "model": {"primary": "bailian/qwen3.5-plus"}},
      {"id": "worker-2", "model": {"primary": "bailian/qwen3.5-plus"}},
      {"id": "worker-3", "model": {"primary": "bailian/qwen3.5-plus"}}
    ]
  }
}

分发策略:

  • 轮询分发
  • 按负载分发
  • 按专长分发

技巧 3:Agent 自我优化

配置 self-improving-agent 技能:

{
  "agents": {
    "items": [
      {
        "id": "main",
        "skills": {
          "allow": ["self-improving-agent"]
        }
      }
    ]
  }
}

功能:

  • 分析错误日志
  • 提出改进建议
  • 避免重复犯错

七、常见问题

Q1:Agent 配置后不生效?

解决:

# 检查配置语法
openclaw config check

# 重启网关
openclaw gateway restart

# 查看日志
openclaw logs

Q2:Agent 间无法通信?

检查:

  1. Agent ID 是否正确
  2. 是否有权限调用
  3. 网关是否正常运行

Q3:如何查看 Agent 状态?

# 查看活跃 Agent
openclaw agents list

# 查看 Agent 日志
openclaw logs --agent <agent-id>

Q4:技能冲突怎么办?

解决:

{
  "skills": {
    "allow": ["skill1", "skill2"],
    "deny": ["conflict-skill"]
  }
}

八、最佳实践

✅ 推荐做法

  1. 按需创建 - 不要创建过多 Agent
  2. 明确分工 - 每个 Agent 职责清晰
  3. 权限隔离 - 敏感技能单独管理
  4. 日志监控 - 定期检查 Agent 运行状态
  5. 性能优化 - 高频任务用独立 Agent

❌ 避免做法

  1. 技能重复 - 多个 Agent 有相同技能
  2. 权限过大 - 所有 Agent 都有全部权限
  3. 无监控 - 不检查 Agent 运行状态
  4. 过度复杂 - 协作链条过长

九、总结

配置步骤

# 1. 编辑配置文件
nano ~/.openclaw/openclaw.json

# 2. 添加多 Agent 配置
# 参考上文示例

# 3. 验证配置
openclaw config check

# 4. 重启生效
openclaw gateway restart

# 5. 测试协作
# 发送任务测试

协作模式选择

场景 推荐模式
通用 + 专项 主从模式
流水线任务 任务链模式
多渠道 渠道分离
技能隔离 技能隔离模式

核心原则

  1. 专业分工 - 让合适的 Agent 做合适的事
  2. 权限最小 - 只给必要的技能权限
  3. 简单优先 - 能单 Agent 就不多 Agent
  4. 监控到位 - 及时发现和解决问题

官方文档:

  • OpenClaw 配置文档[1]
  • ClawHub 技能市场[2]
  • 多 Agent 示例[3]

最后更新:2026-03-28

引用链接

[1]OpenClaw 配置文档: https://docs.openclaw.ai

[2]ClawHub 技能市场: https://clawhub.ai

[3]多 Agent 示例: https://github.com/openclaw/openclaw