可视化
调试
Canvas
OpenClaw Agent 执行过程是「黑盒」的:你发送一个任务,它返回结果,中间发生了什么?调用了哪些工具?执行顺序如何?哪个步骤最耗时?
可视化让你成为「有透视眼」的 Agent 调试者。
# 启动 Canvas 工作流展示
openclaw canvas start \
--mode workflow \
--session my-agent-session \
--port 3000
# 浏览器访问
# http://localhost:3000/canvas
# 会看到实时的工作流执行图:
#
# [用户输入]
# ↓
# [LLM推理] → [工具调用1: web_search]
# ↓
# [工具调用2: read_file]
# ↓
# [LLM整合] → [输出结果]
# 导出工作流为 JSON
openclaw canvas export --session my-session --output workflow.json
# workflow.json 结构
{
"nodes": [
{"id": "node-1", "type": "llm", "label": "推理节点", "duration_ms": 1234},
{"id": "node-2", "type": "tool", "label": "web_search", "duration_ms": 450},
{"id": "node-3", "type": "tool", "label": "read_file", "duration_ms": 89}
],
"edges": [
{"from": "node-1", "to": "node-2"},
{"from": "node-1", "to": "node-3"}
]
}
# 开启会话快照
openclaw session start --agent my-agent \
--enable-snapshots \
--snapshot-interval 10s
# 执行过程中,每 10 秒自动保存一次快照
# 快照包含:完整上下文、工具调用历史、LLM 响应
# 列出所有快照
openclaw time-travel list --session my-session
# 输出:
# snapshot-001 [00:00:10] 上下文: 2.3K tokens
# snapshot-002 [00:00:20] 上下文: 4.1K tokens
# snapshot-003 [00:00:30] 上下文: 6.8K tokens ← 这里出错了
# 回放到指定快照
openclaw time-travel replay --snapshot snapshot-003
# 从快照恢复并调试
openclaw session restore --snapshot snapshot-003 --mode debug
# 现在你可以单步执行、检查变量、修改上下文
# 实时日志流
openclaw logs stream --session my-agent --level debug
# 结构化日志输出
{
"timestamp": "2026-05-22T01:12:33.456Z",
"level": "info",
"agent": "seo-agent",
"event": "tool_call",
"tool": "web_search",
"duration_ms": 234,
"tokens_used": 342,
"context_size": "8.7K"
}
# 生成执行火焰图
openclaw logs flamegraph --session my-agent --output flame.html
# 可视化每个步骤的耗时比例
# 1. 发现问题:Agent 执行超过 5 分钟无响应
openclaw session status --session stuck-agent
# 状态:running, 已运行 5m32s, 无新输出
# 2. 查看实时工作流
openclaw canvas snapshot --session stuck-agent
# 发现:Agent 在 tool_call "web_fetch" 卡住
# 3. 时间旅行回放
openclaw time-travel replay --session stuck-agent --last 60s
# 发现:web_fetch 访问的 URL 返回 403,但 Agent 没有处理错误
# 4. 修复:添加错误处理
# 编辑 skill 配置
openclaw skill edit my-skill \
--add-hook "on_tool_error: retry_with_fallback"
# 5. 从快照恢复
openclaw session restore --snapshot snap-005 --resume
# Agent 从错误点继续执行,问题修复!
妙趣AI | OpenClaw 教程合集 | 最后更新:2026-05-22