READMESource: main@39b85fe3
dsh-plugin-agent-optimizer
Non-invasive runtime policy, PTC-backed composite batch tools, soft convergence guidance, and A/B turn telemetry plugin for the official DeepSeek Harness (
@deepseek-ai/dsh-agent-loop).
Architectural Boundaries
dsh-plugin-agent-optimizer strictly separates loop lifecycle ownership from local policy and efficiency optimizations:
- Official Loop Ownership (
@deepseek-ai/dsh-agent-loop):- Retains 100% control over turn/step state machines, durable session replay, native parallel tool scheduling (
maxParallelToolCalls), retries, cancellation, andend_turncompletion semantics. cordis.patch.ymlmountsdsh-plugin-agent-optimizerpurely additively (- insert:) and never disables or replaces@deepseek-ai/dsh-agent-loop.
- Retains 100% control over turn/step state machines, durable session replay, native parallel tool scheduling (
- Never Mutates
agent/requestParameters:- The official loop verifies that
provider,model, andreasoningEffortinagent/requestmatch the step's selected configuration. This plugin never hooksagent/requestto downgrade reasoning effort mid-turn.
- The official loop verifies that
- Defensive Runtime Policy (
src/runtime-policy.js):NO_PROGRESSGuard: Computes deterministic tool invocation fingerprints and blocks repeated identical failing tool calls afternoProgressLimit(default2) consecutive failures.- Windows Shell Payload Guard (
EMBEDDED_SHELL_PAYLOAD_TOO_LARGE): Blocksbashcommands exceedingmaxShellCommandBytes(4096bytes) or inline script arguments (node -e,python -c,pwsh -Command) exceedingmaxInlineScriptBytes(512bytes) to preventspawn ENAMETOOLONGon Windows.
- File Mutation & Write Recovery (
src/file-mutation-policy.js,src/failure-recovery.js):- Tracks observed/existing vs. newly created files per turn and guards against accidental large full-file overwrites when
editis available. - Provides one-shot
retry_failed_writerecovery overToolExecutionPipelinewhen a largewrite(8KB–1MB) is rejected due to an unpairedjustification, avoiding regenerating the file content.
- Tracks observed/existing vs. newly created files per turn and guards against accidental large full-file overwrites when
- Composite Batch Tooling (
src/composite-tools.js):- Registers
read_batchto read up tomaxBatchFiles(10) files in a single tool call. - Dispatches every sub-read through
ToolExecutionPipeline(tool/ptc-dispatch-start/tool/ptc-dispatch) so all DSH sandbox permissions and policy hooks remain enforced.
- Registers
- Lightweight Soft Convergence (
src/convergence.js):- Injects batching/efficiency guidance and a one-time soft step budget notice (
softStepBudget: 8). - Important: A soft budget notice appends one user message (
source.kind = "optimizer-convergence"). It is not a hard stop, does not guarantee fewer model requests on its own, and adds a small input token cost tracked by telemetry.
- Injects batching/efficiency guidance and a one-time soft step budget notice (
- Objective A/B Telemetry (
src/telemetry.js):- Tracks
modelRequests,toolCalls,ptcSubCalls,toolBatches,parallelismRatio(toolCalls / toolBatches),failedToolCalls,wallClockMs,firstTokenMs(p50/p95), token usage, and prompt history prefix stability (prefixChanges).
- Tracks
Configuration (cordis.patch.yml)
- insert:
- id: agent-optimizer
name: dsh-plugin-agent-optimizer
config:
enabled: true
runtimePolicy:
mode: enforce
noProgressLimit: 2
recoveryAttemptLimit: 1
minLargeWriteBytes: 8192
maxShellCommandBytes: 4096
maxInlineScriptBytes: 512
fileMutationPolicy:
mode: observe
minLargeWriteBytes: 8192
recoverFailedWrites: true
compositeTools:
enabled: true
readBatch: true
maxBatchFiles: 10
convergence:
enabled: true
injectGuidance: true
softStepBudget: 8
telemetry:
enabled: true
trackStreams: true
Verification & A/B Benchmarking
# Link local peer dependencies from the installed DSH host (zero network requests)
npm run setup:local
# Run integration tests against the official @deepseek-ai/dsh-agent-loop
npm test
# Verify TypeScript declarations
npm run typecheck
# Run offline A/B mechanism verification
npm run benchmark
No comments yet. Be the first to write one.