dsh-context-offload: DeepSeek Harness Context Offloading

Introduction

When building agents with DeepSeek Harness (DSH), the agent resends the entire history at every step. Much of this consists of tool outputs (file reads, command executions, etc.). This consumes the context window. This plugin releases tool calls and their results that are no longer needed from the model-visible history, replacing them with brief stubs.

Plugin Overview

This is a plugin for DeepSeek Harness designed for context offloading. Maintained by Hanochhu and licensed under MIT. It replaces tool calls and their results in the model-visible history with brief stubs, while retaining the original records in the session log for replay.

Installation and Activation

The installation command is as follows:

dsh plugin --profile web add dsh-context-offload

After restarting dsh web, the plugin will automatically mount to the profile composition and override all agents under that profile.

To disable it without uninstalling, add the following content to the profile’s cordis.patch.yml:

- id: context-offload
  disabled: true

How It Works

The plugin implements context offloading through two paths:
1. Policy-based Batch Release: During the agent/pre-step phase, the policy checks the currently accumulated unoffloaded content. A batch replacement is executed when the number of new complete tool units exceeds retainUnits, or when the accumulated character count reaches flushChars. Each batch replacement replaces at most maxUnitsPerFlush units and triggers at most once every flushEverySteps steps.
2. Model-initiated Offloading: The plugin provides the offload_context tool, allowing the model to actively offload completed calls within the request. This request is recorded during the tool call and applied at the next step boundary.

In the model-visible history, each offloaded tool unit (containing the assistant message and all answer results) is replaced by a stub of type user/message. The stub content is as follows:

[tool context offloaded — 2 tool call(s) removed from model context; 39,045 characters released]
- bash(command=cd /Users/me/proj && ls -la && for d in */; do echo …)
- read(path=src/harness/loop.ts)
The original arguments and results remain in the session log. Re-read a file or re-run a command if you need the content again.

Configuration

All fields are optional. The default values are as follows:

Field Default Value Description
enabled true When set to false, only model-visible tool calls are retained.
retainUnits 8 Number of recent complete tool units to keep intact in the model-visible history.
minUnitChars 4000 Units with fewer characters than this are not worth replacing.
flushChars 20000 Trigger a flush only when the accumulated releasable character count reaches this value.
flushEverySteps 10 Trigger a flush at most every N steps.
maxUnitsPerFlush 40 Upper limit on the number of units replaced in a single flush.

Scope and Limitations

This plugin is mounted into the config file via dsh.bundle.patch. By default, it mounts into the profile composition, overriding all agents under that profile.

If you need to restrict it to a single preset, do not enable the bundle line; instead, install the package so that node_modules can resolve it, and then add the configuration to your own preset copy:

- id: context-offload
  name: dsh-context-offload

You must enable one of the two methods, but not both.

This plugin works in conjunction with the compaction-basic context compression plugin; they do not conflict and do not override each other.

Please note:
* The replaced content is not shown in the human conversation transcript because transcripts are rendered from append events.
* Unfinished steps or system prompts (surface node 0) are not processed.
* The plugin depends on Node.js >= 20 and DSH >= 0.1.5-rc.1.

Summary

By replacing redundant tool outputs in the model-visible history with stubs, this plugin effectively reduces model context usage without losing original logs, making it suitable for handling long conversations or complex task flows.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye