1514 字
8 分钟

OpenClaw 的核心概念


read_when:

  • 你想要了解 OpenClaw 的核心概念
  • 你想要理解 agents、workspace、sub-agents、channels 之间的关系 summary: OpenClaw 核心概念详解:Agents、Workspace、Sub-Agents、Channels 及其协作方式 title: OpenClaw 核心概念详解 x-i18n: generated_at: “2026-02-11T00:00:00Z” model: claude-sonnet-4-5 provider: openclaw-docs source_path: concepts/core-concepts-guide.md workflow: docs

OpenClaw 核心概念详解#

概念总览#

┌─────────────────────────────────────────────────────────────┐
│ Gateway (网关) │
│ openclaw.json 配置 │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Channel 1 │ │ Channel 2 │ │
│ │ (WhatsApp) │ │ (Telegram) │ │
│ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │
│ │ Bindings(路由) │ │
│ └──────────┬──────────┘ │
│ ▼ │
│ ┌────────────────────┐ │
│ │ Agent 1 (main) │ ◄── 默认智能体 │
│ │ ───────────── │ │
│ │ Workspace: │ │
│ │ ~/.openclaw/ │ │
│ │ workspace/ │ │
│ │ │ │
│ │ • AGENTS.md │ │
│ │ • SOUL.md │ │
│ │ • USER.md │ │
│ │ • memory/ │ │
│ └─────────┬──────────┘ │
│ │ │
│ │ sessions_spawn 工具 │
│ ▼ │
│ ┌────────────────────┐ │
│ │ Sub-Agent │ ◄── 后台任务 │
│ │ (独立会话) │ │
│ └────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

1. Agents (智能体)#

什么是 Agent?#

一个 Agent 是一个完全独立的”AI 大脑”,包含:

属性说明
工作区文件、记忆、人格规则
状态目录认证配置、模型注册表
会话存储聊天历史记录
认证配置独立的 API 密钥和 OAuth

单 Agent 模式(默认)#

{
agents: {
defaults: {
workspace: "~/.openclaw/workspace", // 默认工作区
},
},
}
  • agentId: "main" (默认)
  • 会话键: agent:main:main
  • 适合:个人使用

多 Agent 模式#

{
agents: {
list: [
{
id: "home",
name: "Home",
workspace: "~/.openclaw/workspace-home",
model: "anthropic/claude-sonnet-4-5",
default: true,
},
{
id: "work",
workspace: "~/.openclaw/workspace-work",
model: "anthropic/claude-opus-4-5",
},
],
},
}

使用场景

  • 工作/生活分离
  • 不同人格/角色
  • 多人共享服务器

2. Workspace (工作区)#

定义#

工作区是 Agent 的”家”和”记忆”,存储在独立于配置的位置。

默认位置#

~/.openclaw/workspace # 默认
~/.openclaw/workspace-<agentId> # 多 Agent 模式

工作区文件结构#

~/.openclaw/workspace/
├── AGENTS.md # 操作指南 + 记忆使用指南
├── SOUL.md # 人设、语气、边界
├── USER.md # 用户档案、称呼偏好
├── IDENTITY.md # Agent 名称、风格、表情
├── TOOLS.md # 本地工具和惯例说明
├── HEARTBEAT.md # 心跳检查清单(可选)
├── BOOTSTRAP.md # 首次运行仪式(完成后删除)
├── MEMORY.md # 长期记忆精选(可选)
├── memory/
│ └── 2026-02-11.md # 每日记忆日志
├── skills/ # Agent 特定的 Skills
└── canvas/ # Canvas UI 文件

引导文件注入#

每个会话开始时,OpenClaw 会将这些文件注入到 Agent 上下文中:

// 文件内容被添加到系统提示词中
const prompt = `
${readFile("AGENTS.md")}
${readFile("SOUL.md")}
${readFile("USER.md")}
...
`;

3. Sub-Agents (子智能体)#

定义#

Sub-Agent 是从主 Agent 会话中生成的后台并行任务,运行在独立会话中。

关键特性#

特性说明
独立会话agent:<agentId>:subagent:<uuid>
非阻塞立即返回,后台运行
结果通告完成后将结果发送回请求者聊天
工具限制默认无会话工具(防止无限生成)
成本每个 Sub-Agent 有独立的 token 使用量

使用示例#

用户: 帮我研究一下 Python 和 JavaScript 的最新趋势
Agent: 我会启动两个并行研究任务...
[sessions_spawn x2]
{
agents: {
defaults: {
subagents: {
maxConcurrent: 8, // 最大并发数
model: "openai/gpt-4o-mini", // 使用更便宜的模型
},
},
},
}

