DeepSeek Harness Dynamic Output Quota Plugin: dsh-adaptive-max-tokens

Preface

In the development of long-context scenarios for DeepSeek Harness (DSH), a common issue is the budget collision between a fixed reserved output quota (e.g., 384K) and growing input text. This leads to the server rejecting requests directly before the input has been compressed. dsh-adaptive-max-tokens is a plugin designed to transform fixed output reservations into dynamic quotas. By dynamically adjusting maxTokens based on context estimation, it releases occupied context space before compression strategies take effect.

Plugin Positioning

This is a model inference plugin maintained by 3289192-bot. It runs under the DSH Web profile. By reading request metadata and session events from the host’s memory, it calculates the remaining space. It does not initiate network requests, write to files, or read credentials. This plugin only adjusts the output quota; it does not alter the model’s inference intensity or increase the model’s actual context capacity.

Core Functions

This plugin primarily addresses the following specific issues:

  1. Dynamic maxTokens Adjustment: Calculates the maximum allowed output length based on current input estimation, context capacity, and safety margins.
  2. Quota Recovery After Compression: After compression strategies take effect, it recalculates the quota based on configuration and the current model’s output limits, avoiding the persistence of previously reduced values.
  3. Calibration Maintenance During Interrupted Sessions: Utilizes existing usage records to assist in estimation, preventing the loss of effective calibration points due to a single reply lacking usage data.
  4. Identifying and Retrying Overflow Errors: Intercepts context overflow errors based on formats identified in the code, attempts to shrink the output quota and retry once; other situations are handed back to the host for processing.
  5. Routing Compatibility: When switching models, it adheres to the explicit upper-bound constraints of the current route and agent.

Installation and Enablement

Before installation, please confirm your current DSH version. This plugin only supports 0.1.6-alpha.1 or 0.1.7-rc.2.

  1. Check the version:
dsh --version
  1. Install the plugin:
dsh plugin --profile web add github:3289192-bot/dsh-adaptive-max-tokens#v0.1.0

After installation, it takes effect for agent requests in this profile by default.

  1. Restart the instance:
    Restart the corresponding DSH Web instance when the task is idle, then start a new session. If an older version was manually installed previously, please remove or disable the old adaptive-max-tokens.mjs line from the custom preset before enabling this package.

Uninstall command:

dsh plugin --profile web remove dsh-adaptive-max-tokens

Default Parameters and Calculation Logic

The plugin includes a set of default parameters for calculating the output budget. The following is a typical configuration based on a 1,000,000 context budget and a 384,000 output limit:

Parameter Value Description
effectiveContextWindow 1,000,000 The configured context budget upper limit; takes the minimum of this and the adapter-declared value
maxOutputTokens 384,000 The configured output upper limit, also constrained by the current adapter and agent limits
safetyTokens 32,768 Space reserved for estimation errors
minOutputTokens 16,384 The desired minimum quota; will continue to shrink if space is insufficient
pendingWeight 1 The minimum estimation weight for pending input
log true Logs output budget changes

The calculation logic is simplified as: Output Quota = max(1, min(Output Cap, Context Budget − Safety Margin − Input Estimate)).

Applicable Scenarios and Limitations

Applicable Scenarios: Scenarios requiring the processing of long-context conversations where context overflow errors caused by fixed output reservations need to be reduced.

Important Limitations:
1. Cannot Guarantee No Overflow: The plugin calculates based on estimates, which include errors. Attachments, new tools, and large segments of new input may exceed the estimation, so it cannot guarantee that every request will remain within limits.
2. Does Not Increase Capacity: The plugin does not increase the model’s actual context capacity, nor does it modify official compression strategies or summarization parameters.
3. Retry Scope: Retries are only supported for context overflow error formats identified in the code; unknown formats are handed directly back to the host.
4. Privacy and Security: The plugin only reads request metadata and usage data from memory and does not involve reading credentials. However, when logging is enabled, it records session identifiers and error information.

Summary

dsh-adaptive-max-tokens is a practical tool designed to resolve output budget conflicts in long conversations. Through a dynamic shrinking and recovery mechanism, it allows output quota to yield to input. When used in conjunction with official compression strategies, it can significantly improve the stability of long-context tasks. For more details and compatibility notes, please refer to the GitHub Repository.

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

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

Xiaoye