Skip to main content

Routing

Routing determines which agent handles each message based on channel, account, peer, and guild. OpenClaw supports complex routing rules for multi-agent setups, group policies, and access control.

What is Routing?

Routing maps incoming messages to agents and sessions:
  1. Extract identifiers from inbound message (channel, account, peer)
  2. Match routing bindings against message context
  3. Select agent based on match or default
  4. Build session key for agent + routing context
  5. Load/create session and deliver message

Routing Basics

Default Routing

Without routing configuration, all messages go to the default agent:
All messages route to agent:main. Location: src/routing/resolve-route.ts:438

Simple Multi-Agent Routing

Route different channels to different agents:
Now:
  • Telegram messagesmain agent (default)
  • Discord messagescoding agent
Location: src/routing/bindings.ts:1

Routing Bindings

Binding Structure

Routing bindings map message patterns to agents:
Location: src/routing/resolve-route.ts:20

Binding Priority

Bindings are evaluated in order of specificity:
  1. Peer match (specific user/group)
  2. Parent peer match (thread inherits from parent)
  3. Guild + roles (Discord server + member roles)
  4. Guild (Discord server)
  5. Team (Slack workspace)
  6. Account (specific account)
  7. Channel (messaging platform)
  8. Default (fallback)
Location: src/routing/resolve-route.ts:366
More specific bindings take precedence over generic ones.

Routing Examples

Route by Channel

Route by Account

Route by Peer (User/Group)

Route by Guild (Discord)

Route by Roles (Discord)

Members with admin OR moderator role route to admin-agent. Location: src/routing/resolve-route.ts:284

Wildcard Account Routing

Matches all accounts for Telegram. Location: src/routing/resolve-route.ts:408

Routing Flow

Complete Routing Flow

Routing Decision Tree

Location: src/routing/resolve-route.ts:418

Allowlists (Access Control)

Channel Allowlists

Control who can message through each channel:
Allowlist Matching:
  • Wildcard *: Allow everyone
  • User ID: 123456789
  • Username: user:alice or @alice
  • Phone: +15551234567
  • Guild: guild:123456789
Location: src/channels/plugins/allowlist-match.ts:1

Account-Specific Allowlists

Location: src/channels/plugins/account-helpers.ts:1

Nested Allowlists

Channel and account allowlists combine:
Logic:
  1. Check channel allowlist (must include “admin” OR account has wildcard)
  2. Check account allowlist (must match or be wildcard)
Location: src/channels/channel-config.ts:165

Group Policies

Group Policy Types

Policy Options: Default: open Location: src/config/types.base.ts:8

Group Access Control Flow

Location: src/web/inbound/access-control.ts:82

Mention Gating

In group chats, require mentions to respond:
Built-in Mention Detection:
  • Discord: @bot-name
  • Telegram: @bot_username
  • Slack: @bot-name
  • WhatsApp: Quote/reply to bot
Location: src/channels/mention-gating.ts:1, src/channels/plugins/group-mentions.ts:1

Group vs DM Routing

Route DMs and groups to different agents:
Location: src/routing/resolve-route.ts:295

DM-Only Mode

Ignore all group messages:
Location: src/config/types.base.ts:8

Multi-Agent Routing Table

Complex Routing Example

Routing Table: Location: src/routing/resolve-route.ts:295

Routing Testing

Test Routing Rules

Output:
Location: src/commands/routing.ts:1

Debug Routing

Enable verbose routing logs:
Log Output:
Location: src/routing/resolve-route.ts:347

Advanced Routing

Thread Routing

Threads inherit routing from parent:
Threads in channel 987654321 route to support agent. Location: src/routing/resolve-route.ts:356

Session Key Building

Routing builds session keys:
Location: src/routing/resolve-route.ts:90

Identity Resolution

Identity links affect session keys:
Both identities resolve to:
Location: src/routing/session-key.ts:190

Configuration Examples

Personal + Work Split

Multi-Channel Support Setup

Admin + Community Agents

Admins/moderators route to admin agent, others to community.

Troubleshooting

Messages Route to Wrong Agent

Allowlist Not Working

Group Messages Ignored

Routing rules are evaluated in order. More specific rules should appear before generic ones.

Next Steps

Agent Configuration

Configure multiple agents with different models

Session Management

Understand session keys and scoping

Channel Setup

Configure channels and access control

Access Control

Advanced allowlist and pairing configuration