
DSH Workbench
☆ 0DeepSeek Harness plugin for token auditing, live monetary cost estimation, dynamic model routing, and automatic context compaction gating.
Get this plugin
Review the source, then continue to the publisher.
dsh plugin add github:echo-escape/dsh-cost-governorAbout this plugin
Source snapshot 8/13/2026dsh-cost-governor
English | 中文
dsh-cost-governor is a plugin for DeepSeek Harness (dsh) that provides real-time token auditing, monetary cost tracking, dynamic model routing, and context compaction gating.
Powered by Cordis, it integrates directly with the Context lifecycle to monitor usage across agent sessions.
Overview
The plugin tracks prompt, completion, and prompt-cache hit tokens across sessions. It calculates monetary costs using configured model pricing matrices (including DeepSeek-V3, DeepSeek-R1, OpenAI, and Claude), recommends or degrades models based on budget constraints, and emits compaction signals when context token usage crosses defined thresholds.
Features
- Token and cost ledger: Tracks prompt, completion, and cache-hit tokens per session with estimated costs.
- Model pricing matrix: Pre-configured rates for DeepSeek, OpenAI, and Anthropic models, with support for custom rates.
- Dynamic model routing: Recommends appropriate models based on task complexity and automatically downgrades when budget limits are breached.
- Context compaction threshold: Emits compaction triggers to Cordis (
ctx.compaction) when context token usage reaches configured percentages. - Agent tool integration: Registers the
get_cost_statstool for real-time cost breakdown queries during agent sessions.
Installation
Add dsh-cost-governor to your DeepSeek Harness installation or workspace:
dsh plugin add github:echo-escape/dsh-cost-governor
Or install via pnpm / npm:
pnpm add @echo-escape/dsh-cost-governor
Configuration
Configure the plugin in your session's cordis.yml:
plugins:
cost-governor:
enabled: true
config:
currency: "USD"
maxSessionBudgetUsd: 5.0
compactionThresholdPercent: 80
modelRates:
deepseek-chat:
inputPerM: 0.27
outputPerM: 1.10
cacheHitInputPerM: 0.07
deepseek-reasoner:
inputPerM: 0.55
outputPerM: 2.19
cacheHitInputPerM: 0.14
Usage
The plugin automatically registers the get_cost_stats tool on ctx.tools. An agent or caller can execute this tool to retrieve structured cost statistics:
{
"status": "success",
"currency": "USD",
"totalTokens": 150000,
"promptTokens": 100000,
"completionTokens": 50000,
"cacheHitTokens": 20000,
"totalCostUsd": 0.0806,
"recordCount": 5,
"byModel": {
"deepseek-chat": {
"promptTokens": 100000,
"completionTokens": 50000,
"costUsd": 0.0806
}
}
}
Development
Run tests and type checking:
pnpm run typecheck
pnpm run test
Build the package:
pnpm run build
License
MIT