前面拆了 AGENTS.md(Day8)、Skills(Day10)、工具(Day12)。這些東西最後都會匯集到同一個地方:system prompt。今天把它整份打開來看。
Day6 提過一件事:session 記錄裡看不到 system prompt。它在迴圈開始前就被組好,每一輪都跟著送出去,但不會被存進 .jsonl。所以要看它長什麼樣子,得直接叫 Pi 自己把它組出來。
以下是預設狀態(開 read/bash/edit/write 四個工具、沒有 AGENTS.md、沒有 skills)下,Pi 送出去的完整 system prompt。我只把路徑裡的家目錄換成 <家目錄>,其餘一字未改:
You are an expert coding assistant operating inside pi, a coding agent harness. You help users by
reading files, executing commands, editing code, and writing new files.
Available tools:
- read: Read file contents
- bash: Execute bash commands (ls, grep, find, etc.)
- edit: Make precise file edits with exact text replacement, including multiple disjoint edits in one call
- write: Create or overwrite files
In addition to the tools above, you may have access to other custom tools depending on the project.
Guidelines:
- Use bash for file operations like ls, rg, find
- Use read to examine files instead of cat or sed.
- You can inspect PI_* environment variables for current model and session details.
- Use edit for precise changes (edits[].oldText must match exactly)
- Use write only for new files or complete rewrites.
- Be concise in your responses
- Show file paths clearly when working with files
Pi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):
- Main documentation: <家目錄>\...\pi-coding-agent\README.md
- Additional docs: <家目錄>\...\pi-coding-agent\docs
- Examples: <家目錄>\...\pi-coding-agent\examples (extensions, custom tools, SDK)
- When reading pi docs or examples, resolve docs/... under Additional docs and examples/... under Examples,
not the current working directory
- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md),
skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md),
keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md),
adding models (docs/models.md), pi packages (docs/packages.md), environment variables (docs/environment-variables.md)
- When working on pi topics, read the docs and examples, and follow .md cross-references before implementing
- Always read pi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)
Current working directory: D:/work/taskapp
28 行、2,198 個字元,換算大約五百多個 token。一個能自己讀檔、跑指令、改程式碼的 coding agent,指令部分就這麼多。
| 區塊 | 內容 | 誰決定 |
|---|---|---|
| 開場一句 | 你是誰、在什麼東西裡面跑 | 寫死 |
| Available tools | 每個工具一行的 snippet | 當下開了哪些工具 |
| Guidelines | 怎麼用這些工具的規則 | 工具自己帶的 + 動態加的 |
| Pi documentation | Pi 自己的文件在哪 | 安裝路徑 |
| Current working directory | 工作目錄 | 執行時決定 |
有 AGENTS.md 的話,<project_context> 會接在 Guidelines 之後;有 skills 的話,<available_skills> 再接在後面;最後才是工作目錄那一行。
看 Guidelines 的第一行:
- Use bash for file operations like ls, rg, find
這行不是寫死的。原始碼裡它只有在「有 bash,但沒開 grep/find/ls」的時候才會加進去:
if ((hasBash || hasPowerShell) && !hasGrep && !hasFind && !hasLs) {
addGuideline("Use bash for file operations like ls, rg, find");
}
同樣的道理,工具清單只列出「呼叫端有提供 snippet」的工具;skills 區塊只有在 read 工具開著時才會出現(Day10 提過)。
這就是 harness engineering 的一個具體樣貌:prompt 不是一份文件,是一個函式。輸入是「這次開了哪些能力」,輸出是「該告訴模型什麼」。能力不存在就不要提,提了只會讓模型嘗試不存在的東西;能力存在但不明顯,就補一行提示。
Day13 的實驗之所以不只是「多兩個工具」這麼單純,原因也在這裡——開啟 grep/find/ls 會同時移除那行「用 bash 做檔案操作」的提示。變的不只是工具清單,還有指令本身。
system prompt 每一輪都會重送,聽起來很貴。但實際量一下就會發現它不是大頭。
用第一輪校準的資料來看(gpt-5.6-luna,30 次執行):
AGENTS.md 之後變成 1,474~1,525 tokens。兩者相減,那份 1,145 字元的 AGENTS.md 值 354 個 token——五個任務量出來都是 354,一個不差。換句話說:system prompt 只在第一輪佔比高,之後迅速被對話歷史稀釋。 真正把成本推上去的是「每一輪把目前為止讀過的檔案、跑過的指令結果整包重送」。
把 30 次執行的成本拆開來更清楚:
| 項目 | tokens | 成本 | 佔比 |
|---|---|---|---|
| 輸入(未命中快取) | 537,224 | $0.107 | 63% |
| 輸出(含 reasoning) | 36,154 | $0.043 | 26% |
| 輸入(命中快取) | 953,344 | $0.019 | 11% |
有兩件事值得記住:
如果你想壓低一個 coding agent 的成本,從這份資料看,優先順序應該是:
read 的截斷、bash 輸出的上限(Day12)都是在做這件事。這也是為什麼 Day15 那個「把 system prompt 加料」的實驗,我事前的預期是成本影響很小——加料加在最前面,反而是最容易被快取的位置。
Day15 是這系列的第一個「彈性格」:把額外的指令灌進 system prompt,和原版比較。我會先寫下事前預測,再看資料是不是打臉。