目录
- 概览
- 核心组件
- 控制平面
- 网关协议
- 消息路由
- 消息流程
- 启动流程
概览
OpenClaw 是一个多渠道 AI 助手网关,设计用于在用户自己的设备上运行。它采用单一网关 + 多客户端/节点模型,支持 WhatsApp、Telegram、Slack、Discord、Google Chat、Signal、iMessage 等多种通信渠道。
核心结构
| 组件 |
描述 |
| 🌐 Gateway(网关) |
长期运行的守护进程,管理所有消息平台连接和智能体通信 |
| 💻 Clients(客户端) |
控制平面应用(macOS 应用、CLI、Web 界面) |
| 📱 Nodes(节点) |
设备节点,提供硬件能力(macOS/iOS/Android/无头设备) |
整体架构
graph TB
subgraph UserLayer["用户设备层"]
MacApp["macOS 应用"]
IOSApp["iOS 应用"]
AndroidApp["Android 应用"]
CLI["命令行界面"]
WebUI["Web 界面"]
end
subgraph GatewayLayer["网关核心层"]
Gateway["Gateway 网关服务"]
WS["WebSocket 服务器"]
HTTP["HTTP 服务器"]
NodeReg["节点注册表"]
ChannelMgr["渠道管理器"]
end
subgraph ChannelLayer["消息渠道层"]
Telegram["Telegram"]
Slack["Slack"]
Discord["Discord"]
WhatsApp["WhatsApp"]
Signal["Signal"]
GoogleChat["Google Chat"]
OtherChannels["其他渠道..."]
end
subgraph AgentLayer["智能体层"]
AgentSystem["智能体系统"]
Skills["技能系统"]
Memory["记忆系统"]
Providers["AI 提供商"]
end
MacApp --> WS
IOSApp --> WS
AndroidApp --> WS
CLI --> WS
WebUI --> HTTP
WS --> Gateway
HTTP --> Gateway
Gateway --> NodeReg
Gateway --> ChannelMgr
ChannelMgr --> Telegram
ChannelMgr --> Slack
ChannelMgr --> Discord
ChannelMgr --> WhatsApp
ChannelMgr --> Signal
ChannelMgr --> GoogleChat
ChannelMgr --> OtherChannels
Gateway --> AgentSystem
AgentSystem --> Skills
AgentSystem --> Memory
AgentSystem --> Providers
style Gateway fill:#7c3aed,stroke:#5b21b6,color:#fff
style WS fill:#8b5cf6,stroke:#7c3aed,color:#fff
style ChannelMgr fill:#8b5cf6,stroke:#7c3aed,color:#fff
style AgentSystem fill:#10b981,stroke:#059669,color:#fff
架构原则
- 每台主机一个网关实例: 单一职责,避免会话冲突
- 所有通信通过 WebSocket: 使用类型化 API,支持双向通信
- 网关唯一管理平台连接: 避免重复登录,统一状态管理
- 支持多种客户端节点: 通过相同的 WebSocket 协议通信
核心组件
🎛️ Gateway Server(网关服务器)
网关的核心实现,负责协调所有子系统。
位置: src/gateway/server.impl.ts
- 主要职责:
- HTTP 和 WebSocket 服务
- 节点管理和配对
- 渠道生命周期管理
- 智能体会话协调
- 关键子系统:
- 节点注册表
- 渠道管理器
- 会话管理器
- 健康监控器