前言¶
在 DeepSeek Harness(DSH)裏做委派時,父會話往往每次都要在工具參數裏寫 provider、model、reasoning effort,還要選 agent preset。Harness 自帶的 subagent 路徑會把子會話標成 subagent,客戶端會隱藏模型選擇器,子任務和用戶手動開的 Session 在界面上不是同一類對象。
下面介紹社區插件 dsh-subagent-templates(維護者 windwhiterain)。它在 DSH 的「一切皆插件」思路下,用命名模板固定子任務的初始路由(單個 provider/model,或從 route pool 解析)、agent preset 和可選 persona,委派方按模板 id 和描述選型,而不是每次重複填模型參數。插件分類爲工作流,當前版本 0.1.0(MIT),GitHub 倉庫 windwhiterain/dsh-subagent-templates 約 1 star;目錄頁見 SkillHub(社區站點,與 DeepSeek / 幻方無官方從屬關係)。
這是什麼¶
dsh-subagent-templates 是一個 out-of-tree 插件包:除 schema 庫 @deepseek-ai/schemastery 外不依賴 Harness 運行時包,在 ctx 服務之上用 JavaScript 實現委派邏輯,不修改 Harness 源碼 checkout。
每個 template 定義:
- 起始 route:
provider+model,或pool(由 dsh-llm-quota-retry 提供的 route pool,按子任務解析); - preset(agent 預設,可省略則用部署默認);
- 可選 persona、reasoningEffort、maxTokens、toolFilter。
父 agent 通過 Host 平面工具 subagent(配置項 toolName 可改名,默認 subagent)按模板委派;背景任務的結果會自動回傳父會話,無需額外 collection 調用(見 README「Results」)。
核心設計:模板子會話是普通 root Session¶
一次模板委派不是 Harness 原生 subagent,而是與用戶在界面手動打開 Session 相同的路徑:
workspaceRegistry.create(cwd) → a workspace in the parent's directory
agents.create({ sessionId }) → a top-level Agent on the template's route
workspace.attachSession(id) → it appears in the normal session list
agent.followup(prompt) → it starts working
因此:
- 模型選擇器仍可用——子會話 header 故意不帶
parentSession/origin,客戶端不會把它當 subagent 而隱藏 picker。 - 模板路由只是初始值——用戶改 picker 後,以子會話自己的 durable request header 爲準。
- 子會話可再次委派——同一 preset 組合下仍有
subagent工具;嵌套深度由maxDepth等配置約束,不佔用ctx.subagents的遞歸預算。
父子關係存在插件自有存儲域 subagent_templates 的 children 表,而不是 Session header。
按名字管理子任務¶
每次委派必須帶非空 name,作爲子會話標題和唯一句柄(同一父會話下 live children 名字不可重複)。父側用名字引用子任務,例如 list_subagents、message_subagent、interrupt_subagent、delete_subagent(可一次刪多個名字或 "*");模型側工具結果與結算通知也用名字,不暴露 Session id。
與原生 subagent 工具的分工¶
模板子會話故意不在 ctx.subagents 註冊,否則客戶端會隱藏模型選擇器。原生 list_agents、send_message、interrupt_agent、subagent_fork 因此無法管理模板子會話。插件在首次委派成功後,在該會話 agent scope 掛載替代能力:
| 插件工具 | 對應原生 | 作用 |
|---|---|---|
list_subagents |
list_agents |
列出本會話子任務及模板、working/idle/ended |
message_subagent |
send_message |
按名字發消息,繼續或新開一輪 |
interrupt_subagent |
interrupt_agent |
停止當前工作但保留會話與 transcript |
delete_subagent |
— | 按名字結束子任務 |
Host 平面還提供 list_subagent_templates(列出模板與 route/preset 信息)。子會話側註冊 ask_parent,供子 agent 向父會話提問(父 idle 時會被喚醒)。
客戶端增加 Subagents 右側欄 Tab 與 subagentTemplates Session 投影,便於在 UI 中查看、打開或刪除子任務(README 說明: shipped sidebar 暫無父子分組)。
若需恢復原生 subagent 控制面,須在 preset 中重新啓用 tool-subagent-control 等行——會與模板委派形成兩套表面,README 建議通常避免。
配置要點¶
在 profile 的 cordis.patch.yml 中覆蓋或擴展插件行(bundle 自帶示例;profile 層會替換整個 config,需寫全必要字段):
- id: subagent-templates
name: 'dsh-subagent-templates'
config:
toolName: subagent # optional; the model-facing tool name
maxDepth: 1 # optional; how deep delegation may nest (default 1)
maxActiveSubagents: 4 # optional; how many children may work at once (default 4)
templates: # required; at least one
- id: medium # required; lowercase letters, digits, hyphens; the `template` argument
name: Medium # required; display name
description: >- # required; when to pick this template, in the model's vocabulary
Executes and explores: reads code, runs commands, and reports what it found.
provider: command-code-goat # one route: a registered LLM provider id …
model: deepseek/deepseek-v4.1-flash # … and a model that provider serves
# pool: medium # … OR the name of a route pool owned by dsh-llm-quota-retry
preset: personal # optional; agent preset the child joins (default: the deployment default)
reasoningEffort: high # optional; the child's starting thinking effort
maxTokens: 64000 # optional
persona: You are… # optional; the child's own persona
toolFilter: # optional; the child's narrowed tool set
deny: [write]
說明:
- 每個 template 只能選
provider+model或pool之一;toolFilter的allow: []表示除ask_parent外鎖死工具。 maxDepth默認 1:子會話默認不能再委派(達上限的會話不會掛載subagent/list_subagent_templates,避免每輪無效 tool error)。maxActiveSubagents默認 4:同一父會話同時 working 的子任務上限。- Web Plugins 設置頁可編輯模板列表與 caps 並寫回 patch;
toolName需在 patch 裏改並重啓 row。
安裝與啓用¶
插件以當前 dsh 進程權限運行;安裝前請閱讀倉庫源碼與 MIT 許可證,確認配置與工具暴露範圍符合你的部署策略。
在包含本倉庫 checkout 的目錄下執行(README 原文):
dsh plugin --profile <profile> add ./dsh-subagent-templates
也可在 Plugin Manager 中選擇該目錄安裝;bundle patch 會在 Host 平面插入插件行。
因 row schema 依賴 schemastery,link 安裝不會自動裝依賴,需在 checkout 內執行一次:
npm install
否則激活時報 ERR_MODULE_NOT_FOUND。若修改了 dsh.client.inject 中的客戶端注入項,需要重啓 host(客戶端 manifest 緩存)。
headless profile 若同時掛載 dsh-base 自帶的 tool-subagent,會與模板工具的 subagent 名衝突,需先禁用:
- id: tool-subagent
disabled: true
web profile 已默認禁用該行。
在 preset 裏改用模板委派¶
README「Use it in a preset」建議:
- 在 profile 的
cordis.patch.yml中去掉該 preset 的tool-subagent行,讓 Host 平面模板工具獨佔subagent名。 - 在同一 preset 禁用
tool-subagent-control、tool-subagent-control/list-agents、tool-subagent-fork(它們只認ctx.subagents)。 tool-subagent-codex、tool-subagent-claude-code可保持默認關閉;它們走外部 CLI,與模板子會話是不同能力。
委派時模型調用 subagent,指定 template(模板 id)、父側唯一的 name、任務 prompt,以及是否 run_in_background。前景調用等待子任務首輪自然結束並返回 closing text;背景調用立即返回名字,後續每輪結束以 subagent-settled 通知父會話。可先 list_subagent_templates 讓模型看清各模板 route 與 preset,再選型委派。
適用場景與注意¶
適合:需要在 DSH 里長期用固定「探索 / 審查 / 高推理」等角色委派,又希望子任務在 UI 裏像普通 Session 一樣可改模型、可繼續對話;需要按名字管理多個並行子任務(默認最多 4 個同時 working);希望背景委派結果自動回傳父會話。
注意:
- 與原生 subagent fork、繼承上下文子 agent 不是同一路徑;模板側重自包含 prompt 委派。
list_subagents只列直接子任務;孫子任務需在該子會話自己的工具集裏管理。- 存儲域未掛載時,
maxDepth/maxActiveSubagents無法 enforcement(README 說明 delegations proceed)。 - 插件卸載/HMR 不會自動殺掉已創建的 root Session 子任務;生命週期與映射、adoption 邏輯見 README「What a restart changes」等章節。
結尾¶
dsh-subagent-templates 把「選模型 + 選 preset + 寫人格」收成可命名的模板,並用獨立存儲與工具集管理模板子 Session,在保留完整 Session UI 的前提下完成委派工作流。