Preface¶
When running agents with heavy tool usage in DeepSeek Harness (DSH), the same conversation history is repeatedly sent to the model with every request step. If the reasoning in a specific step is particularly long, these tokens are billed multiple times within the same turn, causing costs to escalate quickly. The host’s built-in context compression collects the history in its entirety, which does not fully align with the need to “only shorten thinking blocks while retaining valid derivations.”
The following is an introduction to the community plugin dsh-reasoning-distill (Maintainer: huhu23333, Category: Workflow). It monitors single-step thinking length and, when a threshold is exceeded, uses a distillation model to rewrite it into a shorter version. This compressed version is then replayed in subsequent requests. It also provides distillation overhead and savings statistics for each session. The plugin is disabled by default; you must select a backend and turn on the master switch in “Settings → Thinking Compression.”
What is this¶
dsh-reasoning-distill is a workflow-class plugin for DSH. Its positioning can be summarized as: compressing excessively long model thoughts into core content, replaying the compressed version in subsequent requests, and reporting session-level costs and net benefits.
- Directory Page: https://www.skillhub.cn/plugins/huhu23333/dsh-reasoning-distill
- Source Code & Documentation: https://github.com/huhu23333/dsh-reasoning-distill
- Current Package Version (package.json):
0.1.11, License MIT
The plugin runs with the permissions of the current DSH process. Before installation, please review the repository source code and license to confirm the source is trusted.
Core Functions¶
Compression and Replay¶
- Monitors the thinking content (reasoning) in every model output and estimates token count.
- When a step’s thinking exceeds the model’s Trigger Threshold (default: 4000 tokens), it submits this step’s thinking (optionally including tool calls and results) to a Distillation Model (default:
deepseek-official/deepseek-flash, thinking intensity off) to be rewritten into a shorter version. The compression targets wording and redundancy, not the deletion of valid derivation steps. - Compression is completed before the next request; wait time is limited by the model’s Timeout. If the time limit is reached, the current compression is abandoned (the original text remains unchanged and is not replaced). The compressed result is only adopted if it saves at least the Minimum Savings (default: 600 tokens).
- Adopted compressed versions replace the “thinking seen by the model”; the original thinking text remains unchanged in the session log, while the ledger is written to a sidecar file alongside the session log.
The “Thinking Compression” tab displays trigger count, distillation overhead, adoption count, reduction per request, cumulative history savings, net benefit, and the reason for the most recent non-trigger.
Three Rewriting Backends¶
The plugin is only responsible for generating the compressed version; writing it back to the session requires selecting an Assistant Message Rewriting Backend (if not selected, the master switch is forced off):
| Backend | Suitable Scenarios |
|---|---|
derive |
No installation or patches required; replaces in memory. Priority for packaged DSH versions (e.g., dsh-desktop). The conversation page still displays the original log, but the model actually receives the compressed version. |
in-place |
Requires patching DSH source code (scripts/dsh-inplace-patch.mjs); does not create branches or alter log structure. Requires a DSH built from source; incompatible with direct npm installs or third-party packaged versions. |
message-edit |
Experimental, not recommended: Depends on third-party plugins and creates a new branch session for every compression, limiting applicable scenarios. |
Session Scope and Default Switches¶
Main conversations, resumable sub-agents, and one-shot sub-agents have independent switches; by default, only the main conversation is enabled. Resumable sub-agents, one-shot sub-agents, attached tool call results, and final answer rounds are disabled by default.
There is also a Trigger Limit based on Context Usage (enabled by default, 60%): If usage is too high, compression is halted even if the single-step threshold is reached, to prevent the compressed content from being immediately collected by the host’s full context compression.
Installation and Activation¶
Prerequisites: Node >= 20; DSH starts normally (depends on sessionPersistence). After installation, a restart of dsh web is required.
Install from npm:
dsh plugin --profile web add dsh-reasoning-distill
Install from GitHub (pnpm may require adding the package name to the profile’s allowBuilds in pnpm-workspace.yaml and retrying):
dsh plugin --profile web add github:huhu23333/dsh-reasoning-distill
If derive is selected, no further backend installation is needed. If in-place is used, execute the following in the DSH source directory:
node scripts/dsh-inplace-patch.mjs --apply --build
Then restart dsh web. It is recommended to revert the patch before upgrading DSH and use --check to verify after the upgrade.
Activation steps:
- Open “Settings → Thinking Compression”.
- Select a rewriting backend (
deriveis active upon selection). - Turn on “Enable Thinking Compression”, then adjust thresholds, minimum savings, distillation model, and other items as needed.
The README notes that the potentially compatible DSH version range is 0.2.0-rc.1 to 0.2.1-rc.2; for full functionality and the in-place experience, a DSH built from the official repository source is recommended.
Typical Usage¶
The ideal form is the “single-turn, multi-step tool call, ultra-long single-turn conversation” described in the README: state the task clearly once, allowing the agent to continuously call tools for many steps within the same turn. The same history segment must be resent at every step, and the compressed thinking is replayed repeatedly, allowing the saved input tokens to exceed the distillation overhead.
It is not suitable as a default enabled scenario for “multi-turn Q&A, iterative refinement based on feedback”: there are few steps per turn, so savings are limited. Furthermore, the DeepSeek API typically does not concatenate previous turns’ reasoning_content into the context during multi-turn conversations (unless the request includes tools), meaning the compressed version is often not read by the model, and rewriting may disrupt context cache prefix matching. It is recommended to turn off the master switch in settings during this type of phase.
Scenarios and Caveats¶
Who is it for
- DSH users who prefer “wish-style” single-turn long-chain tool calls and are willing to trade input tokens for a distillation model.
- Users using packaged DSH versions who do not want to modify host source code: use
derive, which requires no patches.
Things to Note
- The plugin is disabled by default; it cannot be enabled without selecting a backend.
in-placemodifies the DSH core; cross-version upgrades may cause the patch to fail. Usederivefor packaged installations.- Under
derive, if a cold start fails to read the sidecar, it will temporarily carry the original text and log a warning, automatically re-applying once recovered. - A few fallback paths may result in cache miss billing, potentially overestimating the net benefit reported (the README explains
cacheBreakTokens).
Conclusion¶
dsh-reasoning-distill addresses the pain point of repeatedly sending ultra-long reasoning in single-turn multi-step tool chains. It uses configurable thresholds and distillation rewriting to shorten thinking and replays it in subsequent requests. It lays out overhead and savings transparently via a sidecar ledger and panel reports. Whether it is cost-effective depends on the conversation shape; it is recommended to disable it during multi-turn refinement phases, while long-chain single-turn tasks can be trialed with derive or in-place.
- Community Directory: https://www.skillhub.cn/plugins/huhu23333/dsh-reasoning-distill
- GitHub: https://github.com/huhu23333/dsh-reasoning-distill