Introduction¶
Developers running long-horizon Agents often encounter situations where the model repeatedly calls tools within a turn and refuses to stop, or consumes far more tokens than expected in a single response. By the time this is noticed, a significant portion of the quota has been burned. The philosophy behind DSH (DeepSeek Harness) is that “everything is a plugin,” and such resource limit issues can be solved by plugins without modifying framework code. The dsh-turn-budget introduced below accomplishes precisely this.
What is it¶
dsh-turn-budget is a fail-closed resource governor for DeepSeek Harness, maintained by Nunchakus888. It independently sets three types of limits per Agent turn: the number of model steps, the count of root/nested tool executions, and the precise token usage reported by the provider. Once the quota is exhausted, subsequent requests will be rejected before execution.
The current version is 0.1.0 under the MIT license, requiring the Node engine >=22.19.0 <23 || >=24.0.0. Implementation-wise, it only utilizes DSH’s public extension points: dsh.bundle.patch in package.json points to cordis.patch.yml.
Intercept Semantics¶
The plugin intercepts via DSH hooks, and the behavior of the three limits varies:
| Limit | Timing | Counted Work | Overflow Result |
|---|---|---|---|
maxStepsPerTurn |
Before the next model request | Requests entered during the current turn | Reject the step, and close the turn with blocked |
maxToolCallsPerTurn |
Before each tool execution | Root calls, plus nested dispatches carrying the Agent’s Code Mode | Return a policy error indicating which budget was exceeded; the model still gets one chance to complete without using tools |
maxProviderTokensPerTurn |
Before the next model request | The latest provider usage per step, including cache read/write buckets | Reject the step after the total reported usage reaches the limit |
The corresponding hooks are分工 as follows:
agent/pre-step: Reject model requests that exceed step or provider-token limits.tools/pre-execute: Reject tool requests that have exhausted tool call quotas before dispatch.tool/resultandturn/end: Leverage existing records to preserve strategy results in standard Session logs, without creating a separate log channel.
There are two points to clarify regarding the token limit: it is only precise when the provider reports usage; missing usage is not estimated. The provider might also exceed the limit within the current response, but the plugin can only block subsequent requests, as the public lifecycle does not provide a preemptible token flow budget.
Installation and Enablement¶
Install from checkout:
git clone https://github.com/Nunchakus888/dsh-turn-budget.git
dsh plugin --profile web add ./dsh-turn-budget
Next, view the effective configuration and then run:
dsh --profile web --dump-config
dsh --profile web
The built-in profile layer defaults to providing a set of conservative baselines: 24 model steps per turn and 40 tool executions.
Override Limits¶
With the steps above, the plugin is working based on the default baseline. If your deployment requires different limits, override the full configuration line in the profile’s cordis.patch.yml:
- update:
id: turn-budget
config:
maxStepsPerTurn: 16
maxToolCallsPerTurn: 32
maxProviderTokensPerTurn: 250000
All three items can be configured, but each must be a positive safe integer, and at least one item must be configured.
Boundaries and Considerations¶
- It is positioned as a circuit breaker, not a billing system: it does not estimate monetary costs, rewrite tool parameters, replace sandboxes or approvals, and cannot terminate non-cooperative model or tool operations mid-step.
- The tool ledger is process-local, keyed by the active Agent identity; cold recovery closes it before continuing an interrupted turn, meaning that old in-progress ledgers cannot be recovered after a process restart.
- Integration tests use the published Harness testkit to start a real Agent Loop, covering step rejection, pre-dispatch tool rejection, turn reset, final response allowance, provider-token accounting, and duplicate usage replacement. When participating in development, first execute
pnpm install, then executepnpm run check. - The plugin runs with the permissions of the current dsh process. Before installing any third-party plugins, it is recommended to read the source code and verify the license; the license for this project is MIT, and you can verify it directly via the repository.
Conclusion¶
dsh-turn-budget solves a specific problem: stopping uncontrolled turns as soon as they exceed limits, rather than manual troubleshooting after the fact. It converges the three types of quotas—steps, tools, and tokens—into three independent configurations per turn, with behavior traceable in Session logs. It is suitable for operations and developers looking to add a resource baseline to their DSH deployment.
- Community directory page: https://www.skillhub.cn/plugins/Nunchakus888/dsh-turn-budget (independent site, no official affiliation with DeepSeek or Hypothesis)
- GitHub repository: https://github.com/Nunchakus888/dsh-turn-budget