dsh-agent-compact:DeepSeek Harness 的自主片段压缩 DSH plugin
mimichunterz/dsh-agent-compact
DSH plugin 让 Agent 自主压缩对话片段,用自写检查点替代官方全量压缩,减少信息丢失。
让 DeepSeek Harness 的 agent 自主选择对话中已完成、不再需要的片段进行压缩,并用自写的检查点替换,最大限度减少信息损失。
dsh plugin --profile web add github:mimichunterz/dsh-agent-compact- 分类
- 记忆与上下文
- 平台
- DSH-Plugin
- 作者
- mimichunterz
- 分发方式
- 插件
dsh-agent-compact 核心特性
dsh-agent-compact 仓库信息

dsh-agent-compact 仓库简介
dsh-agent-compact 是 DeepSeek Harness(DSH)的上下文压缩插件(DSH plugin),由 MimicHunterZ 维护,采用 TypeScript 编写,最近更新于 2026-08。它解决的是官方压缩机制只能从对话开头进行全量压缩、导致开头任务计划和方向信息随压缩丢失的问题。该插件允许 agent 自主调用 context_compact 工具,选择对话中已完成、不再需要的中间片段进行压缩,并用 agent 自己编写的检查点(checkpoint)替换,从而将信息损失降到最低。核心能力包括:通过 startAnchor / endAnchor 精确选择压缩范围(支持 CJK 标点宽度容错)、强制要求 summary 参数(agent 自写的 Markdown 检查点)、原始片段先归档到 spill 存储(~/.dsh/spill/session-<hash>/<hex>-<seq>.txt,顺序命名,重启安全),且不额外发起 LLM 摘要请求,压缩过程在 agent 正常回合内完成,仅按普通回合计费。
dsh-agent-compact 这个 DSH plugin 支持哪些核心特性?
- 自主选择压缩范围:agent 通过
startAnchor/endAnchor指定要压缩的对话片段,支持唯一前缀匹配,对 CJK 标点宽度不敏感,能精准定位到中间任意一段。 - agent 自写检查点:
summary参数为必填,压缩后替换为 agent 自己生成的 Markdown 检查点,而非官方引擎的自动摘要,保留关键细节。 - 原始数据归档:压缩前先将完整原始片段写入 spill 存储,路径在 shadow 消息中回显,模型可随时读回原始文本,重启后依然可访问。
- 无额外摘要请求:复用宿主引擎的标准事务(边界校验、工具对平衡、表面替换),不额外调用 LLM 摘要器,节省成本。
dsh-agent-compact 怎么安装?
安装命令如下,安装后需重启 profile 使 context_compact 工具生效:
dsh plugin --profile web add github:mimichunterz/dsh-agent-compact
若从本地源码安装,可执行 dsh plugin --profile web add ./agent-compact。dsh plugin 命令会在 profile 目录中转发给 pnpm,并将 bundle 追加到 dsh.profile.bundles。插件自带的 cordis.patch.yml 将 spill 归档根目录固定为 ~/.dsh/spill,部署时可通过 profile 的 cordis.patch.yml 覆盖。
dsh-agent-compact 怎么卸载?
卸载命令如下,同样需要重启 profile:
dsh plugin --profile web remove @mimichunterz/agent-compact
该命令会转发给 pnpm remove,卸载包并从 dsh.profile.bundles 中移除 bundle。若插件是通过 profile 的 cordis.patch.yml 额外挂载的(开发模式),需手动删除对应行,否则下次启动会重新挂载。
dsh-agent-compact 有哪些配置项?
| 字段 | 默认值 | 说明 |
|---|---|---|
autoArchive | true | 压缩前是否将完整原始片段保存到 spill 归档 |
配置可通过 profile 的 cordis.patch.yml 插入的行或 bundle patch 传递。
dsh-agent-compact 的工作原理是什么?
patchEngine()(见 src/optimizer.ts)包装了引擎的 summarize() 方法:当存在 _externalSummary(即 agent 自写的检查点)时,直接使用该摘要,跳过官方引擎的自动摘要流程。工具调用发生在 agent 的正常回合内,按普通回合计费,仅避免了官方引擎对同一片段额外发起的摘要请求。