OpenClaw

OpenClaw Multi-Agent Routing👨‍💻

When running multiple agents in a single OpenClaw gateway, the routing system decides which agent handles each incoming message. Agent bindings define these rules through an eight-tier priority hierarchy evaluated from most specific (peer) to least specific (default). This lets you build sophisticated routing topologies -- a triage agent that classifies and forwards, role-based routing within a Discord server, or region-specific agents bound to different WhatsApp numbers.

Key Takeaways

  • 1The routing hierarchy has eight tiers, evaluated in order: peer > parent peer > guild+roles > guild > team > account > channel > default. The first match wins, and lower tiers are not evaluated.
  • 2Agent bindings map message context (channel, account, guild, role) to a specific agent. Each binding has a type that determines its priority tier. The first-match-in-tier rule resolves conflicts within the same tier.
  • 3Every multi-agent gateway should have at least one default binding. Without it, messages that do not match any specific binding are silently dropped with no error.
  • 4Workspaces provide logical isolation in multi-tenant setups. Each workspace has its own channels, agents, and sessions. Data never leaks between workspaces within the same Gateway process.
  • 5The triage pattern uses a lightweight agent to classify incoming messages and route them to specialist agents. The triage agent uses a fast, cheap model (GPT-4o-mini) while specialists use more powerful models (Claude Sonnet).
  • 6Each agent has a fully isolated workspace at `~/.openclaw/agents/<agentId>/`. Workspace isolation means agents never share memory, sessions, or bootstrap files unless explicitly configured to do so.

Master openclaw multi-agent routing

Take the OpenClaw for Production & Advanced Use course with hands-on lessons and challenges.

Examples

Binding types and priority hierarchy

json

Three agents with different binding types. A message from a developer in the Discord engineering server matches the guild+roles binding (tier 3), routing to code-reviewer. A message from the WhatsApp support line matches the account binding (tier 6), routing to support-bot. Everything else falls through to the default binding (tier 8).

Triage agent pattern for customer support

json

The triage agent receives all messages (default binding) and uses a cheap, fast model for classification. It routes billing questions to the billing specialist and technical issues to the technical specialist. Specialists use more powerful models with domain-specific tools. This pattern is cost-effective and produces better responses than a single generic agent.

Workspace isolation for multi-tenant deployments

json

Team Alpha uses Discord with the coder agent. Team Beta uses Slack with the support agent. Workspaces ensure that Team Alpha's messages, sessions, and agent memory are completely isolated from Team Beta's. Both operate within the same Gateway process but cannot see each other's data.

Routing priority evaluation order

bash

The eight tiers are evaluated top-to-bottom. Peer bindings are the most specific because they represent direct agent-to-agent communication. Default is the catch-all. If a message matches a guild+roles binding at tier 3, account and channel bindings at tiers 6-7 are never checked.

Conditional routing rules

json

Routing rules are evaluated top-to-bottom with first-match-wins semantics. Discord admins get the admin-bot, other Discord users get the general-bot, and WhatsApp users get the support-bot. Order matters: if the two Discord rules were swapped, admins would match the general rule first and never reach the admin-specific rule.

Common Mistakes

Mistake:

Forgetting to define a default binding, causing messages that do not match any specific binding to be silently dropped

Fix:

Always define at least one agent with a default binding. This acts as a catch-all and ensures no message goes unanswered. Even a simple 'I can't help with that, try asking a specific agent' is better than silence.

Mistake:

Creating overlapping bindings at the same tier without realizing that the first-defined binding wins silently

Fix:

Audit your bindings for overlaps within the same tier. If two agents bind to the same guild without roles, the first one wins and the second is silently ignored. Use roles or more specific binding types to differentiate.

Mistake:

Assuming agents share memory or sessions in a multi-agent setup when they are actually fully isolated

Fix:

Each agent has its own workspace, memory, and sessions. If you need shared knowledge between agents, set up explicit shared paths or use a shared knowledge base tool.

Mistake:

Using a powerful expensive model for the triage agent when it only needs to classify message intent

Fix:

The triage agent does simple classification -- it does not need Claude Sonnet. Use GPT-4o-mini or a similar lightweight model for triage. Reserve powerful models for specialist agents that do the real work.

Best Practices

  • Use the triage pattern for any customer-facing deployment. A lightweight classifier agent routing to specialists is more cost-effective and produces better responses than a single generic agent.
  • Document your routing topology in a diagram or table. As the number of agents and bindings grows, visual documentation prevents routing mistakes and makes onboarding new team members easier.
  • Use the most specific binding type possible. Prefer guild+roles over guild-only, account over channel. More specific bindings reduce ambiguity and unintended routing.
  • Test routing by sending messages from each channel/role combination and verifying which agent responds. Use `openclaw logs` to trace routing decisions.
  • Start with a single workspace and only introduce workspace isolation when you need tenant separation. Premature partitioning adds configuration complexity.
  • Name agents descriptively and consistently: 'support-us-east', 'coder-python', 'deploy-staging'. Clear names make routing configuration self-documenting.

Summary

OpenClaw's multi-agent routing directs messages to specialized agents via an eight-tier priority hierarchy. Bindings map message context (peer, guild, account, channel) to specific agents. The triage pattern uses a cheap classifier agent to route to expensive specialists. Workspaces provide logical isolation for multi-tenant setups. Each agent has a fully isolated workspace. Always define a default binding, use the most specific binding types, and document your routing topology.

Practice OpenClaw with hands-on challenges

Learn openclaw multi-agent routing hands-on in your IDE

Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.

Related Concepts

Related Cheatsheets

Master OpenClaw with Stanza

Interactive lessons and challenges, right in your code editor.

Check the free courses. No credit card.