DeepSeek Harness (DSH) 採用插件化架構。在構建多代理系統時,主代理通常調用昂貴的官方 API,而子代理如果未配置,會繼續走官方接口,增加成本並帶來隱私泄露風險。dsh-llama-responses 作爲一個適配器插件,解決了這個問題,它通過 OpenAI Responses 協議,將子代理的請求路由到本地運行的 llama.cpp 服務。
插件概覽¶
- 名稱: dsh-llama-responses
- 所有者: SnowRikka
- 類別: 模型推理
- 許可證: MIT
- 核心功能:
- 多輪記憶
- function_call 流式
- function_call_output 回傳
- 子代理委派 (spawn/可繼續後臺, fork/one-shot 前臺)
- 追問排隊 (send_message)
- 狀態查詢 (list_agents)
- 中斷控制 (interrupt_agent)
- 結算通知 (report)
- Skill 發現與加載
安裝¶
使用官方插件命令安裝:
dsh plugin --profile web add git+https://github.com/SnowRikka/dsh-llama-responses.git
在 npm 發佈前,也可以通過軟鏈方式安裝(便於修改源碼):
git clone https://github.com/SnowRikka/dsh-llama-responses.git ~/dsh-llama-responses
ln -sfn ~/dsh-llama-responses ~/.dsh/profiles/web/node_modules/dsh-llama-responses
使用前置條件¶
- 本地模型服務已運行: 確保 llama.cpp 的
llama-server正在運行,監聽本地端口(如 8080)。 - 關鍵配置步驟: 每次啓動 DeepSeek Harness 後,必須先手動選擇一次本地的 qwen3.8-27b 並提問一次,然後將主代理切回 DeepSeek V4 模型。不做這一步,子代理不會正常路由到本地模型。
啓用子代理功能¶
本插件掛載在 DSH 的子代理體系上。默認情況下,web profile 的子代理工具是禁用的,需要手動啓用。
在 ~/.dsh/profiles/web/cordis.patch.yml 中加入以下配置:
- id: tool-subagent-control # send_message / interrupt_agent
disabled: false
- id: tool-subagent-list-agents # list_agents
disabled: false
- id: tool-subagent # 委派工具(可繼續後臺子代理)
disabled: false
- id: tool-subagent-fork # 委派工具(one-shot,已重定向 spawn=無父對話)
disabled: false
啓用後,模型將獲得 subagent、subagent_fork、send_message、interrupt_agent、list_agents 五個工具。
啓用本地模型路由¶
1. 配置適配器¶
在 ~/.dsh/profiles/<profile>/cordis.patch.yml 中註冊適配器:
- insert:
- id: llm-responses-local
name: dsh-llama-responses
config:
baseURL: http://127.0.0.1:8080/v1
providerName: llama-responses
apiKeyEnv: DSH_LOCAL_LLM_KEY
models:
- id: qwen3.8-27b
name: Qwen3.8-27B IQ4_XS (local)
contextWindow: 163840
defaultContextWindow: 163840
defaultMaxTokens: 8192
2. 配置子代理使用本地模型¶
在 patch 中指定子代理的 provider 爲 llama-responses:
- id: tool-subagent
config:
provider: spawn
toolName: subagent
backgroundMode: continuable
agentOptions:
provider: llama-responses
model: qwen3.8-27b
maxTokens: 8192
3. 環境變量¶
設置本地模型鑑權佔位符:
export DSH_LOCAL_LLM_KEY=local-no-auth
子代理隔離設計¶
這是本插件的重要設計特性。所有子代理不繼承父對話,包括父會話已完成的歷史內容。subagent_fork 工具已通過 patch 重定向,確保完全隔離。父代理若需傳遞背景,必須顯式寫在委派指令中。
協議細節¶
插件實現了 OpenAI Responses 協議的適配。在對接 llama.cpp 時,需注意以下細節:
- 歷史消息格式: 歷史消息條目必須帶頂層
type: 'message',assistant 內容使用output_text。 - 工具調用: 工具定義使用扁平格式
{type: 'function', name, description, parameters}。 - 結果回傳: 工具結果回傳使用
{type: 'function_call_output', call_id, output}。 - SSE 事件: 監聽
response.output_text.delta、response.function_call_arguments.delta、response.output_item.done、response.completed。