02 · 架构图
系统架构 & 模块组成
OpenClaw 以单一 TypeScript 进程(Gateway)为核心,WebSocket 端口 18789 统一管理所有渠道连接、Session 路由和工具执行。架构刻意保持极简。
高层架构总览
伴侣应用层(apps/)
🍎 macOS App
Menu Bar
快捷入口
快捷入口
📱 iOS Node
设备配对
移动端节点
移动端节点
🤖 Android Node
持续语音
移动端节点
移动端节点
🖥️ Control UI
Web 管理面板
Mission Control
Mission Control
🎤 Voice
唤醒词检测
MLX TTS(macOS)
MLX TTS(macOS)
⬇️ WebSocket (port 18789)
Gateway 层(src/gateway)— 单一 TypeScript 进程,系统核心
🌐 WebSocket Server
所有连接入口
port 18789
port 18789
🔐 Auth & Auth Mode Policy
设备配对 / Token 验证
Rate Limit
Rate Limit
🔄 Config Reload
热重载配置
Diff + Plan + Apply
Diff + Plan + Apply
📊 Control UI
CSP + 路由
Web 面板
Web 面板
⬇️ 内部函数调用(TypeScript async)
核心业务层(src/)— ~60 功能模块
🤖 Agents
多 Agent 运行时
Sandbox 执行
Tool 审批
Sandbox 执行
Tool 审批
💬 Channels
50+ 渠道接入
消息路由
Allowlist
消息路由
Allowlist
🧠 Memory
Markdown 文件
SOUL.md / MEMORY.md
日志追加
SOUL.md / MEMORY.md
日志追加
🔀 Routing
多 Agent 路由
账号隔离
Session 绑定
账号隔离
Session 绑定
🔧 Tools / Flows
工具执行
健康检查流
Provider 流
健康检查流
Provider 流
🔌 Plugin SDK
扩展接口
公共 API Barrel
能力契约
公共 API Barrel
能力契约
⬇️ Extension Plugin API
扩展插件层(extensions/)— LLM、渠道、工具、媒体
🤖 LLM Providers
Anthropic / OpenAI
Google / AWS …
25+ 提供商
Google / AWS …
25+ 提供商
📡 Channel Plugins
Slack / Discord
Telegram / WhatsApp
50+ 渠道
Telegram / WhatsApp
50+ 渠道
🛠️ Tool Plugins
Search / Browser
GitHub / MCP
Diagnostics
GitHub / MCP
Diagnostics
🎵 Media Plugins
ElevenLabs / Deepgram
Runway / Azure
Image / Video
Runway / Azure
Image / Video
🧠 Memory Plugins
active-memory
memory-lancedb
memory-wiki
memory-lancedb
memory-wiki
⬇️ 文件系统 / HTTP / WebSocket
存储 & 外部服务
📁 Workspace
~/.openclaw/workspace/
纯 Markdown 文件
无向量数据库
纯 Markdown 文件
无向量数据库
📄 Memory Files
SOUL.md · MEMORY.md
AGENTS.md · TOOLS.md
日志 YYYY-MM-DD.md
AGENTS.md · TOOLS.md
日志 YYYY-MM-DD.md
🌐 LLM APIs
Claude / GPT / Gemini
DeepSeek / Local Ollama
25+ 提供商
DeepSeek / Local Ollama
25+ 提供商
🔗 External APIs
消息平台 API
搜索引擎 · 媒体
GitHub · Calendar
搜索引擎 · 媒体
GitHub · Calendar
核心设计原则:「Core 保持 Plugin 无感知。无捆绑 ID / 默认值 / 策略在 Core 中,能力通过 Manifest/Registry/Capability 契约声明。」所有渠道、LLM、工具均通过插件扩展,Core 只管运行时循环。
核心模块(src/)
gateway
src/gateway/
整个系统的单一控制平面。WebSocket Server(18789)、Auth/Token 管理、Config 热重载、Control UI 路由、Chat 附件处理
agents
src/agents/
多 Agent 运行时、Sandbox 执行(Docker/SSH/OpenShell)、Tool 审批工作流、Anthropic API 流式调用、Bash 执行、API Key 轮转
channels
src/channels/
抽象渠道接入层:消息路由、Allowlist 管理、Inbound Event 处理、Thread 绑定、消息草稿、输入状态指示符、插件注册表
memory
src/memory/
极简记忆系统:纯 Markdown 文件,无向量数据库。日志追加(昨天 + 今天自动加载)、MEMORY.md 长期记忆、SOUL.md 人格定义
routing
src/routing/
多 Agent 路由:渠道/账号绑定到隔离 Agent、Session Key 管理、Account Lookup、Peer Kind 匹配、Binding Scope 定义
plugin-sdk
src/plugin-sdk/
Plugin 公共 API Barrel:所有插件仅通过此 SDK 访问 Core 能力。声明能力契约、热路径 prepared facts 传递
flows
src/flows/
工作流编排:Doctor 健康检查/修复流、渠道初始化流、搜索配置流、Provider 管理流、Model Picker
tts / voice
src/tts/
文字转语音集成、唤醒词检测(macOS/iOS)、持续语音模式(Android)、实时转录
mcp
src/mcp/
Model Context Protocol 客户端/服务端实现,允许通过 MCP 调用外部工具,与 mcporter 包配合
web-search / web-fetch
src/web-search/ + src/web-fetch/
搜索引擎集成(Google/DuckDuckGo/Brave/Firecrawl)、网页内容抓取、链接理解
cli / tui
src/cli/ + src/tui/
CLI 入口(entry.ts → runCli)、TUI 终端界面、Compile Cache、Respawn Plan、参数规范化
媒体生成
src/image-generation/ + video/ + music/
图像生成、视频生成、音乐生成、媒体理解接口(具体实现由 extensions 提供)
扩展插件生态(extensions/)
捆绑插件随 Core 分发,官方外部插件独立管理依赖。所有插件只通过
src/plugin-sdk API Barrel 访问 Core。LLM
anthropicLLM
openaiLLM
googleLLM
aws-bedrockLLM
mistralLLM
groqLLM
deepseekLLM
ollama (local)渠道
slack渠道
discord渠道
telegram渠道
whatsapp渠道
signal渠道
matrix渠道
teams渠道
imessage搜索
google-search搜索
brave-search搜索
firecrawl搜索
duckduckgo语音
elevenlabs语音
deepgram语音
azure-speech媒体
runway记忆
active-memory记忆
memory-lancedb记忆
memory-wiki开发
github-copilotSDK 包(packages/)
sdk
packages/sdk/
Core SDK,外部工具和脚本集成 OpenClaw 的主要入口
plugin-sdk
packages/plugin-sdk/
插件开发 SDK,封装插件与 Core 通信的全部公共 API
plugin-package-contract
packages/plugin-package-contract/
插件包契约定义:Manifest 格式、能力声明、版本兼容性规范
memory-host-sdk
packages/memory-host-sdk/
Memory Host 接入 SDK,供 memory-lancedb / memory-wiki 等扩展记忆插件实现标准接口
完整文件结构
📁 openclaw/ — 仓库根目录
openclaw/
src/ TypeScript 核心源码(~60 模块)
ui/ Control UI / Web 管理面板
docs/ 文档
deploy/ 部署脚本
security/ · qa/ · test/
package.json · pnpm-workspace.yaml
docker-compose.yml · Dockerfile
fly.toml · render.yaml 云部署配置
.crabbox.yaml Build 配置
README.md · AGENTS.md · VISION.md · SOUL.md
entry.ts CLI 入口,compile cache + respawn
runtime.ts 运行时环境配置
globals.ts / global-state.ts 全局状态
gateway/ WebSocket 服务器,控制平面
routing/ 多 Agent 路由
flows/ 工作流编排(Doctor/Setup)
plugin-sdk/ 公共 API Barrel
mcp/ Model Context Protocol
tts/ 语音合成接口
web-search/ · web-fetch/ 搜索 + 抓取
cli/ · tui/ CLI + 终端界面
image-generation/ · video-generation/
commands/ · tasks/ · chat/
sessions/ · hooks/ · security/
extensions/ 捆绑插件(LLM/渠道/工具)
runtime.ts 运行时环境配置
globals.ts / global-state.ts 全局状态
gateway/ WebSocket 服务器,控制平面
server/ WS Server 实现
methods/ Gateway 方法处理
protocol/ 协议定义
auth*.ts 认证相关(auth-mode/rate-limit/token)
config-reload*.ts 配置热重载
chat-*.ts Chat 操作(abort/attach/sanitize)
control-ui*.ts 控制面板路由 + CSP
boot.ts / client.ts
agents/ Agent 引擎
methods/ Gateway 方法处理
protocol/ 协议定义
auth*.ts 认证相关(auth-mode/rate-limit/token)
config-reload*.ts 配置热重载
chat-*.ts Chat 操作(abort/attach/sanitize)
control-ui*.ts 控制面板路由 + CSP
boot.ts / client.ts
harness/ 会话运行时
sandbox/ Docker/SSH/OpenShell 沙箱
skills/ Agent 能力模块
tools/ 工具实现
auth-profiles/ 认证配置缓存
spawn-agent.ts Agent 进程管理
bash-executor.ts Bash 执行 + 审批
channels/ 渠道抽象层
sandbox/ Docker/SSH/OpenShell 沙箱
skills/ Agent 能力模块
tools/ 工具实现
auth-profiles/ 认证配置缓存
spawn-agent.ts Agent 进程管理
bash-executor.ts Bash 执行 + 审批
transport/
allowlists/
inbound-event/
message/ · plugins/
status/ · turn/
memory/ Markdown 记忆系统allowlists/
inbound-event/
message/ · plugins/
status/ · turn/
routing/ 多 Agent 路由
flows/ 工作流编排(Doctor/Setup)
plugin-sdk/ 公共 API Barrel
mcp/ Model Context Protocol
tts/ 语音合成接口
web-search/ · web-fetch/ 搜索 + 抓取
cli/ · tui/ CLI + 终端界面
image-generation/ · video-generation/
commands/ · tasks/ · chat/
sessions/ · hooks/ · security/
anthropic/ · openai/ · google/ LLM
slack/ · discord/ · telegram/ 渠道
memory-core/ · memory-lancedb/ 记忆
elevenlabs/ · deepgram/ 语音
firecrawl/ · brave/ · google-search/
packages/ SDK 包
slack/ · discord/ · telegram/ 渠道
memory-core/ · memory-lancedb/ 记忆
elevenlabs/ · deepgram/ 语音
firecrawl/ · brave/ · google-search/
sdk/ · plugin-sdk/ · plugin-package-contract/ · memory-host-sdk/
apps/ 伴侣应用
macos/ · macos-mlx-tts/ · ios/ · android/ · swabble/
shared/OpenClawKit/ 跨平台共享框架
skills/ 内置 Skill 定义(SKILL.md)shared/OpenClawKit/ 跨平台共享框架
ui/ Control UI / Web 管理面板
docs/ 文档
deploy/ 部署脚本
security/ · qa/ · test/
package.json · pnpm-workspace.yaml
docker-compose.yml · Dockerfile
fly.toml · render.yaml 云部署配置
.crabbox.yaml Build 配置
README.md · AGENTS.md · VISION.md · SOUL.md
关键依赖
🟩 运行时
- ▸Node.js 24 + tsx — TypeScript 直接执行,无编译步骤
- ▸pnpm workspace — Monorepo 包管理
- ▸vitest — 单元/集成测试
🌐 网络通信
- ▸WebSocket (ws) — Gateway 核心通信,port 18789
- ▸fetch API — LLM 流式调用(内置 Node 24)
- ▸各渠道 SDK — Telegram Bot / Discord.js / Slack Bolt…
🤖 AI/LLM
- ▸@anthropic-ai/sdk — Claude 流式推理
- ▸openai — GPT / o 系列
- ▸@google/generative-ai — Gemini
- ▸ollama — 本地模型(可选)
🛠️ 工具链
- ▸Docker SDK — 沙箱容器执行
- ▸node-ssh — SSH 沙箱后端
- ▸oxlint — 极速 JS/TS Linter
- ▸mlx-tts — macOS 本地 TTS(Apple Silicon)