sequenceDiagram
autonumber
title OpenClaw 消息处理时序图
participant User
participant Channel
participant Gateway
participant CommandQueue as Command Queue
participant AgentRuntime as Agent Runtime (L1-L4)
participant Model as Model (LLM)
participant ToolExecutor as Tool Executor
participant EventSubscriber as Event Subscriber
participant Persistence as Persistence (JSONL)
User->>Channel: 发送消息
Channel->>Gateway: 转发消息
Gateway->>CommandQueue: 消息入队 (collect/steer/followup)
CommandQueue->>AgentRuntime: agent.wait() 触发执行
Note over AgentRuntime: L1: runReplyAgent\nL2: runAgentTurnWithFallback\nL3: runEmbeddedPlAgent\nL4: runEmbeddedAttempt
AgentRuntime->>Model: 构建 Prompt (上下文+技能)
Model->>AgentRuntime: 返回决策 (文本/工具调用)
alt 直接回复
AgentRuntime->>EventSubscriber: 流式事件 (assistant)
Note over AgentRuntime: buildReplyPayloads()
EventSubscriber->>User: 返回最终回复
else 工具调用
AgentRuntime->>ToolExecutor: 执行工具
ToolExecutor->>AgentRuntime: 返回工具结果
AgentRuntime->>Model: 注入结果, 再次推理
Model->>AgentRuntime: 返回最终文本
AgentRuntime->>EventSubscriber: 流式事件 (assistant)
Note over AgentRuntime: buildReplyPayloads()
EventSubscriber->>User: 返回最终回复
end
AgentRuntime->>Persistence: 会话持久化 (.JSONL)
Persistence->>AgentRuntime: 持久化完成
OpenClaw也是用Reasoning and Acting(推理与行动)模式。
计算执行方式activeRunQueueAction
判断条件
activeRunQueueAction
当前无活跃运行?
run-now
typingSignals打字信号
心跳消息
drop
应该后续执行 OR messages.queue “steer”
enqueue-followup
messages.queue默认是collect
默认
run-now
LLM交互案例
INPUT
SYSTEM
SYSTEM 系统角色 / System Prompt,AI 的 “身份说明书” 和 “行为准则”,由开发者设定,是整个对话的「总纲领」。
定义 AI 的角色、任务、回答风格、约束条件(比如 “你是一个专业的天气助手,只回答北京的天气问题,用口语化表达”)。
给模型设定上下文背景、规则、格式要求,全程约束模型的输出。
只在对话开头出现一次(或少数几次),不会由用户输入。
You are a personal assistant running inside OpenClaw.
## Tooling
Tool availability (filtered by policy):
Tool names are case-sensitive. Call tools exactly as listed.
- read: Read file contents
- write: Create or overwrite files
- edit: Make precise edits to files
- exec: Run shell commands (pty available for TTY-required CLIs)
- web_search: Search the web
- web_fetch: Fetch and extract readable content from a URL
HUMAN&AI
HUMAN。human(用户角色 / Human Message),真实用户的提问 / 输入,代表用户的需求、问题、补充信息,是模型需要响应的核心输入。
---name:weatherdescription:Get current weather and forecasts (no API key required).homepage:https://wttr.in/:helpmetadata:{"clawdbot":{"emoji":"🌤️","requires":{"bins":["curl"]}}}---# Weather
Two free services, no API keys needed.
## wttr.in (primary)
Quick one-liner:
curl -s "wttr.in/London?format=3"
# Output: London: ⛅️ +8°C
Read HEARTBEAT.md if it exists (workspace context). Follow it strictly. Do not infer or repeat old tasks from prior chats. If nothing needs attention, reply HEARTBEAT_OK.
When reading HEARTBEAT.md, use workspace file /data/.openclaw/workspace/HEARTBEAT.md (exact case). Do not read docs/heartbeat.md.
Current time: Tuesday, March 31st, 2026 — 04:15 (UTC) / 2026-03-31 04:15 UTC