前言¶
在 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 的前提下完成委派工作流。