2026-01-06 18:25:52 +00:00
---
2026-01-13 07:15:57 +00:00
summary: "Multi-agent routing: isolated agents, channel accounts, and bindings"
2026-01-06 18:25:52 +00:00
title: Multi-Agent Routing
read_when: "You want multiple isolated agents (workspaces + auth) in one gateway process."
status: active
---
# Multi-Agent Routing
2026-01-31 21:13:13 +09:00
Goal: multiple _isolated_ agents (separate workspace + `agentDir` + sessions), plus multiple channel accounts (e.g. two WhatsApps) in one running Gateway. Inbound is routed to an agent via bindings.
2026-01-06 18:25:52 +00:00
2026-01-06 22:44:07 +01:00
## What is “one agent”?
An **agent** is a fully scoped brain with its own:
- **Workspace** (files, AGENTS.md/SOUL.md/USER.md, local notes, persona rules).
- **State directory** (`agentDir` ) for auth profiles, model registry, and per-agent config.
2026-01-30 03:15:10 +01:00
- **Session store** (chat history + routing state) under `~/.openclaw/agents/<agentId>/sessions` .
2026-01-06 22:44:07 +01:00
2026-01-15 04:41:38 +00:00
Auth profiles are **per-agent** . Each agent reads from its own:
2026-02-17 14:27:52 -06:00
```text
2026-01-30 03:15:10 +01:00
~/.openclaw/agents/< agentId > /agent/auth-profiles.json
2026-01-15 04:41:38 +00:00
```
Main agent credentials are **not** shared automatically. Never reuse `agentDir`
across agents (it causes auth/session collisions). If you want to share creds,
copy `auth-profiles.json` into the other agent's `agentDir` .
2026-01-09 01:37:19 +01:00
Skills are per-agent via each workspace’ s `skills/` folder, with shared skills
2026-01-30 03:15:10 +01:00
available from `~/.openclaw/skills` . See [Skills: per-agent vs shared ](/tools/skills#per-agent-vs-shared-skills ).
2026-01-09 01:37:19 +01:00
2026-01-06 22:44:07 +01:00
The Gateway can host **one agent** (default) or **many agents** side-by-side.
2026-01-09 01:54:28 +01:00
**Workspace note:** each agent’ s workspace is the **default cwd** , not a hard
sandbox. Relative paths resolve inside the workspace, but absolute paths can
reach other host locations unless sandboxing is enabled. See
[Sandboxing ](/gateway/sandboxing ).
2026-01-08 07:49:07 +01:00
## Paths (quick map)
2026-01-30 03:15:10 +01:00
- Config: `~/.openclaw/openclaw.json` (or `OPENCLAW_CONFIG_PATH` )
- State dir: `~/.openclaw` (or `OPENCLAW_STATE_DIR` )
- Workspace: `~/.openclaw/workspace` (or `~/.openclaw/workspace-<agentId>` )
- Agent dir: `~/.openclaw/agents/<agentId>/agent` (or `agents.list[].agentDir` )
- Sessions: `~/.openclaw/agents/<agentId>/sessions`
2026-01-08 07:49:07 +01:00
2026-01-06 22:44:07 +01:00
### Single-agent mode (default)
2026-01-30 03:15:10 +01:00
If you do nothing, OpenClaw runs a single agent:
2026-01-06 22:44:07 +01:00
- `agentId` defaults to ** `main` **.
- Sessions are keyed as `agent:main:<mainKey>` .
2026-01-30 03:15:10 +01:00
- Workspace defaults to `~/.openclaw/workspace` (or `~/.openclaw/workspace-<profile>` when `OPENCLAW_PROFILE` is set).
- State defaults to `~/.openclaw/agents/main/agent` .
2026-01-06 22:44:07 +01:00
2026-01-07 09:58:54 +01:00
## Agent helper
Use the agent wizard to add a new isolated agent:
```bash
2026-01-30 03:15:10 +01:00
openclaw agents add work
2026-01-07 09:58:54 +01:00
```
2026-01-09 12:44:23 +00:00
Then add `bindings` (or let the wizard do it) to route inbound messages.
2026-01-07 09:58:54 +01:00
2026-01-08 07:49:07 +01:00
Verify with:
```bash
2026-01-30 03:15:10 +01:00
openclaw agents list --bindings
2026-01-08 07:49:07 +01:00
```
2026-02-17 14:27:52 -06:00
## Quick start
< Steps >
< Step title = "Create each agent workspace" >
Use the wizard or create workspaces manually:
```bash
openclaw agents add coding
openclaw agents add social
```
Each agent gets its own workspace with `SOUL.md` , `AGENTS.md` , and optional `USER.md` , plus a dedicated `agentDir` and session store under `~/.openclaw/agents/<agentId>` .
< / Step >
< Step title = "Create channel accounts" >
Create one account per agent on your preferred channels:
- Discord: one bot per agent, enable Message Content Intent, copy each token.
- Telegram: one bot per agent via BotFather, copy each token.
- WhatsApp: link each phone number per account.
```bash
openclaw channels login --channel whatsapp --account work
```
See channel guides: [Discord ](/channels/discord ), [Telegram ](/channels/telegram ), [WhatsApp ](/channels/whatsapp ).
< / Step >
< Step title = "Add agents, accounts, and bindings" >
Add agents under `agents.list` , channel accounts under `channels.<channel>.accounts` , and connect them with `bindings` (examples below).
< / Step >
< Step title = "Restart and verify" >
```bash
openclaw gateway restart
openclaw agents list --bindings
openclaw channels status --probe
```
< / Step >
< / Steps >
2026-01-06 22:44:07 +01:00
## Multiple agents = multiple people, multiple personalities
With **multiple agents** , each `agentId` becomes a **fully isolated persona** :
2026-01-13 07:15:57 +00:00
- **Different phone numbers/accounts** (per channel `accountId` ).
2026-01-06 22:44:07 +01:00
- **Different personalities** (per-agent workspace files like `AGENTS.md` and `SOUL.md` ).
- **Separate auth + sessions** (no cross-talk unless explicitly enabled).
This lets **multiple people** share one Gateway server while keeping their AI “brains” and data isolated.
2026-01-12 01:25:53 +00:00
## One WhatsApp number, multiple people (DM split)
2026-02-08 16:20:52 -08:00
You can route **different WhatsApp DMs** to different agents while staying on **one WhatsApp account** . Match on sender E.164 (like `+15551234567` ) with `peer.kind: "direct"` . Replies still come from the same WhatsApp number (no per‑ agent sender identity).
2026-01-12 01:25:53 +00:00
Important detail: direct chats collapse to the agent’ s **main session key** , so true isolation requires **one agent per person** .
Example:
```json5
{
agents: {
list: [
2026-01-30 03:15:10 +01:00
{ id: "alex", workspace: "~/.openclaw/workspace-alex" },
2026-01-31 21:13:13 +09:00
{ id: "mia", workspace: "~/.openclaw/workspace-mia" },
],
2026-01-12 01:25:53 +00:00
},
bindings: [
2026-02-08 16:20:52 -08:00
{
agentId: "alex",
match: { channel: "whatsapp", peer: { kind: "direct", id: "+15551230001" } },
},
{
agentId: "mia",
match: { channel: "whatsapp", peer: { kind: "direct", id: "+15551230002" } },
},
2026-01-12 01:25:53 +00:00
],
2026-01-13 06:16:43 +00:00
channels: {
whatsapp: {
dmPolicy: "allowlist",
2026-01-31 21:13:13 +09:00
allowFrom: ["+15551230001", "+15551230002"],
},
},
2026-01-12 01:25:53 +00:00
}
```
Notes:
2026-01-31 21:13:13 +09:00
2026-01-12 01:25:53 +00:00
- DM access control is **global per WhatsApp account** (pairing/allowlist), not per agent.
2026-02-07 15:40:35 -05:00
- For shared groups, bind the group to one agent or use [Broadcast groups ](/channels/broadcast-groups ).
2026-01-12 01:25:53 +00:00
2026-01-06 22:44:07 +01:00
## Routing rules (how messages pick an agent)
Bindings are **deterministic** and **most-specific wins** :
1. `peer` match (exact DM/group/channel id)
2026-02-14 10:05:09 +08:00
2. `parentPeer` match (thread inheritance)
3. `guildId + roles` (Discord role routing)
4. `guildId` (Discord)
5. `teamId` (Slack)
6. `accountId` match for a channel
7. channel-level match (`accountId: "*"` )
8. fallback to default agent (`agents.list[].default` , else first list entry, default: `main` )
2026-02-17 14:27:52 -06:00
If multiple bindings match in the same tier, the first one in config order wins.
2026-02-14 10:05:09 +08:00
If a binding sets multiple match fields (for example `peer` + `guildId` ), all specified fields are required (`AND` semantics).
2026-01-06 22:44:07 +01:00
## Multiple accounts / phone numbers
2026-01-13 07:15:57 +00:00
Channels that support **multiple accounts** (e.g. WhatsApp) use `accountId` to identify
2026-01-06 22:44:07 +01:00
each login. Each `accountId` can be routed to a different agent, so one server can host
multiple phone numbers without mixing sessions.
2026-01-06 18:25:52 +00:00
## Concepts
- `agentId` : one “brain” (workspace, per-agent auth, per-agent session store).
2026-01-13 07:15:57 +00:00
- `accountId` : one channel account instance (e.g. WhatsApp account `"personal"` vs `"biz"` ).
- `binding` : routes inbound messages to an `agentId` by `(channel, accountId, peer)` and optionally guild/team ids.
2026-01-06 18:25:52 +00:00
- Direct chats collapse to `agent:<agentId>:<mainKey>` (per-agent “main”; `session.mainKey` ).
2026-02-17 14:27:52 -06:00
## Platform examples
### Discord bots per agent
Each Discord bot account maps to a unique `accountId` . Bind each account to an agent and keep allowlists per bot.
```json5
{
agents: {
list: [
{ id: "main", workspace: "~/.openclaw/workspace-main" },
{ id: "coding", workspace: "~/.openclaw/workspace-coding" },
],
},
bindings: [
{ agentId: "main", match: { channel: "discord", accountId: "default" } },
{ agentId: "coding", match: { channel: "discord", accountId: "coding" } },
],
channels: {
discord: {
groupPolicy: "allowlist",
accounts: {
default: {
token: "DISCORD_BOT_TOKEN_MAIN",
guilds: {
"123456789012345678": {
channels: {
"222222222222222222": { allow: true, requireMention: false },
},
},
},
},
coding: {
token: "DISCORD_BOT_TOKEN_CODING",
guilds: {
"123456789012345678": {
channels: {
"333333333333333333": { allow: true, requireMention: false },
},
},
},
},
},
},
},
}
```
Notes:
- Invite each bot to the guild and enable Message Content Intent.
- Tokens live in `channels.discord.accounts.<id>.token` (default account can use `DISCORD_BOT_TOKEN` ).
### Telegram bots per agent
```json5
{
agents: {
list: [
{ id: "main", workspace: "~/.openclaw/workspace-main" },
{ id: "alerts", workspace: "~/.openclaw/workspace-alerts" },
],
},
bindings: [
{ agentId: "main", match: { channel: "telegram", accountId: "default" } },
{ agentId: "alerts", match: { channel: "telegram", accountId: "alerts" } },
],
channels: {
telegram: {
accounts: {
default: {
botToken: "123456:ABC...",
dmPolicy: "pairing",
},
alerts: {
botToken: "987654:XYZ...",
dmPolicy: "allowlist",
allowFrom: ["tg:123456789"],
},
},
},
},
}
```
Notes:
- Create one bot per agent with BotFather and copy each token.
- Tokens live in `channels.telegram.accounts.<id>.botToken` (default account can use `TELEGRAM_BOT_TOKEN` ).
### WhatsApp numbers per agent
Link each account before starting the gateway:
```bash
openclaw channels login --channel whatsapp --account personal
openclaw channels login --channel whatsapp --account biz
```
2026-01-06 18:25:52 +00:00
2026-01-30 03:15:10 +01:00
`~/.openclaw/openclaw.json` (JSON5):
2026-01-06 18:25:52 +00:00
```js
{
2026-01-09 12:44:23 +00:00
agents: {
list: [
{
id: "home",
default: true,
2026-01-07 09:58:54 +01:00
name: "Home",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-home",
agentDir: "~/.openclaw/agents/home/agent",
2026-01-06 18:25:52 +00:00
},
2026-01-09 12:44:23 +00:00
{
id: "work",
2026-01-07 09:58:54 +01:00
name: "Work",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-work",
agentDir: "~/.openclaw/agents/work/agent",
2026-01-06 18:25:52 +00:00
},
2026-01-09 12:44:23 +00:00
],
},
2026-01-06 18:25:52 +00:00
2026-01-09 12:44:23 +00:00
// Deterministic routing: first match wins (most-specific first).
bindings: [
2026-01-13 07:15:57 +00:00
{ agentId: "home", match: { channel: "whatsapp", accountId: "personal" } },
{ agentId: "work", match: { channel: "whatsapp", accountId: "biz" } },
2026-01-09 12:44:23 +00:00
// Optional per-peer override (example: send a specific group to work agent).
{
agentId: "work",
match: {
2026-01-13 07:15:57 +00:00
channel: "whatsapp",
2026-01-09 12:44:23 +00:00
accountId: "personal",
peer: { kind: "group", id: "1203630...@g .us" },
2026-01-06 18:25:52 +00:00
},
2026-01-09 12:44:23 +00:00
},
],
2026-01-06 18:25:52 +00:00
2026-01-09 12:44:23 +00:00
// Off by default: agent-to-agent messaging must be explicitly enabled + allowlisted.
tools: {
2026-01-06 18:25:52 +00:00
agentToAgent: {
enabled: false,
allow: ["home", "work"],
},
},
2026-01-13 06:16:43 +00:00
channels: {
whatsapp: {
accounts: {
personal: {
2026-01-30 03:15:10 +01:00
// Optional override. Default: ~/.openclaw/credentials/whatsapp/personal
// authDir: "~/.openclaw/credentials/whatsapp/personal",
2026-01-13 06:16:43 +00:00
},
biz: {
2026-01-30 03:15:10 +01:00
// Optional override. Default: ~/.openclaw/credentials/whatsapp/biz
// authDir: "~/.openclaw/credentials/whatsapp/biz",
2026-01-13 06:16:43 +00:00
},
2026-01-06 18:25:52 +00:00
},
},
},
}
```
2026-01-07 11:59:04 +01:00
2026-01-12 05:59:32 +00:00
## Example: WhatsApp daily chat + Telegram deep work
2026-01-13 07:15:57 +00:00
Split by channel: route WhatsApp to a fast everyday agent and Telegram to an Opus agent.
2026-01-12 05:59:32 +00:00
```json5
{
agents: {
list: [
{
id: "chat",
name: "Everyday",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-chat",
2026-01-31 21:13:13 +09:00
model: "anthropic/claude-sonnet-4-5",
2026-01-12 05:59:32 +00:00
},
{
id: "opus",
name: "Deep Work",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-opus",
2026-02-05 16:54:44 -05:00
model: "anthropic/claude-opus-4-6",
2026-01-31 21:13:13 +09:00
},
],
2026-01-12 05:59:32 +00:00
},
bindings: [
2026-01-13 07:15:57 +00:00
{ agentId: "chat", match: { channel: "whatsapp" } },
2026-01-31 21:13:13 +09:00
{ agentId: "opus", match: { channel: "telegram" } },
],
2026-01-12 05:59:32 +00:00
}
```
Notes:
2026-01-31 21:13:13 +09:00
2026-01-13 07:15:57 +00:00
- If you have multiple accounts for a channel, add `accountId` to the binding (for example `{ channel: "whatsapp", accountId: "personal" }` ).
- To route a single DM/group to Opus while keeping the rest on chat, add a `match.peer` binding for that peer; peer matches always win over channel-wide rules.
2026-01-12 05:59:32 +00:00
2026-01-13 07:15:57 +00:00
## Example: same channel, one peer to Opus
2026-01-12 06:00:00 +00:00
Keep WhatsApp on the fast agent, but route one DM to Opus:
```json5
{
agents: {
list: [
2026-01-31 21:13:13 +09:00
{
id: "chat",
name: "Everyday",
workspace: "~/.openclaw/workspace-chat",
model: "anthropic/claude-sonnet-4-5",
},
{
id: "opus",
name: "Deep Work",
workspace: "~/.openclaw/workspace-opus",
2026-02-05 16:54:44 -05:00
model: "anthropic/claude-opus-4-6",
2026-01-31 21:13:13 +09:00
},
],
2026-01-12 06:00:00 +00:00
},
bindings: [
2026-02-08 16:20:52 -08:00
{
agentId: "opus",
match: { channel: "whatsapp", peer: { kind: "direct", id: "+15551234567" } },
},
2026-01-31 21:13:13 +09:00
{ agentId: "chat", match: { channel: "whatsapp" } },
],
2026-01-12 06:00:00 +00:00
}
```
2026-01-13 07:15:57 +00:00
Peer bindings always win, so keep them above the channel-wide rule.
2026-01-12 06:00:00 +00:00
2026-01-20 15:00:11 +00:00
## Family agent bound to a WhatsApp group
Bind a dedicated family agent to a single WhatsApp group, with mention gating
and a tighter tool policy:
```json5
{
agents: {
list: [
{
id: "family",
name: "Family",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-family",
2026-01-20 15:00:11 +00:00
identity: { name: "Family Bot" },
groupChat: {
2026-01-31 21:13:13 +09:00
mentionPatterns: ["@family ", "@familybot ", "@Family Bot"],
2026-01-20 15:00:11 +00:00
},
sandbox: {
mode: "all",
2026-01-31 21:13:13 +09:00
scope: "agent",
2026-01-20 15:00:11 +00:00
},
tools: {
2026-01-31 21:13:13 +09:00
allow: [
"exec",
"read",
"sessions_list",
"sessions_history",
"sessions_send",
"sessions_spawn",
"session_status",
],
deny: ["write", "edit", "apply_patch", "browser", "canvas", "nodes", "cron"],
},
},
],
2026-01-20 15:00:11 +00:00
},
bindings: [
{
agentId: "family",
match: {
channel: "whatsapp",
2026-01-31 21:13:13 +09:00
peer: { kind: "group", id: "120363999999999999@g .us" },
},
},
],
2026-01-20 15:00:11 +00:00
}
```
Notes:
2026-01-31 21:13:13 +09:00
2026-01-20 15:00:11 +00:00
- Tool allow/deny lists are **tools** , not skills. If a skill needs to run a
binary, ensure `exec` is allowed and the binary exists in the sandbox.
- For stricter gating, set `agents.list[].groupChat.mentionPatterns` and keep
group allowlists enabled for the channel.
2026-01-07 11:59:04 +01:00
## Per-Agent Sandbox and Tool Configuration
Starting with v2026.1.6, each agent can have its own sandbox and tool restrictions:
```js
{
2026-01-09 12:44:23 +00:00
agents: {
list: [
{
id: "personal",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-personal",
2026-01-07 11:59:04 +01:00
sandbox: {
mode: "off", // No sandbox for personal agent
},
// No tool restrictions - all tools available
},
2026-01-09 12:44:23 +00:00
{
id: "family",
2026-01-30 03:15:10 +01:00
workspace: "~/.openclaw/workspace-family",
2026-01-07 11:59:04 +01:00
sandbox: {
mode: "all", // Always sandboxed
scope: "agent", // One container per agent
2026-01-08 00:52:15 +01:00
docker: {
// Optional one-time setup after container creation
setupCommand: "apt-get update & & apt-get install -y git curl",
},
2026-01-07 11:59:04 +01:00
},
tools: {
allow: ["read"], // Only read tool
2026-01-12 03:42:49 +00:00
deny: ["exec", "write", "edit", "apply_patch"], // Deny others
2026-01-07 11:59:04 +01:00
},
},
2026-01-09 12:44:23 +00:00
],
2026-01-07 11:59:04 +01:00
},
}
```
2026-01-19 01:35:17 +00:00
Note: `setupCommand` lives under `sandbox.docker` and runs once on container creation.
Per-agent `sandbox.docker.*` overrides are ignored when the resolved scope is `"shared"` .
2026-01-07 11:59:04 +01:00
**Benefits:**
2026-01-31 21:13:13 +09:00
2026-01-07 11:59:04 +01:00
- **Security isolation**: Restrict tools for untrusted agents
- **Resource control**: Sandbox specific agents while keeping others on host
- **Flexible policies**: Different permissions per agent
2026-01-09 12:44:23 +00:00
Note: `tools.elevated` is **global** and sender-based; it is not configurable per agent.
2026-01-12 02:49:55 +00:00
If you need per-agent boundaries, use `agents.list[].tools` to deny `exec` .
2026-01-09 12:44:23 +00:00
For group targeting, use `agents.list[].groupChat.mentionPatterns` so @mentions map cleanly to the intended agent.
2026-01-08 22:57:08 +01:00
2026-02-07 15:40:35 -05:00
See [Multi-Agent Sandbox & Tools ](/tools/multi-agent-sandbox-tools ) for detailed examples.