Introduction¶
When developing DeepSeek Harness (DSH) presets, tool results in long sessions can be large and easily cause context overflow. Existing compression methods sometimes struggle to balance aggressive pruning with historical recovery capability. dsh-context-guard aims to control context growth by pruning oversized tool results while retaining persistent session history for targeted recovery.
What It Is¶
This is a DSH preset plugin maintained by kpl0111, focused on solving token consumption in long agent sessions. It manages retention and pruning of tool results through policies and does not introduce extra LLM calls.
Core Features¶
The plugin controls token consumption through the following mechanisms:
- Over-limit pruning and preview: Before the next model request, the plugin replaces oversized regular tool results with a 2.3K-character preview (retaining the first 1792 characters and the last 448 characters).
- Session history retention: Original tool outputs are stored in DSH’s append-only session history. The plugin itself does not delete raw data; it only prunes previews.
- Specific policies: Search results follow the normal pruning policy; recall results retain full content only for the immediately following step, then re-enter the pruning queue.
Installation and Enablement¶
Install the plugin using the official command:
dsh plugin --profile web add github:kpl0111/dsh-context-guard#v0.2.0
If bounded search and recall restoration are required, install the companion package:
dsh plugin --profile web add github:KitDoesIt/dsh-compaction-instant
When using pruned outputs, add guidance to the persona/system prompt instructing the model to prefer file paths or narrow-scope search and to use recall only when necessary.
After installation or update, DSH must be restarted and a new session created.
Validation¶
- In a new session, run a tool that produces large output (such as PowerShell).
- Check the session event log or context view and confirm that the model receives a preview of about 2.3K characters rather than the full result.
- Use search to locate a known value, then perform recall to verify the full content.
Compatibility and Notes¶
- Version requirements: Requires a compatible version of
@deepseek-ai/dsh-*0.1.0-rc.6 or later. - Built-in components: Works with the built-in
@deepseek-ai/dsh-compaction-tool-result-pruner. - Threshold setting:
thresholdRatio: 0.001sets a near-immediate trigger threshold, but the context window is still checked; set it to0.20if deferred pruning is preferred. - Data safety: The plugin does not delete original tool outputs (it only prunes previews).
- Mutual exclusivity: It is mutually exclusive with
presets/standard-lite.fragment.ymland cannot be enabled at the same time.
Conclusion¶
The plugin optimizes token utilization in DSH sessions through policy-level control. Refer to the project directory or source code for more details.