前言¶
在 DeepSeek Harness(DSH)里跑长任务时,同一会话会持续累积上下文与计费 token。上下文变长后,模型侧压力上升,任务边界也容易在多轮对话里被冲淡。常见做法是手动开新会话、自己粘贴背景,或依赖会话压缩——后者会改写事件流,且不一定保留「最初那条用户指令」的原文。
下面介绍第三方 bundle dsh-auto-summary(维护者 Warsk-80486,社区分类为工作流)。它在每个 Agent 回合结束后观测用量,当会话跨过可配置的 token 阈值时,用一次独立的摘要调用生成交接简报,并通过子 Agent 启动新的执行体;交接任务里会强制带上会话的首条用户 prompt 原文,便于续做而不丢任务定义。
这是什么¶
dsh-auto-summary 是以 dsh.bundle.patch 形式挂载的外部插件,不修改 DSH 源码。它监听已结束的回合(turn/end),从持久化会话日志或当前请求的 token 计量判断是否达到阈值;达到后写交接简报并调用 spawn 等子 Agent 提供方启动新 Agent,摘要内容作为新 Agent 的首条用户消息。
与「在原会话里继续堆消息」或「对原会话做 compaction」不同:README 明确说明被摘要的会话不会因本插件新增事件或被 compact;摘要请求是单独组装的 ctx.llm.stream(),不带 session id,避免污染原对话。
核心功能¶
触发与计量¶
- Turn-end 触发:在
turn/end之后执行,即每完成一段工作再评估。 - Token 阈值:默认
100000000(一亿),从 durable session log 计量;可在 profile 中改为更贴近实际的数值(最小 1000)。 - 两种指标:
total(累计 provider 计费 token,默认)或context(当前请求压力,ctx.tokenMeter.measure)。 - 仅已完成回合:默认
onlyCompletedTurns: true,只在turn/end且 reason 为completed时触发。
首条 prompt 与交接¶
- 首条 prompt 保底:从 DSH 的
titleInput投影读取(压缩后仍可 survives),即使用户自定义 handoff 模板漏写,也会强制追加「Original first user prompt」段。 - 新 Agent:通过
ctx.subagents.startActivation与handoff.provider(默认spawn)启动;简报经handoff.promptTemplate渲染,占位符包括{{firstPrompt}}、{{summary}}、{{sessionId}}、{{turn}}、{{reason}}。
安全与失败策略¶
- 递归安全:handoff 产生的是子 Agent;默认
summarizeSubagentSessions: false,且跳过origin: 'subagent'或delegationDepth > 0的会话,避免 handoff Agent 再触发 handoff。 - Re-arm:一次成功交接后,阈值在用量基础上再抬高一档,长会话是「每跨一档阈值交接一次」,而不是每回合都交接。
- Fail-open:摘要或 spawn 失败会记录日志,下一回合重试;连续失败达
maxConsecutiveFailures(默认 3)后消耗当前阈值档位,0表示一直重试。 - Dry run:
dryRun: true只打日志,不调模型、不创建 Agent。
运行依赖¶
- DSH 版本:
engines.dsh: ^0.2.1-rc.5(package.json 与 README 一致)。 - Profile 需挂载:
agents、llm、sessionProjections、subagents、tokenMeter;README 称dsh-base+dsh-web-app组合已满足。 - 摘要模型路由:默认沿用会话最近一次
request/header路由;也可在配置里同时指定summary.provider与summary.model。
安装与启用¶
插件以 git 依赖形式安装,仓库内已提交构建产物 lib/(第三方 bundle 不跑安装期 build script)。
在 DSH Web 界面 Plugins 中安装该仓库 bundle,或让 Agent 通过 plugin_manager 执行 install_bundle:
git+https://github.com/Warsk-80486/dsh-auto-summary.git
需要固定版本时,可 pin 到 40 位 commit:
git+https://github.com/Warsk-80486/dsh-auto-summary.git#<40-char-commit-sha>
安装后 bundle 出现在 profile 的 dsh.profile.bundles 列表,并挂载 auto-summary 行。若 Plugins 页提示需要重启,则重启应用。
本地开发可在 DSH 应用关闭时用 CLI 链接目录(需绝对路径):
dsh plugin --profile desktop add /absolute/path/to/dsh-auto-summary
卸载:在 Plugins 页移除 bundle,或:
dsh plugin --profile desktop remove dsh-auto-summary
说明:插件在 DSH 进程权限下运行;安装前请自行查看 GitHub 仓库 源码与 MIT 许可证。社区目录 SkillHub 插件页 为独立站点,与 DeepSeek / 幻方无官方从属关系。
配置¶
所有字段有默认值,不配置也可挂载。在 profile 自身的 cordis.patch.yml 中覆盖 bundle 行(该层在 bundle 之后应用),例如:
- id: auto-summary
config:
thresholdTokens: 100000000
metric: total
onlyCompletedTurns: true
summarizeSubagentSessions: false
maxConsecutiveFailures: 3
dryRun: false
summary:
provider: ''
model: ''
maxInputChars: 48000
maxOutputTokens: 4096
timeoutMs: 120000
handoff:
provider: spawn
delivery: parent
labelPrefix: handoff
promptTemplate: |
You are a continuation agent taking over a task from an earlier DeepSeek Harness session.
...
## Original first user prompt (verbatim)
{{firstPrompt}}
## Handoff summary
{{summary}}
长会话若希望更早交接,应把 thresholdTokens 调到符合预期的数值(README 默认一亿相当于「默认几乎不触发」,适合先验证链路再收紧)。
handoff.delivery:parent 时原 Agent 会收到新 Agent 完成通知;caller 为 fire-and-forget。
典型用法¶
- 在已满足依赖的 DSH profile 上按上文命令安装 bundle 并重启(若需要)。
- 保持默认配置时,插件仅在 token 达到极高默认阈值时才会交接;调试可先设
dryRun: true观察日志,再将thresholdTokens设为可触发的值。 - 长任务持续在同一主会话中推进;当计量跨过阈值且回合正常结束时,插件读取 transcript(人类 prompt + 助手文本,新到旧,受
summary.maxInputChars限制),调用摘要模型生成交接简报,再 spawn 子 Agent 接手。 - 原会话不再写入摘要相关事件;后续工作主要在 handoff 子 Agent 会话中继续,且其首条任务仍包含最初用户 prompt 原文。
适用场景与注意¶
适合:单会话内 token 或上下文压力持续增长、又希望「开新 Agent 续做」且必须保留任务原文的 DSH 工作流;与 DSH「一切皆插件」的扩展方式一致,以 bundle 补丁挂载即可。
注意:
- 默认跳过子 Agent 会话,handoff 链路由
spawn承担,避免无限递归。 - 摘要失败不会阻塞原会话正常 turn,但可能延迟交接,需结合日志与
maxConsecutiveFailures排查。 - 摘要使用额外模型调用,会产生独立 token 消耗;
summary.maxOutputTokens、timeoutMs可按任务体量调整。 - Node.js
>=20.0.0;插件版本见 package.json(当前资料为0.1.0)。
结尾¶
dsh-auto-summary 在回合结束时计量 token,超阈值则用一次辅助模型调用写交接简报,并以子 Agent 续任务,同时保证首条用户 prompt 不被模板遗漏。若你在 DSH 里做长 horizon 开发,可在社区目录与 GitHub 查看说明与 issue:
- 目录页:https://www.skillhub.cn/plugins/Warsk-80486/dsh-auto-summary
- 仓库:https://github.com/Warsk-80486/dsh-auto-summary