Introduction
When running multiple agents, you need a way to direct incoming messages to the right agent based on context. OpenClaw uses a bindings system that matches channels, guilds, and roles to specific agents. This lesson covers how multi-agent routing works and how workspaces keep each agent's state cleanly separated.
Key Concepts
- Bindings: Configuration rules that map incoming messages from a channel, guild, or role to a specific agent.
- Matching Rules: The criteria OpenClaw evaluates to determine which agent should handle a given message, checked in order of specificity.
- Workspace Isolation: Each agent operates in its own workspace directory, ensuring conversation history, temporary files, and configuration do not leak between agents.
- Multi-Agent Routing: The process of evaluating bindings to dispatch messages to the correct agent.
Real World Context
Imagine a company Discord server with channels for engineering, sales, and support. You want a technical agent in the engineering channels, a product-knowledge agent in sales channels, and a troubleshooting agent in support channels. Bindings let you configure this routing without any custom code. If a user with an admin role sends a message in any channel, you might route them to a privileged agent with extra tools.
Deep Dive
Bindings are defined as an array of rules in your OpenClaw configuration. Each binding specifies match criteria and the target agent. Here is an example bindings configuration:
json{ "bindings": [ { "match": { "channel": "engineering-help" }, "agentId": "code-reviewer" }, { "match": { "channel": "sales-*", "guild": "acme-corp" }, "agentId": "sales-assistant" }, { "match": { "role": "admin" }, "agentId": "admin-agent" } ] }
The bindings above demonstrate three routing patterns. The first binding routes all messages in the engineering-help channel to the code-reviewer agent. The second binding uses a wildcard sales-* to match any channel starting with "sales-" but only within the acme-corp guild, routing those messages to the sales-assistant. The third binding matches by role rather than channel, sending all admin messages to a dedicated admin-agent.
OpenClaw evaluates bindings in order of specificity. A binding that matches on channel AND guild is more specific than one matching only a channel, which is more specific than one matching only a role. When multiple bindings could match, the most specific one wins.
Workspace isolation is critical in multi-agent setups. Each agent's workspace is stored at ~/.openclaw/agents/<agentId>/workspace/:
json{ "workspaceStructure": { "~/.openclaw/agents/code-reviewer/workspace/": { "history/": "conversation logs", "tmp/": "temporary processing files", "state.json": "agent runtime state" }, "~/.openclaw/agents/sales-assistant/workspace/": { "history/": "conversation logs", "tmp/": "temporary processing files", "state.json": "agent runtime state" } } }
This directory structure shows that each agent maintains completely independent state. The code-reviewer agent cannot read the sales-assistant agent's conversation history or temporary files. This isolation prevents data leakage between agents and ensures that resetting one agent does not affect another.
When a message arrives, the routing engine evaluates it through the following process: it extracts the message metadata (channel, guild, sender roles), iterates through bindings from most specific to least specific, and dispatches to the first matching agent. If no binding matches, the message is either dropped or routed to a default agent if one is configured.
Common Pitfalls
- Overlapping bindings without clear specificity: If two bindings match with equal specificity, the behavior may be unpredictable. Always ensure bindings have distinct specificity levels.
- Wildcard overuse: Using
*wildcards too broadly can accidentally route messages to the wrong agent. Test your patterns carefully. - Forgetting a default binding: Without a catch-all binding, messages that match no rule are silently dropped.
Best Practices
- Order bindings from most specific to least specific: This makes the configuration easier to read and reason about.
- Use explicit channel names over wildcards when possible: Explicit names are easier to debug and less prone to accidental matches.
- Always configure a default agent: Add a catch-all binding at the end to handle unmatched messages gracefully.
Summary
- Bindings map channels, guilds, and roles to specific agents using match rules.
- More specific bindings (matching multiple criteria) take priority over less specific ones.
- Each agent's workspace is fully isolated under
~/.openclaw/agents/<agentId>/workspace/. - Wildcard patterns allow flexible channel matching but should be used carefully.
- A default catch-all binding prevents messages from being silently dropped.