前言¶
在 DeepSeek Harness(DSH)裏跑 agent 時,有時會出現一輪迴復什麼都沒有做,界面卻直接顯示「已完成」,思考也停了。上游 API 的結束原因明明是工具調用(stop_reason=tool_use),消息裏卻沒有 tool-call 塊,也沒有正文匯報。這不是模型主動收尾,而是 agent-loop 把殘缺響應當成正常結束。維護者 Paradox1278 的插件 dsh-empty-turn-guard 掛在官方擴展點上,在輪次即將關閉時介入,把「靜默完成」改回「繼續執行」。下面介紹它針對的問題、判定方式、安裝與配置。
這是什麼¶
dsh-empty-turn-guard 是 DSH 工作流類插件,倉庫 Paradox1278/dsh-empty-turn-guard,當前包版本 0.4.0,MIT 許可證,需 Node ≥22,peer 依賴 cordis ≥4.0.0-rc.8 <5。社區目錄頁:skillhub.cn 上的插件條目(獨立站點,與 DeepSeek / 幻方無官方從屬關係)。
一句話:檢測「上游聲稱 tool-calls 結束,卻一個 tool-call 都沒發」的 attempt,通過 agent.steer 往 inbox 注入補救消息,使輪次繼續,而不是寫出 turn/end { kind: "completed" }。
問題從哪來¶
README 裏逐行核過的根因鏈如下。
dsh-llm-deepseek把上游stop_reason: "tool_use"翻譯成{ kind: "tool-calls" }。dsh-agent-loop只看消息裏有沒有 tool-call 塊;沒有則return { kind: "completed" }。- 隨後寫出
turn/end { kind: "completed" },界面顯示完成。
「結束原因是工具調用」在 agent-loop 裏被丟掉,沒有 tool-call 也不報錯。
作者在 12 個會話、817 個 assistant step 上統計:finish=tool-calls 但無 tool-call 塊共 57 次(7.0%);其中僅 reasoning 塊佔 75%,完全空塊 19%,僅正文 text 5%。因此不能只看「內容塊數量」,必須判斷:上游說 tool-calls,到底有沒有發出 tool-call。
核心功能¶
擴展點與修復思路¶
不改 app.asar,只用公開擴展點:
| 擴展點 | 用途 |
|---|---|
agent/assistant-stream |
觀察 attempt 的 start / chunk / end,統計內容塊與 tool-call 塊,記錄 finish.reason.kind |
agent/turn-stopping |
輪次即將關閉、loop 尚未 break 時介入 |
agent.steer(msg) |
往 inbox.next-step 塞消息,使第二道判空失效,輪次繼續 |
classifyAttempt 判定(摘自 README):
end.outcome.kind === 'committed'(報錯 / 取消 / abandoned 不救)- 且滿足其一:
contentBlocks === 0(除 usage/finish 外零塊),或finishKind === 'tool-calls'且toolCallBlocks === 0 - 當前
turn-stopping的 turn 與殘缺 attempt 的 turn 相同
安全與默認行爲¶
- 默認關閉:
enabled默認false,須顯式enabled: true才註冊監聽。 - 異常吞掉:監聽器內 try/catch,只記日誌,不打斷正常輪次。
- 0.4.0 起不限次數補救:每一次「沒有有效輸出」都注入,直到模型發出 tool-call 或寫出正文;停止條件是「模型恢復產出」,不是次數閾值。僅
absoluteLimit(默認 10000)防判定邏輯死循環;設爲0可關掉這道閘。 - 用戶中斷優先:
signal.aborted爲真時不復活輪次。 - 零副作用:純內存 WeakMap,不寫文件、不髮網絡、不額外申請權限。
安裝與啓用¶
本包不在 npm registry,README 推薦離線 zip 或在本機源碼目錄用安裝腳本寫入 profile,而不是 dsh plugin add github:... 這類憑名稱拼接的命令。
A. 分發包(跨機器 / 多客戶端)¶
在開發機打包:
powershell -NoProfile -ExecutionPolicy Bypass -File .\build-package.ps1
# -> .\dist\dsh-empty-turn-guard-v0.4.0.zip
解壓後任選其一:
# Windows:雙擊 install.cmd,或
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1 -ProfileDir "<profile>"
# Windows / Linux / macOS(Node 22+)
node install.mjs
node install.mjs --profile ~/.dsh/profiles/desktop
安裝器探測 profile(DSH_HOME\profiles\* 優先,其次 ~/.dsh/profiles/*);多 profile 須顯式指定。完成後重啓 DSH。
B. 源碼目錄直接裝¶
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\install.ps1
.\install.ps1 -ProfileDir "D:\x"
.\install.ps1 -Uninstall
與 install.mjs 等價:備份 manifest → 複製到 <profile>/vendor/dsh-empty-turn-guard → 建立 node_modules 解析入口 → 登記 dependencies 與 dsh.profile.bundles → 更新 cordis.patch.yml。
重啓前建議:
node preflight.mjs
exit 0 再重啓,避免 profile 清單 BOM 等問題導致宿主啓動失敗。
升級¶
推薦雙擊 run-sync.cmd(等價 sync-latest.ps1)。看到 VERDICT: OK -- empty-turn-guard 0.4.0 deployed (unlimited mode) 後重啓 DSH。手動升級時注意 patch 裏 maxConsecutiveEmptySteps、maxRemediesPerTurn、maxRemediesPerAgent 須同時爲 0,否則仍是舊版限流行爲。
配置示例¶
在 profile 的 cordis.patch.yml 中插入插件塊,例如:
- insert:
- id: dsh-empty-turn-guard
name: dsh-empty-turn-guard
config:
enabled: true
maxConsecutiveEmptySteps: 0
maxRemediesPerTurn: 0
maxRemediesPerAgent: 0
absoluteLimit: 10000
log: true
steerText: '[empty-turn-guard] 上一步沒有任何有效輸出……請立刻繼續執行。'
| 字段 | 默認值 | 說明 |
|---|---|---|
| enabled | false | 總開關 |
| maxConsecutiveEmptySteps | 0 | 連續空輪次上限;0 = 不限 |
| maxRemediesPerTurn | 0 | 單 turn 補救上限;0 = 不限 |
| maxRemediesPerAgent | 0 | 單 agent 補救總數;0 = 不限 |
| absoluteLimit | 10000 | 程序性死循環保險絲;0 = 關閉 |
| log | true | ctx.logger.warn 記錄介入 |
| steerText | 內置中文 | 注入模型的內容(0.4.0 起要求立刻繼續執行、不要回複本條) |
典型用法與驗證¶
- 安裝並
enabled: true,重啓 DSH。 - 在真實會話中若命中,日誌類似:
[empty-turn-guard] turn 12 step 3 命中(tool-calls-without-tool-call:finish=tool-calls,但沒有出現任何 tool-call 塊),已注入第 1 次補救(本 turn 第 1 次,連續第 1 次)
- 會話裏會出現一條以
[empty-turn-guard]開頭的用戶消息(即steerText),表示插件已攔截殘缺輪次。
開發側自檢(在插件源碼目錄):
node test.mjs # 43 項單元斷言
node preflight.mjs # 9 項啓動前置檢查
.\verify.ps1 # 8 項安裝完整性
node replay.mjs # 真實幀回放,期望 REPLAY OK,補救 2 次
適用場景與注意¶
適合誰:經常在 DSH 裏跑長任務 agent、且遇到過「界面已完成但 agent 沒調用工具也沒彙報」的開發者;尤其是 finish=tool-calls 卻只剩 reasoning 塊的情況(README 統計裏佔多數)。
務必知曉:
- 插件與當前 DSH 進程同權限運行;安裝前應閱讀 GitHub 源碼 與 MIT 許可證。
- 每次補救會多消耗一次上游模型調用。
finish=stop且模型確實無產出時不介入(屬正常收尾)。- 依賴
agent/turn-stopping在 loop break 之前觸發;上游若改時機需重新覈對。 - 0.2.0 曾用
maxRemediesPerTurn=1導致同 turn 內第二次空輪被放行;0.4.0 默認三上限均爲 0,只保留absoluteLimit。
結尾¶
dsh-empty-turn-guard 把 DSH 擴展點用在「殘缺 tool-calls 輪次」上:觀測 stream、在 turn-stopping 判定、用 steer 拉回執行,默認 fail-open、須顯式開啓。需要離線安裝、配置與迴歸用例時,以倉庫 README 爲準。
- 目錄頁:https://www.skillhub.cn/plugins/Paradox1278/dsh-empty-turn-guard
- GitHub:https://github.com/Paradox1278/dsh-empty-turn-guard