OpenClawSkills
GitHub
核心概念 • 5 分钟阅读

通道路由

各通道(WhatsApp/Telegram/Discord/Slack 等)的路由规则与共享上下文

OpenClaw 会把回复确定性地路由回"消息来源的通道"。模型不会选择通道;路由由宿主配置控制,并保持可预测。

Tutorial.step

关键术语

- ''Channel'':''whatsapp''、''telegram''、''discord''、''slack''、''signal''、''imessage''、''webchat''。

- AccountId:每个通道的账户实例(当支持时)。

- AgentId:一个独立的 workspace + session store("大脑")。

- SessionKey:用于存储上下文和控制并发的 bucket key。

Tutorial.step

Session key 形状(示例)

私信折叠到 agent 的 main session:

- ''agent:<agentId>:<mainKey>'' (default: ''agent:main:main'')

群组和通道按通道隔离:

- Groups: ''agent:<agentId>:<channel>:group:<id>''

- Channels/rooms: ''agent:<agentId>:<channel>:channel:<id>''

线程:

- Slack/Discord threads append '':thread:<threadId>'' to the base key.

- Telegram forum topics embed '':topic:<topicId>'' in the group key.

示例:''agent:main:telegram:group:-1001234567890:topic:42''、''agent:main:discord:channel:123456:thread:987654''

Tutorial.step

路由规则(如何选择 agent)

路由为每条入站消息选择一个 agent:

1. ''精确 peer 匹配''(''bindings'' 带有 ''peer.kind'' + ''peer.id'')。

2. ''Guild 匹配''(Discord)通过 ''guildId''。

3. ''Team 匹配''(Slack)通过 ''teamId''。

4. ''Account 匹配''(通道的 ''accountId'')。

5. Channel 匹配(该通道的任意账户)。

6. ''默认 agent''(''agents.list[].default'',否则列表首项,回退到 ''main'')。

匹配的 agent 决定使用哪个 workspace 和 session store。

Tutorial.step

Broadcast groups(同一消息跑多个 agents)

广播组允许您在 OpenClaw 通常会回复时为同一对等方运行多个代理(例如:在 WhatsApp 群组中,在提及/激活门控之后)。

配置:

Json5
{
  broadcast: {
    strategy: "parallel",
    "[email protected]": ["alfred", "baerbel"],
    "+15555550123": ["support", "logger"]
  }
}

参见:''/broadcast-groups''

Tutorial.step

配置概览

- ''agents.list'':命名的 agent 定义(workspace、model 等)。

- ''bindings'':将入站的 channels/accounts/peers 映射到 agents。

示例:

Json5
{
  agents: {
    list: [{ id: "support", name: "Support", workspace: "~/.openclaw/workspace-support" }]
  },
  bindings: [
    { match: { channel: "slack", teamId: "T123" }, agentId: "support" },
    { match: { channel: "telegram", peer: { kind: "group", id: "-100123" } }, agentId: "support" }
  ]
}
Tutorial.step

Session 存储

Session stores 存储在 state 目录下(默认 ''~/.openclaw''):

- ''~/.openclaw/agents/<agentId>/sessions/sessions.json''

- JSONL transcripts 与 store 同目录

你可以通过 ''session.store''(支持 ''{agentId}'' 模板)覆盖 store 路径。

Tutorial.step

WebChat 行为

WebChat attaches to the selected agent and defaults to the agent's main session. Because of this, WebChat lets you see cross-channel context for that agent in one place.

Tutorial.step

回复上下文(Reply context)

入站回复在可能时会包含:

- ''ReplyToId''、''ReplyToBody''、''ReplyToSender''

- 引用内容会附加到 ''Body'' 的 ''[Replying to ...]'' 块中。

此行为在各通道间保持一致。