這一課會完成什麼
- 依 repository task 設計工具輸入,不提供任意 shell escape hatch
- 回傳精簡 typed observation,保留證據但不塞爆 context
- 分開 model-facing repair 與 operator-facing protected diagnostic
- 測成功、invalid、denied、timeout、oversized 與 unknown completion
開始前先準備
- • 模組 01 到 04 的 contract、map、initializer 與 feature ledger
- • 可重播 command、API、database 與 browser outcome 的 local fake adapter
先把定義說清楚
Agent 可讀回饋
Agent-readable tool 是一項有界能力:輸入經 schema 驗證、authority 由 runtime 提供、結果使用 closed union,並指出失敗層與允許的下一步。它不讓模型從數千行 terminal output 猜狀態,也不接受模型自填權限。Context 只收到短 observation 與 evidence ID,完整 redacted log、trace 與 screenshot 留在受保護儲存區,需要時再由明確介面讀取。
Coding agent 依靠環境回饋決定下一步。Command 只回 exit 1、browser runner 把 skipped 當成功,或 API helper 無法區分 denied、timeout 與 partial effect,下一步便只能猜。模型多想幾輪,也無法還原工具丟掉的證據。
General shell 適合探索,重複工作則值得做 narrow surface。具名 check 可以驗正確 route、限制輸出、遮蔽 fixture token、保存 screenshot,並回 stable repair code。Policy 與 evidence 由 application code 控制,agent 則拿到足以行動的 observation。
現場情境
綠色命令掩蓋壞掉的使用者路徑
工具輸出、retry、screenshot 與應用程式狀態都是合成 fixture。
- 負責人
- 你是將 broad shell instruction 改成 task-specific feedback 的 platform engineer。
- 要做的決策
- 哪些工具邊界與 result code 能指出真正失敗層,並讓 agent 選安全下一步?
- 目前狀態
- Agent 每次修改都跑完整 test,輸出超過 context。Command exit zero,但 browser suite 因 binary missing 被 skipped;agent 仍把 request changes 標 verified。
- 預期成果
- Typed check 分開 unit、contract、persistence 與 browser,阻止不支援的修復,所有結論都連 evidence。
限制條件
- • 工具只能作用於當前 environment ID 與 repository allowlist
- • Model-facing result 不得出現 secret、cookie、raw fixture text 或 stack trace
- • Write unknown completion 未 reconcile 前不得 retry
實作範例
CHECK_SKIPPED 擋下一次假完成
證據類型: 具名模擬情境Legacy verify 在 browser 未安裝時回 0,最後一行寫 42 checks passed,前面才提到 browser skipped。Agent 只引用最後一行並將 ledger 改 verified。
新 verify_feature 對每個 required layer 回 closed status。Browser 成為 CHECK_SKIPPED、BROWSER_MISSING、retryable false、nextAction initialize。Transition guard 因 required check 未 PASS 而拒絕 verified。
Initializer 裝好 pinned browser 後,同一工具發現 confirmation 重整便消失。Agent 修 persistence、跑 failing slice,再跑完整 pipeline;receipt 連四層結果、commit、environment 與 screenshot hash。
主張限制
Stable code 能改善控制,不能保證 check 本身代表正確產品行為。Task contract、fixture、權限與 release 後果仍由人負責。
做法
照著做,每一步都有檢查點
現場情境
哪些工具邊界與 result code 能指出真正失敗層,並讓 agent 選安全下一步?
- 01盤點決策與危險捷徑
- 02定義 schema 與 result union
- 03重播 adverse outcomes
驗收條件
Agent 能從精簡 observation 分清 setup、policy、transient、product 與 unknown effect;reviewer 仍可開 evidence 重現結論。
- 01
盤點決策與危險捷徑
沿 baseline 列每個 command、使用者、authority、必要 evidence、輸出量與下一步。標出 general shell、raw log、broad path、hidden skip 與可能重複效果的 write retry。
檢查點 · 每個重複 call 都對到 bounded decision,危險捷徑有外部控制或移除理由。
- 02
定義 schema 與 result union
建立有長度與 path 規則的 closed arguments;分成功、invalid、denied、retryable、unknown、failed。將 compact observation 和 protected evidence 分開,寫清 environment 與 authorization 由哪個 component 派生。
檢查點 · Unknown field、absolute path、任意 command、oversized input 與 model-supplied environment identity 都在執行前被拒。
- 03
重播 adverse outcomes
Fake adapter 依序回 browser missing、migration invalid、evidence denied、transient read timeout、unknown write 與 oversized log,驗 code、retry、evidence、redaction 與 action。
檢查點 · 沒有 case 需要讀 raw terminal;secret 不進 model payload;unknown write 只走 reconciliation。
- 04
跑 fresh-agent selection
給新 session 三個 failure 與 tool catalog,記 chosen tool、arguments、calls、bytes、repair 與 final evidence,使用相同 contract 比較 broad-shell baseline。
檢查點 · Fresh session 選對工具、維持 call ceiling、修到失敗層,也不能靠 skipped check 建 verified。
實務脈絡
展示版之後
從下一個決策倒推結果
列出 call 後允許的行動:continue、repair input、initialize、reconcile、request authority 或 stop。Database check 要分 schema missing、fixture missing、access denied、service unreachable 與 healthy;單一 boolean 不足以支援這些分支。
Payload 只放 status、code、summary、retryable、evidence IDs 與 next action。完整 log、query plan、trace 和 screenshot 放外部儲存。需要深查時,用 read_evidence 取得批准過的 slice,不把所有 terminal volume 重送進模型。
工具說明也是可測介面
名稱與 schema 要說清何時使用、不能做什麼、哪個欄位由誰提供。採 closed enum、長度限制、repository-relative path 與 server-derived environment ID。避免 optional bag,讓任意 command、credential 或 destination 藏在看似普通的 helper。
用保留 task set 測 tool selection,記錯工具、缺 argument、虛構欄位、重複 call 與 recovery。只有 trace 顯示固定誤解才調整名稱或 description;catalog 變更也要跑 regression。
交付補強
工具回傳的 nextAction 是政策允許的集合,不是命令模型一定照做。RETRYABLE 也要帶 retryAfter、最大次數、已用次數與相同 idempotency boundary;DENIED 指向 request_authority 或 stop,不能建議修改 policy file;UNKNOWN 指向 reconcile,不能回 repair 再重送。將這些分支寫成 controller 測試,避免 description 改得再清楚,executor 卻仍把所有非零結果丟回通用 retry。
Result projection 要從下一個決策反推。若 agent 只需要知道 migration 缺少、目前 schema version 與修復命令,就不回完整 database URL、table contents 或 stack trace。Operator evidence 可以包含 redacted phase log、query code 與 runtime versions,但要有 access audit。這種雙層介面既保護 context budget,也避免為了安全而把診斷資訊刪光,最後只能請 agent猜。
Read_evidence 本身也要有窄 scope。Arguments 使用 evidence ID、approved slice type 與 byte ceiling,不接受 arbitrary path 或全文 query。Runtime 驗 caller、task、environment、retention 與資料類別,回傳內容仍視為 untrusted observation,不能提升成 repository instruction。Fixture 應包含一段看似要求關閉 guardrail 的 poisoned log,證明它只停留在 data channel。
Tool catalog 變更要做 diff。新增能力、放寬 schema、提高 output ceiling、改 retry semantics 或 authority source,都可能擴大 agent 行動面。Release receipt 列 old/new schema hash、affected retained cases、selection accuracy、payload tail 與 denied behavior。若只是重新命名,也要確認舊 session 或 generated instructions 沒有留下 stale reference,否則 agent 會持續呼叫不存在工具。
每個錯誤碼要有穩定語意與責任歸屬。輸入不合法由呼叫者修正;環境未就緒回 initializer;權限不足交給 authority owner;暫時性讀取失敗才允許有限重試;寫入結果不明交給 effect reconciliation;產品驗收失敗指向相關測試與檔案範圍。若所有錯誤都回同一段『請稍後再試』,agent 會把架構、權限與資料問題全部當網路波動,造成重複呼叫與錯誤修復。
工具測試應從執行器外側注入惡意與異常輸入。包含跳脫相對路徑、超長字串、未知欄位、偽造環境識別、相似工具名稱、被污染的錯誤訊息、截斷輸出與取消訊號。確認驗證失敗發生在任何檔案、網路或資料操作之前,並且紀錄中不會把被拒內容原樣寫出。這些案例通過只證明目前契約能擋已知手法,工具範圍改變時仍要重新做威脅檢視。
Fresh-session 評估要比較實際決策品質,而不是只看是否呼叫成功。記錄工具選擇是否正確、參數是否一次通過、是否重複查同一證據、收到拒絕後有沒有改走越權路徑、遇 unknown 是否先對帳、最後完成主張是否綁到完整檢查。若窄工具讓呼叫次數略增,卻能消除假完成與危險重試,仍可能是合理取捨;報告要同時呈現成本與控制結果。
工具維護要指定 owner 與相容政策。當執行器改版,舊 schema 的呼叫是明確拒絕、短期轉接或雙版本支援,要在發佈前決定,不能把解析失敗交給 agent 猜。轉接層只處理形狀差異,不可悄悄放寬權限、補入缺少參數或改變重試語意。每次版本切換保留舊版 failure fixtures,確認 stale session 收到可理解的升級訊息,也不會因 fallback 路徑取得更多能力。Operator dashboard 需顯示各版本呼叫量、錯誤碼與淘汰期限,等 consumer 清零後才移除舊介面。
動手實作
將 Release Desk 檢查包成 typed feedback tools
建立 inspect_health、verify_feature、read_evidence 與 reconcile_effect,重播六種 outcome,確認 bounded observation 與 allowed next action。
準備項目
- • 保存 noisy baseline output,記錄 byte 與缺少的 decision field
- • 宣告 environment ID、path allowlist、redaction 與 model payload 上限
本課產出
四個 bounded tool contracts、retained fake adapters、redaction policy、payload report、decision table 與 model/operator evidence sample。
起始模板: Tool observation contract
TypeScripttype ToolObservation = {
status: "PASS" | "FAIL" | "DENIED" | "RETRYABLE" | "UNKNOWN";
code: string;
summary: string;
retryable: boolean;
evidenceIds: string[];
nextAction: "continue" | "repair" | "initialize" | "reconcile" | "request_authority" | "stop";
};可下載的實作檔
Tool observation contract
tool-observation.ts · TypeScript
An editable course fixture for the main lab. Save it inside the Release Desk repository before running the acceptance command.
Run receipt template
he-05-receipt.json · JSON
A compact evidence record for the check, environment, result, and limits that another reviewer must be able to inspect.
驗收指令
npm run harness:tools -- --fixtures fixtures/tool-outcomes.jsonl --max-output 4096預期 receipt
PASS he-05 agent-readable-tools
fixtures=6 stableCodes=6 secretHits=0
unknownWriteRetries=0 verifiedFromSkipped=false預期結果
Agent 能從精簡 observation 分清 setup、policy、transient、product 與 unknown effect;reviewer 仍可開 evidence 重現結論。
留給下一課
後續 mechanical rules、eval、recovery 與 capstone trace 都使用這套 result envelope,不允許用 unrestricted fallback command 繞過。
驗收條件
- 01Argument validation 拒絕 arbitrary command、destination、absolute path、unknown 與 oversized value
- 02六種 fixture 都回 stable code、retryability、evidence IDs 與唯一 allowed action
- 03Model payload 低於 byte limit,沒有 seeded canary 或 raw session material
- 04任何 required check skipped、missing、denied、unknown 或 failed 都不能 verified
常見故障
故障診間
F1Agent 仍一直選 general shell,而不是 task-specific check。
- 先檢查
- 比較 catalog description、argument friction、evidence、selection trace 與 fallback permission。
- 可能原因
- 窄工具沒說清 decision coverage,或 unrestricted shell 比它容易。
- 修復方式
- 補齊 result field 與說明,對該 task class 移除或 policy-gate bypass。
- 下次怎麼避免
- 工具名稱、schema、description 或權限變更就跑 selection fixture。
F2Timeout 後 request changes 被送出兩次。
- 先檢查
- 追 idempotency key、dispatch receipt、effect ledger、status、retry flag 與 reconciliation。
- 可能原因
- 工具把 unknown completion 當成可 retry 的 transport failure。
- 修復方式
- 停止 retry,查 authoritative effect,再從 reconciled outcome resume。
- 下次怎麼避免
- Unknown completion 有獨立 code,write 前後 crash 都要測。
F3Compact feedback 無法診斷新 failure。
- 先檢查
- 打開 evidence ID,確認 correlation、phase、versions 與 safe diagnostic slice 是否保存。
- 可能原因
- Trim 直接刪除證據,沒有分離 observation 與 diagnostic storage。
- 修復方式
- 外部保留完整 redacted evidence,增加 scoped read path。
- 下次怎麼避免
- 同時驗 context budget 與 operator reconstruction。
展示版之後
正式上線前的邊界
- 01Tool purpose、限制、argument schema、authority source 與 terminal outcomes 版本化
- 02Environment、root、scope 與 credential 由 trusted runtime 提供
- 03Model observation typed、bounded、redacted、actionable 並連 protected evidence
- 04Denied、retryable、unknown、failed、skipped 與 passed 在 ledger 中保持不同
- 05Write 使用 idempotency 與 reconciliation,unknown 後不直接 retry
- 06Catalog、schema、adapter 或 policy 變更時跑 retained selection 與 adverse fixture
證據類型
資料來源與主張限制
資料來源只支撐本課標示的主張,不代表換一個系統也會得到相同結果。
- [1]打造有效的 agent採用能通過需求的最簡架構 · workflow 模式 · 環境回饋 · 停止條件
Anthropic · 官方文件 · 2026-08-26
- [2]Harness engineering:在 agent-first 開發環境中運用 Codex知識留在 repository · 讓系統對 agent 可讀 · 機械式規則 · 處理 repository entropy
OpenAI · 公開案例 · 2026-08-26
- [3]Harness Engineering Guide執行環境邊界 · 工具系統 · sandbox · 復原模式
Nexu · 公開案例 · 2026-08-26
- [4]Learn Harness Engineering專案式學習順序 · 五個 harness 子系統 · 迴圈工程 · 工作圖工程
Walking Labs · 公開案例 · 2026-08-26
- [5]長時間應用程式開發的 harness 設計planner、generator、evaluator · 可測合約 · 簡化 harness · 成本取捨
Anthropic · 已發表研究 · 2026-08-26
延伸的 Tenten 資源