Introduction¶
When running agents with the official DeepSeek Harness (DSH, @deepseek-ai/dsh-agent-loop), a common issue is that the context is occupied by a large amount of repetitive tool descriptions and Web GUI commands within the official system prompt, requiring ~2,000 tokens per round, which is both expensive and prone to causing model drift over multiple rounds; reading and editing multiple files can only be done by calling tools one by one; on Windows, excessively long shell commands or chained network commands can directly crash spawn; and repeatedly retrying the same failed call without stopping the loss. The dsh-plugin-agent-optimizer introduced below is designed to handle these issues.
Maintained by Jaylor-Wang, it is positioned as a runtime strategy and batch processing plugin for DSH, categorized under workflows, with 2 stars on GitHub, current version 1.1.0, and license MIT. It does not rewrite the agent loop but attaches non-invasively to the official ToolExecutionPipeline and system-prompt assembly process.
What is it¶
In a nutshell: a DSH plugin that provides an independent, streamlined system prompt engine, PTC composite batch processing tools, foolproof runtime strategies, soft convergence prompts, and objective A/B telemetry. The repository is also published as the npm package dsh-plugin-agent-optimizer, licensed under MIT, and the dsh.bundle.patch in package.json points to ./cordis.patch.yml.
Core Features¶
Streamlined System Prompt Engine (customPrompt)¶
The plugin hooks into DSH’s system-prompt/assemble flow. In placement: "replace-all" mode, it strips out the verbose harness:*, deployment:*, tool:*, deliverable:*, and web:* paragraphs from the official prompt, keeping only the convergence guidance part. The official prompt is about ~2,000 tokens, reduced to about ~380 tokens, representing an approximately 82% reduction in tokens as shown in the README comparison.
It uses a double-layer Markdown convention to manage prompts: globally reads ~/.dsh/SYSTEM.md (or $DSH_HOME/SYSTEM.md), and project-level reads .dsh/SYSTEM.md (or SYSTEM.md). After the file is saved, it hot-reloads via debounced fs.watch, taking effect in the next conversation without needing to restart the DSH process. There are two merge strategies: concat (default, overlaying global and workspace) and workspace-override (workspace overrides global).
It also provides the lintPrompt / fixPrompt / lintPromptFile interfaces. Validation is “preset-aware”: it judges tool instructions in the prompt based on the plugins actually loaded, such as adding defensive clauses for unloaded tools, softening modal words (suggesting changing bias toward to Prioritize), unclosed backticks, and RFC 2119 case issues, ultimately giving a health score of 0-100.
PTC Composite Batch Processing Tools (compositeTools)¶
read_batch: Concurrently view up to 10 file snippets in a single round, suitable for large-scale troubleshooting and dependency tracing.edit_batch: Apply up to 10 literal text replacements sequentially to the same or multiple files in a single round. The replacement target is plain text, not a unified diff. If a partial failure occurs, previously successful edits are not lost.
Each sub-operation still goes through the official ToolExecutionPipeline (tool/ptc-dispatch-start / tool/ptc-dispatch), so file policy locks, change guards, and audit hooks are preserved.
Foolproof Runtime Strategies (runtimePolicy)¶
NO_PROGRESScircuit breaker: Calculates a deterministic fingerprint for tool calls. When the same failed call repeats up tonoProgressLimit(default 2), the plugin blocks execution attools/pre-execute, forcing the agent to change its diagnostic approach.- Windows long command interception: Automatically blocks commands exceeding 4096 bytes and inline scripts over 512 bytes (
node -e,python -c,pwsh -Command), guiding the model to write the output to disk first. Corresponds to the errorEMBEDDED_SHELL_PAYLOAD_TOO_LARGE, avoidingspawn ENAMETOOLONGon the Windows side. - Chained network command guard: Intercepts at
tools/pre-executecomposite shells that chain network/credential operations likegit pushornpm publishwith local operations. It requires local operations to be chained with&&and network operations to be separate lines, avoiding Windows process handle hanging and 120-second timeouts. Corresponds to the errorCHAINED_NETWORK_COMMAND.
Failure Recovery (failureRecovery)¶
When edit is available but a destructive write full overwrite is attempted on an existing large file, the plugin blocks it. If a large write of 8KB–1MB is rejected due to a mismatched justification, the plugin automatically registers retry_failed_write, replaying only that write instead of making the model regenerate the entire content from scratch.
Convergence Prompts and Telemetry (convergence / telemetry)¶
The convergence component appends soft prompts when steps approach the budget interval, with a default stepInterval: 8, max 4 per round. It implements error-aware suppression: it stops prompting when the model is troubleshooting errors to avoid interrupting debugging.
The telemetry component collects model request counts, tool call counts, composite parallelism (parallelismRatio), time to first token (TTFT), token consumption, and prefix cache stability (prefixChanges), used for objective A/B comparisons.
Installation and Usage¶
It is recommended to use the DSH plugin command to add it directly to the current web profile:
dsh plugin --profile web add dsh-plugin-agent-optimizer
You can also use npm or pnpm:
npm install dsh-plugin-agent-optimizer
pnpm add dsh-plugin-agent-optimizer
According to the README, after installation, all optimizations are enabled by default, and no configuration lines are needed in cordis.patch.yml. The repository requires Node >=22.0.0 and DSH >=0.2.2-rc.1, and the package is ESM ("type": "module").
Only when you need to change paths or disable a subsystem should you add a line in cordis.patch.yml:
# Only declare override when customizing defaults
- id: agent-optimizer
config:
# Turn off prompt takeover, restore official verbose prompts
customPrompt:
enabled: false
# Adjust batch limits
compositeTools:
maxBatchFiles: 15
maxBatchEdits: 15
# Loosen non-progress circuit breaker
runtimePolicy:
noProgressLimit: 3
Typical Usage¶
Once installed with zero configuration, the plugin is ready to use without needing to create extra files. If you want to actively use the streamlined prompts, the typical path is:
- Write a
~/.dsh/SYSTEM.md. It will become the sole source of truth for prompts inreplace-allmode, with a size of about 380 tokens. You can simply write your own specifications for tool conventions and delivery requirements. - Save the file. The plugin hot-reloads via
fs.watch, taking effect automatically in the next conversation without restarting DSH. - After installing
read_batch/edit_batch, one call replaces multiple serial reads/writes, suitable for troubleshooting across multiple files and batch replacement. - When you need to confirm the benefits, look at the concurrency ratio, TTFT, token consumption, and
prefixChangesin telemetry for an A/B comparison of the same batch of tasks.
Applicable Scenarios and Notes¶
Suitable for developers already using the official DSH who want to strip out official system prompt redundancy, reduce multiple-file read/write round trips, and need some runtime hard constraints to prevent the agent from getting stuck in a non-progress loop. The batch processing capability is more effective when troubleshooting across files, while NO_PROGRESS and the Windows command guard are more defensive.
Two reminders: First, the plugin runs with the permissions of the current DSH process, capable of reading and writing the filesystem and network scope that you allow the agent to access. Before installing, you should check the source code and license (this repository is MIT, the README indicates 21 tests passing and TypeScript strict types, but you should still review the code yourself). Second, replace-all strips out official prompt paragraphs. If you rely on certain official Web GUI commands, you need to confirm they are covered in SYSTEM.md.
Conclusion¶
The value of this plugin lies in hard-coding several repetitive manual interventions into the runtime: streamlined prompts save tokens, batch processing tools reduce round trips, circuit breakers and command guards prevent mistakes, and telemetry provides an objective basis for comparison. It integrates non-invasively into the official pipeline and is usable out of the box with zero configuration.
Directory Page: https://www.skillhub.cn/plugins/Jaylor-Wang/dsh-plugin-agent-optimizer
GitHub: https://github.com/Jaylor-Wang/dsh-plugin-agent-optimizer