Skip to content

Commit 96c7702

Browse files
authored
Agents: add account-scoped bind and routing commands (#27195)
Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: ad35a45 Co-authored-by: gumadeiras <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
1 parent c5d040b commit 96c7702

17 files changed

Lines changed: 1133 additions & 24 deletions

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Docs: https://docs.openclaw.ai
44

55
## 2026.2.26 (Unreleased)
66

7+
### Changes
8+
9+
- Agents/Routing CLI: add `openclaw agents bindings`, `openclaw agents bind`, and `openclaw agents unbind` for account-scoped route management, including channel-only to account-scoped binding upgrades, role-aware binding identity handling, plugin-resolved binding account IDs, and optional account-binding prompts in `openclaw channels add`. (#27195) thanks @gumadeiras.
10+
711
### Fixes
812

913
- Android/Node invoke: remove native gateway WebSocket `Origin` header to avoid false origin rejections, unify invoke command registry/policy/error parsing paths, and keep command availability checks centralized to reduce dispatcher/advertisement drift. (#27257) Thanks @obviyus.

‎docs/cli/agents.md‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
summary: "CLI reference for `openclaw agents` (list/add/delete/set identity)"
2+
summary: "CLI reference for `openclaw agents` (list/add/delete/bindings/bind/unbind/set identity)"
33
read_when:
44
- You want multiple isolated agents (workspaces + routing + auth)
55
title: "agents"
@@ -19,11 +19,59 @@ Related:
1919
```bash
2020
openclaw agents list
2121
openclaw agents add work --workspace ~/.openclaw/workspace-work
22+
openclaw agents bindings
23+
openclaw agents bind --agent work --bind telegram:ops
24+
openclaw agents unbind --agent work --bind telegram:ops
2225
openclaw agents set-identity --workspace ~/.openclaw/workspace --from-identity
2326
openclaw agents set-identity --agent main --avatar avatars/openclaw.png
2427
openclaw agents delete work
2528
```
2629

30+
## Routing bindings
31+
32+
Use routing bindings to pin inbound channel traffic to a specific agent.
33+
34+
List bindings:
35+
36+
```bash
37+
openclaw agents bindings
38+
openclaw agents bindings --agent work
39+
openclaw agents bindings --json
40+
```
41+
42+
Add bindings:
43+
44+
```bash
45+
openclaw agents bind --agent work --bind telegram:ops --bind discord:guild-a
46+
```
47+
48+
If you omit `accountId` (`--bind <channel>`), OpenClaw resolves it from channel defaults and plugin setup hooks when available.
49+
50+
### Binding scope behavior
51+
52+
- A binding without `accountId` matches the channel default account only.
53+
- `accountId: "*"` is the channel-wide fallback (all accounts) and is less specific than an explicit account binding.
54+
- If the same agent already has a matching channel binding without `accountId`, and you later bind with an explicit or resolved `accountId`, OpenClaw upgrades that existing binding in place instead of adding a duplicate.
55+
56+
Example:
57+
58+
```bash
59+
# initial channel-only binding
60+
openclaw agents bind --agent work --bind telegram
61+
62+
# later upgrade to account-scoped binding
63+
openclaw agents bind --agent work --bind telegram:ops
64+
```
65+
66+
After the upgrade, routing for that binding is scoped to `telegram:ops`. If you also want default-account routing, add it explicitly (for example `--bind telegram:default`).
67+
68+
Remove bindings:
69+
70+
```bash
71+
openclaw agents unbind --agent work --bind telegram:ops
72+
openclaw agents unbind --agent work --all
73+
```
74+
2775
## Identity files
2876

2977
Each agent workspace can include an `IDENTITY.md` at the workspace root:

‎docs/cli/channels.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ openclaw channels remove --channel telegram --delete
3535

3636
Tip: `openclaw channels add --help` shows per-channel flags (token, app token, signal-cli paths, etc).
3737

38+
When you run `openclaw channels add` without flags, the interactive wizard can prompt:
39+
40+
- account ids per selected channel
41+
- optional display names for those accounts
42+
- `Bind configured channel accounts to agents now?`
43+
44+
If you confirm bind now, the wizard asks which agent should own each configured channel account and writes account-scoped routing bindings.
45+
46+
You can also manage the same routing rules later with `openclaw agents bindings`, `openclaw agents bind`, and `openclaw agents unbind` (see [agents](/cli/agents)).
47+
3848
## Login / logout (interactive)
3949

4050
```bash

‎docs/cli/index.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,37 @@ Options:
574574
- `--non-interactive`
575575
- `--json`
576576

577-
Binding specs use `channel[:accountId]`. When `accountId` is omitted for WhatsApp, the default account id is used.
577+
Binding specs use `channel[:accountId]`. When `accountId` is omitted, OpenClaw may resolve account scope via channel defaults/plugin hooks; otherwise it is a channel binding without explicit account scope.
578+
579+
#### `agents bindings`
580+
581+
List routing bindings.
582+
583+
Options:
584+
585+
- `--agent <id>`
586+
- `--json`
587+
588+
#### `agents bind`
589+
590+
Add routing bindings for an agent.
591+
592+
Options:
593+
594+
- `--agent <id>`
595+
- `--bind <channel[:accountId]>` (repeatable)
596+
- `--json`
597+
598+
#### `agents unbind`
599+
600+
Remove routing bindings for an agent.
601+
602+
Options:
603+
604+
- `--agent <id>`
605+
- `--bind <channel[:accountId]>` (repeatable)
606+
- `--all`
607+
- `--json`
578608

579609
#### `agents delete <id>`
580610

‎docs/concepts/multi-agent.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ Bindings are **deterministic** and **most-specific wins**:
185185
If multiple bindings match in the same tier, the first one in config order wins.
186186
If a binding sets multiple match fields (for example `peer` + `guildId`), all specified fields are required (`AND` semantics).
187187

188+
Important account-scope detail:
189+
190+
- A binding that omits `accountId` matches the default account only.
191+
- Use `accountId: "*"` for a channel-wide fallback across all accounts.
192+
- If you later add the same binding for the same agent with an explicit account id, OpenClaw upgrades the existing channel-only binding to account-scoped instead of duplicating it.
193+
188194
## Multiple accounts / phone numbers
189195

190196
Channels that support **multiple accounts** (e.g. WhatsApp) use `accountId` to identify

‎src/channels/plugins/types.adapters.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ import type {
2121
} from "./types.core.js";
2222

2323
export type ChannelSetupAdapter = {
24-
resolveAccountId?: (params: { cfg: OpenClawConfig; accountId?: string }) => string;
24+
resolveAccountId?: (params: {
25+
cfg: OpenClawConfig;
26+
accountId?: string;
27+
input?: ChannelSetupInput;
28+
}) => string;
29+
resolveBindingAccountId?: (params: {
30+
cfg: OpenClawConfig;
31+
agentId: string;
32+
accountId?: string;
33+
}) => string | undefined;
2534
applyAccountName?: (params: {
2635
cfg: OpenClawConfig;
2736
accountId: string;

‎src/cli/program/preaction.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe("registerPreActionHooks", () => {
8080
program.command("update").action(async () => {});
8181
program.command("channels").action(async () => {});
8282
program.command("directory").action(async () => {});
83+
program.command("agents").action(async () => {});
8384
program.command("configure").action(async () => {});
8485
program.command("onboard").action(async () => {});
8586
program
@@ -145,6 +146,15 @@ describe("registerPreActionHooks", () => {
145146
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledTimes(1);
146147
});
147148

149+
it("loads plugin registry for agents command", async () => {
150+
await runCommand({
151+
parseArgv: ["agents"],
152+
processArgv: ["node", "openclaw", "agents"],
153+
});
154+
155+
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledTimes(1);
156+
});
157+
148158
it("skips config guard for doctor and completion commands", async () => {
149159
await runCommand({
150160
parseArgv: ["doctor"],

‎src/cli/program/preaction.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const PLUGIN_REQUIRED_COMMANDS = new Set([
2525
"message",
2626
"channels",
2727
"directory",
28+
"agents",
2829
"configure",
2930
"onboard",
3031
]);

‎src/cli/program/register.agent.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
33

44
const agentCliCommandMock = vi.fn();
55
const agentsAddCommandMock = vi.fn();
6+
const agentsBindingsCommandMock = vi.fn();
7+
const agentsBindCommandMock = vi.fn();
68
const agentsDeleteCommandMock = vi.fn();
79
const agentsListCommandMock = vi.fn();
810
const agentsSetIdentityCommandMock = vi.fn();
11+
const agentsUnbindCommandMock = vi.fn();
912
const setVerboseMock = vi.fn();
1013
const createDefaultDepsMock = vi.fn(() => ({ deps: true }));
1114

@@ -21,9 +24,12 @@ vi.mock("../../commands/agent-via-gateway.js", () => ({
2124

2225
vi.mock("../../commands/agents.js", () => ({
2326
agentsAddCommand: agentsAddCommandMock,
27+
agentsBindingsCommand: agentsBindingsCommandMock,
28+
agentsBindCommand: agentsBindCommandMock,
2429
agentsDeleteCommand: agentsDeleteCommandMock,
2530
agentsListCommand: agentsListCommandMock,
2631
agentsSetIdentityCommand: agentsSetIdentityCommandMock,
32+
agentsUnbindCommand: agentsUnbindCommandMock,
2733
}));
2834

2935
vi.mock("../../globals.js", () => ({
@@ -55,9 +61,12 @@ describe("registerAgentCommands", () => {
5561
vi.clearAllMocks();
5662
agentCliCommandMock.mockResolvedValue(undefined);
5763
agentsAddCommandMock.mockResolvedValue(undefined);
64+
agentsBindingsCommandMock.mockResolvedValue(undefined);
65+
agentsBindCommandMock.mockResolvedValue(undefined);
5866
agentsDeleteCommandMock.mockResolvedValue(undefined);
5967
agentsListCommandMock.mockResolvedValue(undefined);
6068
agentsSetIdentityCommandMock.mockResolvedValue(undefined);
69+
agentsUnbindCommandMock.mockResolvedValue(undefined);
6170
createDefaultDepsMock.mockReturnValue({ deps: true });
6271
});
6372

@@ -147,6 +156,61 @@ describe("registerAgentCommands", () => {
147156
);
148157
});
149158

159+
it("forwards agents bindings options", async () => {
160+
await runCli(["agents", "bindings", "--agent", "ops", "--json"]);
161+
expect(agentsBindingsCommandMock).toHaveBeenCalledWith(
162+
{
163+
agent: "ops",
164+
json: true,
165+
},
166+
runtime,
167+
);
168+
});
169+
170+
it("forwards agents bind options", async () => {
171+
await runCli([
172+
"agents",
173+
"bind",
174+
"--agent",
175+
"ops",
176+
"--bind",
177+
"matrix-js:ops",
178+
"--bind",
179+
"telegram",
180+
"--json",
181+
]);
182+
expect(agentsBindCommandMock).toHaveBeenCalledWith(
183+
{
184+
agent: "ops",
185+
bind: ["matrix-js:ops", "telegram"],
186+
json: true,
187+
},
188+
runtime,
189+
);
190+
});
191+
192+
it("documents bind accountId resolution behavior in help text", () => {
193+
const program = new Command();
194+
registerAgentCommands(program, { agentChannelOptions: "last|telegram|discord" });
195+
const agents = program.commands.find((command) => command.name() === "agents");
196+
const bind = agents?.commands.find((command) => command.name() === "bind");
197+
const help = bind?.helpInformation() ?? "";
198+
expect(help).toContain("accountId is resolved by channel defaults/hooks");
199+
});
200+
201+
it("forwards agents unbind options", async () => {
202+
await runCli(["agents", "unbind", "--agent", "ops", "--all", "--json"]);
203+
expect(agentsUnbindCommandMock).toHaveBeenCalledWith(
204+
{
205+
agent: "ops",
206+
bind: [],
207+
all: true,
208+
json: true,
209+
},
210+
runtime,
211+
);
212+
});
213+
150214
it("forwards agents delete options", async () => {
151215
await runCli(["agents", "delete", "worker-a", "--force", "--json"]);
152216
expect(agentsDeleteCommandMock).toHaveBeenCalledWith(

‎src/cli/program/register.agent.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import type { Command } from "commander";
22
import { agentCliCommand } from "../../commands/agent-via-gateway.js";
33
import {
44
agentsAddCommand,
5+
agentsBindingsCommand,
6+
agentsBindCommand,
57
agentsDeleteCommand,
68
agentsListCommand,
79
agentsSetIdentityCommand,
10+
agentsUnbindCommand,
811
} from "../../commands/agents.js";
912
import { setVerbose } from "../../globals.js";
1013
import { defaultRuntime } from "../../runtime.js";
@@ -102,6 +105,68 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
102105
});
103106
});
104107

108+
agents
109+
.command("bindings")
110+
.description("List routing bindings")
111+
.option("--agent <id>", "Filter by agent id")
112+
.option("--json", "Output JSON instead of text", false)
113+
.action(async (opts) => {
114+
await runCommandWithRuntime(defaultRuntime, async () => {
115+
await agentsBindingsCommand(
116+
{
117+
agent: opts.agent as string | undefined,
118+
json: Boolean(opts.json),
119+
},
120+
defaultRuntime,
121+
);
122+
});
123+
});
124+
125+
agents
126+
.command("bind")
127+
.description("Add routing bindings for an agent")
128+
.option("--agent <id>", "Agent id (defaults to current default agent)")
129+
.option(
130+
"--bind <channel[:accountId]>",
131+
"Binding to add (repeatable). If omitted, accountId is resolved by channel defaults/hooks.",
132+
collectOption,
133+
[],
134+
)
135+
.option("--json", "Output JSON summary", false)
136+
.action(async (opts) => {
137+
await runCommandWithRuntime(defaultRuntime, async () => {
138+
await agentsBindCommand(
139+
{
140+
agent: opts.agent as string | undefined,
141+
bind: Array.isArray(opts.bind) ? (opts.bind as string[]) : undefined,
142+
json: Boolean(opts.json),
143+
},
144+
defaultRuntime,
145+
);
146+
});
147+
});
148+
149+
agents
150+
.command("unbind")
151+
.description("Remove routing bindings for an agent")
152+
.option("--agent <id>", "Agent id (defaults to current default agent)")
153+
.option("--bind <channel[:accountId]>", "Binding to remove (repeatable)", collectOption, [])
154+
.option("--all", "Remove all bindings for this agent", false)
155+
.option("--json", "Output JSON summary", false)
156+
.action(async (opts) => {
157+
await runCommandWithRuntime(defaultRuntime, async () => {
158+
await agentsUnbindCommand(
159+
{
160+
agent: opts.agent as string | undefined,
161+
bind: Array.isArray(opts.bind) ? (opts.bind as string[]) : undefined,
162+
all: Boolean(opts.all),
163+
json: Boolean(opts.json),
164+
},
165+
defaultRuntime,
166+
);
167+
});
168+
});
169+
105170
agents
106171
.command("add [name]")
107172
.description("Add a new isolated agent")

0 commit comments

Comments
 (0)