Purpose: quick reference for how OpenClaw runs multiple agents on one Gateway, routes messages deterministically, and reports presence.

Overview: this diagram shows one OpenClaw Gateway receiving inbound channel payloads, applying a deterministic Routing & Bindings priority ladder (Peer Parent Peer Guild+Role Guild/Team Account Channel Fallback), and selecting an agentId. The selected agent runs in an isolated scope (workspace, state directory with auth/model registries, and session store), then executes tools under a security check with per-agent allow/deny policy (while tools.elevated remains global). The lower lane shows Presence as best-effort in-memory monitoring fed by gateway/WebSocket/beacon updates, pruned after TTL (~5 minutes), and displayed in the macOS Instances UI with instanceId-based deduplication.

One-Screen Summary

TopicKey Point
One agent meansFully scoped environment, not just a prompt
Multi-agent runtimeOne Gateway can host multiple isolated agents side-by-side
RoutingBinding rules are deterministic; most specific rule wins
SecurityWorkspace is default cwd; strict isolation needs sandboxing/docker/tool policy
PresenceBest-effort, in-memory view with TTL pruning

1. What “One Agent” Actually Is

In OpenClaw, each agent has isolated state surfaces.

SurfacePer-Agent Isolation
WorkspaceOwn AGENTS.md, SOUL.md, notes
State directory (agentDir)Own auth profiles and model registry
Session storeOwn chat/session history by agentId

Critical auth reminder:

  • Auth profiles are per-agent.
  • A new agent does not inherit credentials from main unless you explicitly copy auth-profiles.json.

2. Routing: How Messages Find the Target Agent

Routing is deterministic. The first most-specific matching binding wins.

PriorityBinding Type
1 (highest)Peer match (specific user/DM ID)
2Parent peer (thread inheritance)
3Guild + role
4Guild/team ID
5Account ID
6Channel
7 (fallback)Default agent (usually main)

Practical reading rule:

  • If routing is surprising, check for a more-specific peer rule overriding channel/global rules.

2.1 Telegram Routing: Minimal Decision Model

For Telegram, routing is easiest to understand as Who Context Identity Fallback.

KeyQuestionGateway InputTypical RuleWhy It Is Sufficient
Peer ID (Who)“Is this a specific person/chat with dedicated routing?”Sender/chat peer metadatamatch.peerHandles VIP/specific-user routing with highest precision
Parent ID (Context)“Is this a reply that should stay in the same thread/agent?”reply_to_message_id + owner lookupparent-peer inheritanceKeeps replies on the agent that owns the original message
Account ID (Identity)“Which bot login/token received this?”Account metadata derived from token mappingmatch.accountIdSeparates work/personal (or brand A/B) identities cleanly
Default (Safety net)“No specific rule matched?”No match statedefault agentGuarantees deterministic routing for unknown traffic

Practical Telegram scope:

  • Guild/team layers are usually not used for Telegram payloads.
  • Channel rule (telegram) can exist, but many setups can route fully with peer + parent + account + default.

Telegram ladder (packet view)

PriorityRuleInput (What Gateway Sees)Output (Decision)
1Peer MatchsenderId/chatId matches match.peerRoute to specific agent; stop
2Parent PeerReply metadata resolves original message ownerRoute to owning agent; stop
3-4Guild/TeamUsually absent on TelegramSkip/continue
5Account IDIncoming token maps to configured account idRoute to account-bound agent; stop
6Channel (optional)channel=telegramRoute to channel-default agent; stop
7DefaultNo prior matchRoute to default agent

Key technical details:

  • Peer input: DM commonly maps to user ID; group messages commonly map to group/chat context.
  • Parent dependency: requires message-owner linkage in Gateway state; if linkage is gone, inheritance may fail.
  • Account input: accountId is user-defined in openclaw.json (telegram.accounts[].id) and is derived by mapping the receiving token to that configured id.
  • Stop logic: first match wins; lower levels are not evaluated after match.

3. Common Setup Patterns

A) Multi-Account (“Business Phone”)

ScenarioConfig PatternResult
Two WhatsApp numbers on one serverRoute by accountIdNumber A Agent A, Number B Agent B, fully separate

B) Deep Work Split (One User, Two Brains)

ScenarioConfig PatternResult
Daily chat on fast model, one DM thread on premium modelGlobal channel binding + specific peer bindingTarget DM uses specialized agent/model; direct-chat identity remains consistent

C) Family Shared Gateway

ScenarioConfig PatternResult
Multiple people share one hostDifferent agentId per personSeparate auth, sessions, and memory; no cross-talk by default

4. Security and Sandboxing

Use this as the practical boundary checklist.

ControlWhat It DoesNote
Workspace default behaviorSets working directory expectationsNot a hard sandbox by itself
agents.defaults.sandboxEnables stronger path/process isolationNeeded to block absolute-path escapes
Per-agent Docker (v2026.1.6+)Isolates tool execution environmentUseful for untrusted workloads
Per-agent tool allow/denyRestricts tool surface by agenttools.elevated remains global

5. Presence (Monitoring)

Presence is observability, not guaranteed ground truth.

AspectBehavior
PurposeBest-effort list of connected instances (for example macOS Instances tab)
SourcesGateway events, WebSocket connections, client beacons
StorageIn-memory and ephemeral
TTLEntries pruned when older than ~5 minutes
DedupUses instanceId; unstable IDs can create duplicate rows

Operational implication:

  • Presence rows can be temporarily stale or duplicated after reconnects.

Quick Troubleshooting Checklist

  1. Confirm expected agentId owns the workspace/auth/session surfaces
  2. Inspect bindings from highest to lowest priority (peer before channel)
  3. Verify accountId/guild/team/channel identifiers match real inbound metadata
  4. If isolation is required, enable sandboxing and/or per-agent Docker
  5. If presence looks wrong, check instanceId stability and TTL timing

Fast Mental Model

  • Agent = isolated identity + memory + credentials + sessions
  • Binding = deterministic router to pick that agent
  • Presence = soft health signal, not authoritative truth