语境
上下文:模型看到什么、如何构建以及如何检查它
"上下文"是OpenClaw 发送到模型进行运行的所有内容。它受到模型的上下文窗口(令牌限制)的限制。
初学者心理模型:
- 系统提示(OpenClaw构建):规则、工具、技能列表、时间/运行时和注入的工作区文件。
- 对话历史记录:您的消息 + 助理在本次会话中的消息。
- ''工具调用/结果+附件'':命令输出、文件读取、图像/音频等。'
''
'上下文与"内存"不同:内存可以存储在磁盘上并稍后重新加载;上下文是模型当前窗口内的内容。
快速启动(检查上下文)
- ''/status'' → 快速"我的窗口有多满?"视图+会话设置。
- ''/context list'' → 注入内容 + 粗略大小(每个文件 + 总数)。
- ''/context detail'' → 更深入的细分:每个文件、每个工具架构大小、每个技能条目大小和系统提示大小。
- ''/usage tokens'' → 将每个回复的使用页脚附加到正常回复中。
- ''/compact'' → 将较旧的历史记录总结为一个紧凑的条目以释放窗口空间。
输出示例
值因型号、提供商、工具策略以及工作区中的内容而异。
`/context list`
🧠 Context breakdown Workspace: '<workspaceDir>' Bootstrap max/file: 20,000 chars Sandbox: mode=non-main sandboxed=false System prompt (run): 38,412 chars (~9,603 tok) (Project Context 23,901 chars (~5,976 tok)) Injected workspace files: - AGENTS.md: OK | raw 1,742 chars (~436 tok) | injected 1,742 chars (~436 tok) - SOUL.md: OK | raw 912 chars (~228 tok) | injected 912 chars (~228 tok) - TOOLS.md: TRUNCATED | raw 54,210 chars (~13,553 tok) | injected 20,962 chars (~5,241 tok) - IDENTITY.md: OK | raw 211 chars (~53 tok) | injected 211 chars (~53 tok) - USER.md: OK | raw 388 chars (~97 tok) | injected 388 chars (~97 tok) - HEARTBEAT.md: MISSING | raw 0 | injected 0 - BOOTSTRAP.md: OK | raw 0 chars (~0 tok) | injected 0 chars (~0 tok) Skills list (system prompt text): 2,184 chars (~546 tok) (12 skills) Tools: read, edit, write, exec, process, browser, message, sessions_send, … Tool list (system prompt text): 1,032 chars (~258 tok) Tool schemas (JSON): 31,988 chars (~7,997 tok) (counts toward context; not shown as text) Tools: (same as above) Session tokens (cached): 14,250 total / ctx=32,000
`/context detail`
🧠 Context breakdown (detailed) … Top skills (prompt entry size): - frontend-design: 412 chars (~103 tok) - oracle: 401 chars (~101 tok) … (+10 more skills) Top tools (schema size): - browser: 9,812 chars (~2,453 tok) - exec: 6,240 chars (~1,560 tok) … (+N more tools)
什么对上下文窗口有影响
模型收到的所有内容都很重要,包括:
Skill instructions are _not_ included by default. The model is expected to ''read'' the skill's ''SKILL.md'' **only when needed**.
- 对话历史记录。
- 工具调用+工具结果。
- 附件/脚本(图像/音频/文件)。
- 压缩摘要和修剪工件。'
'- 提供者"包装器"或隐藏标头(不可见,仍然计数)。
OpenClaw 如何构建系统提示符
系统提示是OpenClaw-owned并在每次运行时重建。它包括:
- 工具列表+简短描述。
- 技能列表(仅元数据;见下文)。
''/context detail'' breaks down the biggest tool schemas so you can see what dominates.
- 时间(UTC + 转换后的用户时间(如果配置))。
- 运行时元数据(主机/操作系统/模型/思维)。
- 在''项目上下文''下注入工作区引导文件。'
''
'完整故障:''系统提示''。
注入的工作区文件(项目上下文)
默认情况下,OpenClaw 注入一组固定的工作区文件(如果存在):
- ''/...''
- **Directives**: ''/think'', ''/verbose'', ''/reasoning'', ''/elevated'', ''/model'', ''/queue'' are stripped before the model sees the message.
- Directive-only messages persist session settings.
- Inline directives in a normal message act as per-message hints.
- ''/...''
Details: [Slash commands](/tools/slash-commands).
- ''BOOTSTRAP.md''(仅限首次运行)'
''
'使用 ''agents.defaults.bootstrapMaxChars'' (默认 ''20000'' 字符)按文件截断大文件。 ''/context'' 显示''原始大小与注入''大小以及是否发生截断。
技能:注入内容与按需加载内容
跨消息持久化的内容取决于机制:
ReferenceConceptsContextPage step 08: P2
工具:有两种成本
''/context'' prefers the latest **run-built** system prompt report when available:
- ''System prompt (run)'' = captured from the last embedded (tool-capable) run and persisted in the session store.
2. ''工具架构'' (JSON)。这些被发送到模型,以便它可以调用工具。即使您不将它们视为纯文本,它们也会计入上下文。'
''
'''System prompt (estimate)'' 分解了最大的工具模式,以便您可以看到什么占主导地位。
命令、指令和"内联快捷方式"
斜杠命令由网关处理。有几种不同的行为:
- ''独立命令'':仅 ''/...'' 的消息作为命令运行。
- ''指令'':''/think''、''/verbose''、''/reasoning''、''/elevated''、''/model''、''/queue'' 在模型看到消息之前被删除。
- 仅指令消息保留会话设置。
- 普通消息中的内联指令充当每条消息的提示。
- ''内联快捷方式''(仅限列入白名单的发件人):普通消息中的某些 ''/...'' 标记可以立即运行(例如:"hey /status"),并在模型看到剩余文本之前被删除。'
''
'详细信息:''斜线命令''。
会话、压缩和修剪(持续存在的内容)
消息之间持续存在的内容取决于机制:
- 正常历史记录保留在会话记录中,直到被策略压缩/修剪。
- 压缩 将摘要保留到记录中,并保持最近的消息完整。
- ''修剪'' 从运行的_内存_提示中删除旧的工具结果,但不会重写记录。'
''
'文档:''会话''、''压缩''、''会话修剪''。
`/context` 实际报告的内容
''/context'' 更喜欢最新的 ''运行构建'' 系统提示报告(如果可用):
- ''System prompt (run)'' = 从上次嵌入式(支持工具)运行捕获并保留在会话存储中。
- ''System prompt (estimate)'' = 当不存在运行报告时(或通过不生成报告的 CLI 后端运行时)动态计算。
无论哪种方式,它都会报告规模和主要贡献者;它不转储完整的系统提示或工具架构。