jonah791/dsh-agent-compact

jonah791★ 1TypeScriptLast synced: 2026-08-14

Open on GitHub

Agent-driven compaction for DeepSeek Harness: the agent summarizes its own conversation (KV-cache friendly, no giant replay). Verified in production at ~460k-token sessions.

README excerpt

dsh-agent-compact — DSH 的 Agent 驱动压缩插件 为 DeepSeek Harness (DSH) 打造的 Agent 驱动会话压缩插件。 与官方后端把整个会话历史重放到独立 LLM 请求里做总结不同,本插件 让 agent 总结自己的对话 ——摘要直接从模型已经持有的上下文里产出,命中提供方 KV 缓存,不再构造巨型重放请求。 状态:可用原型,已在真实生产会话中完整验证(见实测证据)。DSH 为预览版(0.1.0-rc),无兼容承诺。 问题 官方压缩后端( @deepseek-ai/dsh-compaction-basic )通过把完整 surface 重放进一个新 LLM 请求来做总结( buildSummarizationInput 无截断)。当会话膨胀到一定程度,这个重放请求会在传输层失败: - 真实故障:会话膨胀至 约 46 万 token 输入 (664 个 surface 节点)→ compaction/end 报 error: "DeepSeek API request to https://api.deepseek.com failed" - 连续 5 次 /compact 均以同一 TRANSPORT 错误失败;每次重试都重新构造同一个无上限的重放请求 - 讽刺的是:官方路径在会话小时能成功,随会话膨胀退化为必然失败——而膨胀恰恰是最需要压缩的时刻 方案:让 agent 总结自己的上下文 压缩流程变为: 1. compaction/start —— 与官方完全相同的事务封装 2. 向 agent 的收件箱注入总结指令(next-turn 投递) 3. agent 基于 当前上下文 直接写出 checkpoint 摘要——提供方的 KV cache 里早已缓存了这些内容 4. 捕获并校验摘要( agentSummarize :非空、比原文小) 5. compaction/summary → surface replace → compaction/end → flush —— 与官方事务格式字节级兼容 实测证据 在同一个曾连续失败 5 次的会话上验证(总结轮 turn 24): 指标 数值 inputTokens 865 cacheReadTokens 568,832 (KV 缓存命中——agent 自己的上下文) outputTokens 1,933 结果 Compacted 664 history items ( 460634 tokens) compaction/end 无 error 字段 架构 src/index.ts —— AgentCompactEngine extends CompactionEngine (来自 @deepseek-ai/dsh-compaction ): - compactNo…

View full README on GitHub →
Agentsdsh-pluginagent

Category