概述

多 Agent 路由允许在单个 Gateway 进程中运行多个相互隔离的 Agent,每个 Agent 拥有独立的工作区、状态目录(agentDir)和会话历史。通过 binding 规则将入站消息路由到对应的 Agent。

核心要点

  • Agent 隔离:每个 Agent 有独立的 workspace、auth profiles、session store,路径为 ~/.openclaw/agents/<agentId>/
  • Binding 路由:将 channel account(如某个 WhatsApp 号码)绑定到指定 Agent,路由规则按特异性优先(most-specific wins)
  • 路由优先级:peer 精确匹配 > parentPeer > guildId+roles > guildId > teamId > accountId > channel 级别 > 默认 Agent
  • 多账号支持:同一 channel 可配置多个 accountId,每个账号路由到不同 Agent
  • 跨 Agent 内存搜索:通过 memorySearch.qmd.extraCollections 配置跨 Agent 的 QMD 会话搜索
  • 单 Agent 模式:默认 agentId 为 main,无需额外配置

配置/使用

快速添加新 Agent:

openclaw agents add work
openclaw agents list --bindings

典型配置结构(openclaw.json):

{
  agents: {
    list: [
      { id: "home", workspace: "~/.openclaw/workspace-home" },
      { id: "work", workspace: "~/.openclaw/workspace-work" }
    ]
  },
  bindings: [
    { agentId: "home", match: { channel: "whatsapp", accountId: "personal" } },
    { agentId: "work", match: { channel: "whatsapp", accountId: "biz" } }
  ]
}

关键注意事项:

  • 不同 Agent 的 agentDir 不能复用,否则会导致 auth/session 冲突
  • 每个 Agent 可配置独立的 sandbox 和 tool 限制
  • tools.elevated 是全局的,不支持 per-agent 配置

相关页面