Sub-Agent 命令#

Terminal window
/subagents list # 列出运行中的子智能体
/subagents stop <id> # 停止特定子智能体
/subagents log <id> # 查看子智能体日志
/subagents info <id> # 查看详细信息
/subagents send <id> <msg> # 向子智能体发送消息

4. Channels (渠道)#

定义#

Channel 是 OpenClaw 与外部聊天平台之间的连接桥梁。

支持的渠道#

渠道说明
whatsappWhatsApp
telegramTelegram
discordDiscord
slackSlack
signalSignal
imessageiMessage
webchatWeb 界面
googlechatGoogle Chat

账户概念#

某些渠道支持多账户

{
channels: {
whatsapp: {
accounts: {
personal: {
// authDir: "~/.openclaw/credentials/whatsapp/personal"
},
biz: {
// authDir: "~/.openclaw/credentials/whatsapp/biz"
},
},
},
},
}

5. 它们如何配合工作?#

消息路由流程#

入站消息
识别 Channel
识别 AccountId
检查 Bindings
匹配 Peer/Group?
├─ 是 → 路由到指定 Agent
├─ 否 → 匹配 AccountId?
│ │
│ ├─ 是 → 路由到指定 Agent
│ │
│ └─ 否 → 匹配 Channel?
│ │
│ ├─ 是 → 路由到指定 Agent
│ │
│ └─ 否 → 使用默认 Agent
Agent 处理消息
需要后台任务?
├─ 是 → 启动 Sub-Agent
│ │
│ └─ Sub-Agent 完成后通告
└─ 否 → 生成回复
返回原 Channel

配置示例:完整的多 Agent 设置#

{
// 1. 定义多个 Agent
agents: {
list: [
{
id: "chat",
name: "日常助手",
workspace: "~/.openclaw/workspace-chat",
model: "anthropic/claude-sonnet-4-5",
default: true,
subagents: {
model: "openai/gpt-4o-mini", // 子任务用便宜模型
},
},
{
id: "work",
name: "工作助手",
workspace: "~/.openclaw/workspace-work",
model: "anthropic/claude-opus-4-5",
sandbox: { mode: "all" }, // 工作任务用沙箱
},
],
},
// 2. 路由规则:消息如何分配给 Agent
bindings: [
// WhatsApp 私信 -> 日常助手
{ agentId: "chat", match: { channel: "whatsapp" } },
// Telegram -> 工作助手
{ agentId: "work", match: { channel: "telegram" } },
// 特定群组 -> 工作助手
{
agentId: "work",
match: {
channel: "whatsapp",
peer: { kind: "group", id: "[email protected]" }
}
},
],
// 3. 渠道配置
channels: {
whatsapp: {
dmPolicy: "allowlist",
allowFrom: ["+15551234567", "+15559876543"],
},
telegram: {
botToken: "${TELEGRAM_BOT_TOKEN}",
},
},
// 4. 子智能体配置
tools: {
subagents: {
tools: {
deny: ["sessions_spawn"], // 子智能体不能再生子智能体
},
},
},
}

会话键规则#

场景会话键格式
主 Agent 私信agent:<agentId>:<mainKey>
群组agent:<agentId>:<channel>:group:<id>
频道/房间agent:<agentId>:<channel>:channel:<id>
子智能体agent:<agentId>:subagent:<uuid>
线程/话题上述 + :thread:<id>:topic:<id>

路由优先级#

  1. 精确对端匹配 (bindings 中的 peer.kind + peer.id)
  2. Guild 匹配 (Discord) 通过 guildId
  3. Team 匹配 (Slack) 通过 teamId
  4. 账户匹配 (渠道上的 accountId)
  5. 渠道匹配 (该渠道上的任意账户)
  6. 默认智能体 (agents.list[].default,否则取列表第一项)

总结#

概念作用类比
Agent独立的 AI 大脑公司的不同部门
WorkspaceAgent 的记忆和人格部门的知识库和文化
Sub-Agent后台并行任务外包临时工
Channel消息输入/输出接口客服接入的电话线
Bindings路由规则电话转接规则表

典型配置建议

  • 个人使用:单 Agent + 多 Channels
  • 工作分离:2 个 Agents(home/work)+ 按 Channel 路由
  • 多人共享:多 Agents(每人一个)+ 按 Peer(私信)路由

相关文档#

赞助支持

如果这篇文章对你有帮助,欢迎赞助支持!

赞助
OpenClaw 的核心概念
https://jkwei.com/posts/knowledge/openclaw基础知识/
作者
Jacky
发布于
2026-02-11
许可协议
CC BY-NC-SA 4.0
最后更新于 2026-02-11

目录