前言¶
在 DSH 裏跑 agent 時,工具調用間歇性失敗很常見:網絡抖動、限流、權限或下游服務掛掉。單次會話裏模型還能從當輪錯誤裏調整,但會話結束後這些經歷不會自動帶到下一輪。新會話再次選中同一個「慢性失靈」的工具,就會重複燒回合。
cost-meter、token-heatmap、devtools 等插件更偏向 token、成本與開發者側排查;dsh-tool-health 把視角放在工具執行歷史上:記下每次落地的結果,統計近幾天的成功率與延遲,並在下一輪會話的系統提示裏列出高失敗率工具,讓模型先繞開或先查依賴。本文按倉庫 README 與實測記錄說明其定位、安裝與用法。
這是什麼¶
dsh-tool-health(npm 包名 @uppercrusteve/dsh-tool-health)是 DSH 宿主端插件,當前版本 v0.1.0,零 npm 依賴。維護者爲 uppercrusteve,許可證 MIT。分類上可歸入「記憶」類能力:持久化的是工具健康度歷史,而不是對話內容。
數據落在 $DSH_HOME/tool-health/history.json(DSH_HOME 未設時回退 ~/.dsh)。每條記錄爲 {tool, ok, ms, errorClass, err?},不寫入參值;錯誤摘錄不超過 240 字符。
核心功能¶
觀測與分類¶
插件監聽官方 tools/result 事件記錄執行結果,並通過 tools/execute 環繞分發做計時。錯誤類別用純文本啓發式劃分爲:success、timeout、network、rate-limit、permission、unknown。
歷史按工具名滾動:默認只看近 windowDays 天,單工具最多保留 maxEntriesPerTool 條。
慢性失敗預警(系統提示注入)¶
默認判定規則(可通過 patch 配置調整):在 warnWindowDays(默認 3 天)內,某工具失敗次數 ≥ warnMinFailures(默認 5)且失敗率 ≥ warnMinRate(默認 0.3),即視爲慢性高失敗。
滿足條件時,在系統提示段 plugin:tool-health(order 218)注入一行,例如:
⚠ tool-health: 近期高失敗率工具 foo(62%) bar(41%)——優先改用替代或先檢查其依賴服務。
沒有慢性工具時仍註冊該 section,但 text 爲空串。
面向模型與用戶的接口¶
- 模型工具
tool_health_report({tool?, days?=7}):輸出近若干天的 markdown「體檢表」,含調用數、成功率、錯誤分佈、p50/p95 延遲、最近一次失敗摘錄。 - 模型工具
tool_health_reset({confirm:true}):confirm不爲true時拒絕,防止誤清;爲true時清空歷史。 - Slash 命令
/tool-health:與 report 同源的近 7 天摘要。 - HTTP
GET /dsh-tool-health/summary:JSON,含近 7 天每工具統計、慢性名單與配置回顯,供後續 UI 集成。
重試策略在 v0.1 僅作觀測標註:retryPolicy: v0.1-observe-only,不自動重試。
啓動日誌¶
apply 成功後 stdout 會有一行類似:
[tool-health] apply ok windowDays=14 warnMinFailures=5 warnMinRate=0.3 toolsSeen=N chronic=K configSource=... services=tools:yes,systemPrompt:yes,commands:...,webServer:...
可選設置環境變量 DSH_TOOLHEALTH_LOG=<file.jsonl> 輸出結構化取證日誌。
安裝與啓用¶
插件通過 profile 的 package.json 記入依賴與 dsh.profile.bundles;啓動時自動應用 examples/tool-health.bundle.patch.yml 聲明的 patch,一般不需要 再手動加 --patch。
從 GitHub 安裝(README 實測路徑)¶
在 web profile 下執行:
dsh plugin --profile web add github:uppercrusteve/dsh-tool-health
需要可復現構建時鎖定發佈 tag:
dsh plugin --profile web add github:uppercrusteve/dsh-tool-health#v0.1.0
卸載:
dsh plugin --profile web remove @uppercrusteve/dsh-tool-health
從 npm 安裝¶
預覽期安裝需顯式使用 @preview 標籤(README 記錄首發爲 0.1.0):
dsh plugin --profile web add @uppercrusteve/dsh-tool-health@preview
裝前可用 npm view @uppercrusteve/dsh-tool-health dist-tags 覈對;新包發佈後公共讀端點偶有短暫 404,稍後重試即可。
開發期免安裝 patch¶
迭代時可對隔離的 DSH_HOME 用 dev patch 文件啓動(路徑須爲 file:/// 絕對 URL,詳見倉庫 examples/tool-health.dev-fileurl.patch.yml)。
典型用法¶
1、安裝並啓動帶 web profile 的 DSH 宿主,確認日誌出現 [tool-health] apply ok,且 GET /dsh-tool-health/summary 返回 200。
2、正常使用 agent 調用各類工具;插件在每次工具執行落定後異步寫入歷史(落盤防抖默認 ≥1s)。
3、新開一輪會話時,若存在慢性高失敗工具,系統提示中會出現 tool-health 警告行,模型應優先換替代工具或檢查依賴。
4、需要明細時,在對話中讓 agent 調用 tool_health_report,或在界面執行 /tool-health;運維或自研 UI 可輪詢 GET /dsh-tool-health/summary。
5、要清空統計時,僅當明確需要再執行 tool_health_reset({confirm:true}),或直接刪除 history.json。
配置項¶
配置通過 bundle patch 的 config: 塊傳入(未識別鍵會被忽略;插件不導出 standard-schema 式 Config):
| 鍵 | 默認 | 說明 |
|---|---|---|
windowDays |
14 | 歷史滾動窗口(天,1–90) |
warnWindowDays |
3 | 慢性判定窗口(天) |
warnMinFailures |
5 | 慢性判定最少失敗次數(≥) |
warnMinRate |
0.3 | 慢性判定最低失敗率(≥) |
maxEntriesPerTool |
500 | 每工具條數上限(50–5000) |
flushDebounceMs |
1000 | 落盤防抖下限(≥1000) |
適用場景與注意¶
適合:長期在 DSH 上跑工具密集型 agent,希望跨會話積累「哪幾個工具經常壞」的經驗,並在新會話開頭自動提醒模型。
數據與隱私:唯一持久文件爲 history.json;損壞時會被重命名爲 history.json.corrupt-<ts> 後重建,不中斷宿主。
權限與安全:插件以當前 DSH 進程權限讀寫本地 DSH_HOME;安裝前請自行查看 GitHub 源碼 與 MIT 許可證,確認符合你的環境策略。CI 僅做語法、清單與 npm pack 檢查,無法在流水線裏替代真機宿主行爲驗證。
生態說明:DSH 社區插件目錄由獨立站點維護,與 DeepSeek / 幻方無官方從屬關係;本文安裝命令與行爲描述均以倉庫 README 及其中記載的 Windows 實測爲準。
結尾¶
dsh-tool-health 把工具執行的成敗、耗時與錯誤類型沉澱成本地歷史,用慢性失敗規則驅動系統提示預警,並用 report、slash 與 HTTP 摘要三種方式暴露同一份統計。需要安裝或 issue 跟蹤可訪問社區目錄頁與 GitHub 倉庫:
- 目錄頁:https://www.skillhub.cn/plugins/uppercrusteve/dsh-tool-health
- 源碼:https://github.com/uppercrusteve/dsh-tool-health