乐于分享
好东西不私藏

OpenClaw 多 Agent 配置指南:轻松实现多机器人协同

OpenClaw 多 Agent 配置指南:轻松实现多机器人协同

在日常工作中,我们经常需要同时处理不同类型的任务:一个是负责日常资讯的助手,一个是开发顾问,另一个是生活管家。每个角色有不同的名字、性格和工作方式。

OpenClaw 的多 Agent 机制就能完美满足这种需求——一台设备上运行多个独立的 AI 助手,各自服务不同的场景。


一、创建 Agent

1.1 基本命令

# 创建新的 Agent
openclaw agents add <agent名称>

# 示例:创建 dailynews agent

openclaw agents add dailynews

# 查看 Agent 列表

openclaw agents list

1.2 输出示例

Agents:
- main (default)
  Identity: 💼✨ 小美
  Workspace: ~/.openclaw/workspace
- dailynews
  Workspace: ~/.openclaw/workspace-dailynews

1.3 每个 Agent 的独立配置

每个 Agent 需要自己的独立工作空间和配置文件:

文件
作用
IDENTITY.md
Agent 身份信息(名字、性格、emoji)
SOUL.md
核心价值观和行为准则
USER.md
人类用户信息
AGENTS.md
行为规范
HEARTBEAT.md
主动模式任务清单
MEMORY.md
长期记忆

二、配置多飞书机器人

2.1 在飞书开放平台创建机器人

  1. 1. 打开 飞书开放平台[1]
  2. 2. 创建企业自建应用
  3. 3. 获取 App ID 和 App Secret
  4. 4. 添加必要权限:
    • • contact:contact.base:readonly - 读取通讯录
    • • im:message:send_as_bot - 发消息
    • • im:message:receive - 收消息
  5. 5. 发布应用

2.2 配置 openclaw.json

{
  "channels"
: {
    "feishu"
: {
      "enabled"
:true,
      "defaultAccount"
: "main",
      "domain"
: "feishu",
      "accounts"
: {
        "main"
: {
          "appId"
: "cli_第一个机器人的appId",
          "appSecret"
: "第一个机器人的secret"
        }
,
        "dailynews"
: {
          "appId"
: "cli_第二个机器人的appId",
          "appSecret"
: "第二个机器人的secret"
        }
,
        "dev"
: {
          "appId"
: "cli_第三个机器人的appId",
          "appSecret"
: "第三个机器人的secret"
        }

      }

    }

  }

}

2.3 验证配置

openclaw channels list

输出示例:

Chat channels:
- Feishu main: configured, enabled
- Feishu dailynews: configured, enabled
- Feishu dev: configured, enabled

三、绑定 Agent 到 Channel

3.1 使用命令绑定

# 绑定 agent 到指定飞书账号
openclaw agents bind --agent <agentId> --bind feishu:<accountId>

# 示例

openclaw agents bind --agent main --bind feishu:main
openclaw agents bind --agent dailynews --bind feishu:dailynews

3.2 或在配置文件中添加 bindings

{
  "bindings"
: [
    {

      "agentId"
: "main",
      "match"
: {
        "channel"
: "feishu",
        "accountId"
: "main"
      }

    }
,
    {

      "agentId"
: "dailynews",
      "match"
: {
        "channel"
: "feishu",
        "accountId"
: "dailynews"
      }

    }

  ]

}

3.3 查看绑定结果

openclaw agents bindings

四、配置用户白名单(推荐)

使用白名单机制可以更安全地控制机器人访问权限:

4.1 创建白名单文件

vim ~/.openclaw/credentials/feishu-allowFrom.json

内容:

{
  "version"
: 1,
  "allowFrom"
: [
    "ou_用户的open_id_1"
,
    "ou_用户的open_id_2"

  ]

}

4.2 获取用户 open_id

在飞书开放平台的 API 工具中获取:

  • • 打开 https://open.feishu.cn/document/server-docs/contact-v3/user/get
  • • 选择用户后点击"尝试"
  • • 返回结果中会显示用户的 open_id

或者在飞书中:

  • • 打开用户主页 → 点击分享 → 复制链接,链接中包含用户ID

注意:使用 allowFrom 白名单后,不需要执行 openclaw pairing approve,更安全方便。


五、重启并验证

# 重启 Gateway
openclaw gateway restart

然后用不同的飞书机器人发送消息,检查是否路由到对应的 Agent。


六、使用多 Agent 的好处

6.1 场景隔离

每个 Agent 可以服务不同的场景:

  • • main:日常对话和综合助手
  • • dailynews:定时推送新闻资讯
  • • dev:开发问题解答

6.2 个性化配置

每个 Agent 可以有不同的:

  • • 性格和行为方式
  • • 专业领域知识
  • • 工作时间安排

6.3 资源节约

相比运行多个独立的 AI 应用,多 Agent 共享:

  • • 同一个 Gateway 服务
  • • 同一个模型 API(可配置不同模型)
  • • 同一台设备资源

6.4 统一管理

通过单一配置文件管理所有机器人和 Agent 绑定关系,维护成本低。


七、完整配置示例

{
  "agents"
: {
    "list"
: [
      {

        "id"
: "main",
        "default"
:true,
        "name"
: "小美",
        "workspace"
: "/home/username/.openclaw/workspace"
      }
,
      {

        "id"
: "dailynews",
        "name"
: "dailynews",
        "workspace"
: "/home/username/.openclaw/workspace-dailynews"
      }

    ]

  }
,
  "channels"
: {
    "feishu"
: {
      "enabled"
:true,
      "defaultAccount"
: "main",
      "domain"
: "feishu",
      "accounts"
: {
        "main"
: {
          "appId"
: "cli_xxx1",
          "appSecret"
: "secret1"
        }
,
        "dailynews"
: {
          "appId"
: "cli_xxx2",
          "appSecret"
: "secret2"
        }

      }

    }

  }
,
  "bindings"
: [
    {

      "agentId"
: "main",
      "match"
: {
        "channel"
: "feishu",
        "accountId"
: "main"
      }

    }
,
    {

      "agentId"
: "dailynews",
      "match"
: {
        "channel"
: "feishu",
        "accountId"
: "dailynews"
      }

    }

  ]

}

常见问题

Q: 提示 "access not configured"

确认 channels.feishu.accounts 中是否配置了对应账号

Q: 提示权限错误

需要在飞书开放平台授权相应权限

Q: 绑定后不生效

执行 openclaw gateway restart 重启 Gateway


以上就是 OpenClaw 多 Agent 的完整配置指南。通过这种机制,你可以在一台设备上运行多个各具特色的 AI 助手,分别处理不同类型的任务,既高效又灵活。快试试吧!

引用链接

[1] 飞书开放平台: https://open.feishu.cn/