上下文
「Context」是 OpenClaw 在一次執行中送給模型的所有內容。它受限於模型的 context window(權杖上限)。 「Context」是 OpenClaw 在一次執行中送給模型的所有內容。它受限於模型的 context window(權杖上限)。 It is bounded by the model’s context window (token limit). 新手心智模型:- System prompt(由 OpenClaw 建立):規則、工具、Skills 清單、時間/執行期資訊,以及注入的工作區檔案。
- Conversation history:此工作階段中你的訊息 + 助手的訊息。
- Tool 呼叫/結果 + 附件:指令輸出、檔案讀取、影像/音訊等。
快速開始(檢視 context)
/status→ 快速查看「我的視窗用了多少?」+ 工作階段設定。/context list→ 注入了哪些內容 + 大致大小(每個檔案 + 總計)。/context detail→ 更深入的拆解:每個檔案、每個工具 schema 的大小、每個 skill 條目的大小,以及 system prompt 的大小。/usage tokens→ 在一般回覆後附加每次回覆的使用量頁尾。/compact→ 將較舊的歷史摘要成精簡條目以釋放視窗空間。
範例輸出
實際數值會依模型、提供者、工具政策,以及你的工作區內容而異。/context list
/context detail
什麼會計入 context window
模型接收到的一切都會計入,包括:- System prompt(所有區段)。
- Conversation history。
- Tool 呼叫 + Tool 結果。
- Attachments/transcripts (images/audio/files).
- Compaction 摘要與修剪產物。
- 提供者的「包裝器」或隱藏標頭(不可見,但仍會計入)。
OpenClaw 如何建構 system prompt
System prompt 由 OpenClaw 持有,且每次執行都會重建。內容包含: It includes: It includes:- 工具清單 + 簡短描述。
- Skills 清單(僅中繼資料;見下文)。
- 工作區位置。
- 時間(UTC + 若有設定則轉換為使用者時間)。
- Runtime metadata (host/OS/model/thinking).
- 在 Project Context 下注入的工作區啟動檔案。
注入的工作區檔案(Project Context)
預設情況下,OpenClaw 會注入一組固定的工作區檔案(若存在):AGENTS.mdSOUL.mdTOOLS.mdIDENTITY.mdUSER.mdHEARTBEAT.mdBOOTSTRAP.md(僅首次執行)
agents.defaults.bootstrapMaxChars 進行截斷(預設 20000 個字元)。/context 會顯示 原始 vs 注入 的大小,以及是否發生截斷。 /context shows raw vs injected sizes and whether truncation happened. OpenClaw 亦會透過 agents.defaults.bootstrapTotalMaxChars(預設 24000 字元)對所有檔案的 bootstrap 注入總量進行上限限制。 /context shows raw vs injected sizes and whether truncation happened.
Skills:注入的內容 vs 隨需載入
System prompt 會包含精簡的 skills 清單(名稱 + 描述 + 位置)。這份清單具有實際的負擔。 This list has real overhead. This list has real overhead. Skill instructions are not included by default. Skill 的指示 預設不會 包含。模型被期望在 需要時 才read 該 skill 的 SKILL.md。
Tools:有兩種成本
Tools 以兩種方式影響 context:- System prompt 中的 Tool 清單文字(你看到的「Tooling」)。
- Tool schemas (JSON). These are sent to the model so it can call tools. They count toward context even though you don’t see them as plain text.
/context detail 會拆解最大的 tool schema,讓你看出主要佔用來源。
指令、指示詞與「行內捷徑」
Slash commands 由 Gateway 閘道器 處理,行為略有不同: Slash commands 由 Gateway 閘道器 處理,行為略有不同: There are a few different behaviors:- 獨立指令:只包含
/...的訊息會以指令執行。 - 指示詞:
/think、/verbose、/reasoning、/elevated、/model、/queue會在模型看到訊息前被移除。- Directive-only messages persist session settings.
- 一般訊息中的行內指示詞會作為每則訊息的提示。
- 行內捷徑(僅允許清單中的寄件者):一般訊息中的某些
/...token 可立即執行(例如:「hey /status」),並在模型看到剩餘文字前被移除。
Sessions, compaction, and pruning (what persists)
跨訊息會保留哪些內容取決於所使用的機制:- 一般歷史紀錄會保留在工作階段逐字稿中,直到依政策進行壓縮/裁剪。
- Compaction 會將摘要持續寫入逐字稿,並保留近期訊息。
- Pruning 會從單次執行的 記憶體中 prompt 移除舊的 tool 結果,但不會改寫逐字稿。
/context 實際回報的是什麼
/context 在可用時,偏好最新的 以執行建構 的 system prompt 報告:
System prompt (run)= 從最近一次嵌入式(具工具呼叫能力)執行中擷取,並保存在工作階段儲存區中。System prompt (estimate)= 當不存在執行報告時即時計算(或透過不產生報告的 CLI 後端執行時)。