Multi-Agent Routing 指南:在一台 Gateway 上運行多個 AI 身分
你有沒有遇過這種情況?你想在同一個伺服器跑兩個機器人,結果對話紀錄全混在一起,或者你想讓 WhatsApp 的私訊跟群組由不同的 AI 來處理,但設定起來卻像地獄一樣複雜。當你需要同時管理多個身分、多組帳號,還要確保隱私跟權限完全隔離時,手動切換設定檔絕對不是好辦法。
這篇指南會教你如何使用 Multi-Agent Routing 功能,讓你的 Gateway 變成一個強大的調度中心,精準地把訊息送到正確的 AI「大腦」手中。
需要準備的東西
Section titled “需要準備的東西”- 已安裝並運行的 OpenClaw Gateway
- 對
~/.openclaw/openclaw.json的編輯權限 - 至少一個已配置的 Channel(例如 WhatsApp 或 Telegram)
只要 5 分鐘,你就能建立一個全新的隔離 Agent 並查看路由狀況。
-
新增 Agent: 使用內建小幫手建立一個名為
work的獨立 Agent:Terminal window openclaw agents add work -
檢查路由: 確認目前的 Agent 列表與訊息綁定(bindings)狀況:
Terminal window openclaw agents list --bindings
核心概念:什麼是「一個 Agent」?
Section titled “核心概念:什麼是「一個 Agent」?”在 OpenClaw 中,一個 agent 就是一個完整且獨立的運作單元,它擁有自己的:
- Workspace: 存放檔案、
AGENTS.md、SOUL.md、USER.md、本地筆記與人格規則。 - State directory (
agentDir): 存放 auth profiles、model registry 以及每個 agent 的獨立設定。 - Session store: 存放對話紀錄與路由狀態,路徑在
~/.openclaw/agents/<agentId>/sessions。 - Skills: 透過 workspace 下的
skills/資料夾管理專屬技能。
重要提醒:Auth profiles 是 per-agent 的。每個 agent 會讀取自己的 ~/.openclaw/agents/<agentId>/agent/auth-profiles.json。絕對不要在多個 agent 之間共用同一個 agentDir,這會導致驗證與 session 發生衝突。
路由規則:訊息如何找到正確的 Agent?
Section titled “路由規則:訊息如何找到正確的 Agent?”當訊息進來時,Gateway 會根據 bindings 進行**確定性(deterministic)**比對,越具體的規則優先權越高:
peer匹配(精確的私訊/群組/頻道 ID)guildId(Discord)teamId(Slack)accountId匹配特定頻道帳號- 頻道層級匹配 (
accountId: "*") - 回退至預設 agent(
agents.list[].default,若未設定則為列表第一個,預設值為main)
1. 兩個 WhatsApp 帳號對應兩個 Agent
Section titled “1. 兩個 WhatsApp 帳號對應兩個 Agent”如果你有兩個 WhatsApp 號碼(例如個人用與商務用),可以這樣設定:
{ agents: { list: [ { id: "home", default: true, workspace: "~/.openclaw/workspace-home", agentDir: "~/.openclaw/agents/home/agent", }, { id: "work", workspace: "~/.openclaw/workspace-work", agentDir: "~/.openclaw/agents/work/agent", }, ], }, bindings: [ { agentId: "home", match: { channel: "whatsapp", accountId: "personal" } }, { agentId: "work", match: { channel: "whatsapp", accountId: "biz" } }, ], channels: { whatsapp: { accounts: { personal: {}, biz: {}, }, }, },}2. 同一帳號,特定好友轉交給高階模型
Section titled “2. 同一帳號,特定好友轉交給高階模型”你可以讓 WhatsApp 大部分對話由快速的模型處理,但特定好友的私訊路由給跑 Opus 模型的 Agent:
{ agents: { list: [ { id: "chat", model: "anthropic/claude-sonnet-4-5", }, { id: "opus", model: "anthropic/claude-opus-4-6", }, ], }, bindings: [ { agentId: "opus", match: { channel: "whatsapp", peer: { kind: "direct", id: "+15551234567" } }, }, { agentId: "chat", match: { channel: "whatsapp" } }, ],}Per-Agent Sandbox 與工具配置
Section titled “Per-Agent Sandbox 與工具配置”從 v2026.1.6 版本開始,你可以為每個 Agent 設定獨立的 Sandbox 與工具權限。這對於處理不信任的來源或群組非常有用。
{ agents: { list: [ { id: "family", workspace: "~/.openclaw/workspace-family", sandbox: { mode: "all", // 開啟 Sandbox scope: "agent", // 每個 Agent 獨立容器 docker: { setupCommand: "apt-get update && apt-get install -y git curl", }, }, tools: { allow: ["read"], // 僅允許讀取工具 deny: ["exec", "write", "edit", "apply_patch"], // 禁用危險工具 }, }, ], },}- Session 內容混亂:檢查你是否在多個 Agent 中指定了相同的
agentDir。每個 Agent 必須擁有路徑中包含其agentId的獨立目錄。 - 訊息沒有反應:使用
openclaw agents list --bindings檢查你的match規則。請記住,peer匹配的優先權高於channel匹配。 - 權限錯誤:如果你在 Sandbox 模式下執行,確保
setupCommand已正確安裝該技能所需的二進位檔案。
如果你在設定過程中遇到任何困難,隨時詢問 AI Setup Assistant 來獲取即時幫助。
- Skills: per-agent vs shared - 了解如何管理不同 Agent 的技能
- Sandboxing - 深入研究容器化隔離技術
- Broadcast groups - 學習如何在多個頻道間同步訊息
- Multi-Agent Sandbox & Tools - 更多關於工具限制的進階範例
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。