pi-anchored-tool-for-dspro

August 15, 2026 · View on GitHub

A pi extension that anchors a target model's first request to a minimal tool catalog (shell + read), restores the full catalog after the session records its first durable tool call, and rewrites the harness-injected system prompt to the DSH minimal-mode persona for the whole session. It exists because DeepSeek V4 Pro conditions strongly on both the API-visible tool list and the system-prompt persona — and the fix is a direct port of the DSH plugin xiaobright/dsh-anchored-standard to the pi coding agent.

This is an experimental prompt-conditioning patch, not a correctness guarantee. The underlying benchmark is a single personal evaluation, not a universal claim. No network requests, no telemetry.

Why this exists

The modeltest Project2 evaluation (DeepSeek V4 Pro, reasoningEffort=max) showed:

PresetAbility (run1/run2)let me countTool catalog
Standard91208full (25 tools)
PTC92194run_code
Minimal99 / 960 / 02 tools
Anchored Standard98 / 991 / 02 tools first, then full 25

The pattern: V4 Pro's RL-aligned scaffold reacts badly to a wide tool catalog on the first request (high let me, degraded planning), but performs at its best with the two-tool Minimal catalog. Staying on Minimal permanently gives up the Standard tool set — hence the two-phase trick:

  1. First model request → expose only one shell + read (anchors the Minimal trajectory).
  2. After the first durable tool call → expose every tool (no capability is ever lost).

The trigger mechanism experiments also isolated the system prompt as a co-equal variable: the minimal-mode persona is a codex-style one-liner (You are a helpful software engineer assistant.), and rewording it breaks the We need reasoning style (paraphrase runs went standard-like). The persona is therefore kept byte-identical to the Harness minimal preset and stays in place for the whole session — only the tool catalog promotes.

Both runs of the DSH preset emitted exactly two tool-catalog snapshots (bootstrap, then full), and the second run had zero let me across the whole trajectory — evidence it is not luck-of-the-draw.

Full methodology, trajectory statistics, and SHA-256 evidence: xiaobright/modeltest (docs/v4.1/DEEPSEEK_V4_TRIGGER_MECHANISM_EXPERIMENTS_20260814.md, evaluator/trajectory_evidence/).

What this extension does in pi

The DSH plugin hooks system-prompt/assemble and filters the tool catalog before the model sees it. pi has no equivalent assemble hook, so this extension works one layer lower — on the serialized provider payload:

  • before_provider_request: for a configured target model, payload.tools is filtered down to the bootstrap set before the first durable tool call, and payload.messages[0] (or top-level payload.system) is rewritten to the DSH minimal persona on every request of the session. Returning a replacement payload is the actual request pi sends.
  • After the first durable tool call (a toolResult message or an assistant message containing a toolCall), the tool filter stops firing and the full catalog flows through untouched — the minimal persona stays.
  • The phase is derived from session entries, not memory — /resume and /reload preserve it automatically, exactly like the DSH preset derives promotion from durable session events.

Semantics match the DSH plugin precisely:

  • The minimal persona is permanent (like complete: true in the Harness preset): only the tool catalog changes phase.
  • First response makes no tool call → no promotion.
  • A failed tool execution still promotes (a durable tool call exists).
  • The catalog changes exactly once per session (one request-prefix cache discontinuity, same as DSH).

Differences from the DSH plugin

dsh-anchored-standardpi-anchored-tool-for-dspro
HostDeepSeek Harness (Cordis)pi (ExtensionAPI)
Hook layersystem-prompt/assemblebefore_provider_request (payload)
Phase sourcesession.events (tool/call)sessionManager.buildContextEntries()
Platform shellbash or pwsh (one per platform)bash (pi's unified shell tool)
Minimal personapreset persona row, complete: truepayload system-message rewrite, permanent
Config failurethrows (loud fail)warns + skips (fail safe)
Configpreset YAMLpi settings.json, multi-level override

Install

Via npm (once published):

pi install pi-anchored-tool-for-dspro

Or clone this repo and add it in ~/.pi/agent/settings.json:

{ "packages": ["git:github.com/dbydd/pi-anchored-tool-for-dspro@v0.1.0"] }

Or copy src/ into ~/.pi/agent/extensions/anchored-tools/. Run /reload in pi after installing.

Config

Configuration lives in pi's settings.json under the top-level anchoredTools key, with the same multi-level override semantics pi uses for its own settings:

  • Global ~/.pi/agent/settings.json is the base.
  • A trusted project's .pi/settings.json deep-merges over it — nested objects merge recursively, arrays are replaced wholesale (never concatenated), undefined skips, project values win.
  • Re-read on every request, so edits take effect immediately.
// ~/.pi/agent/settings.json (global base)
{
  "anchoredTools": {
    "enabled": true,
    "models": ["deepseek-v4-pro"],
    "bootstrapTools": ["bash", "read"],
    "minimalSystemPrompt": true,
    "notify": true
  }
}
// .pi/settings.json (project override — replaces whole arrays for this project)
{
  "anchoredTools": {
    "models": ["claude-*"],
    "bootstrapTools": ["bash", "read", "ffgrep", "fffind"],
    "minimalSystemPrompt": false,
    "notify": false
  }
}
  • enabled — master switch.
  • models — glob patterns matched against provider/modelId and bare modelId. Patterns containing / match the qualified form only ("deepseek/*", "*/deepseek-v4-pro"). Empty array = no model anchored (safe default).
  • bootstrapTools — tools exposed on the anchored first request. Must be a subset of the catalog; if a name is missing from the catalog the filter fails safe (skips with a logged warning) rather than stripping tools.
  • minimalSystemPrompt — rewrite the harness-injected system prompt (the front of the context) to the DSH minimal persona (You are a helpful software engineer assistant., byte-identical to the Harness minimal preset) on every request for a target model. Set false to keep pi's default system prompt. The text is deliberately not configurable: the evaluation showed rewording the persona breaks the intended reasoning style.
  • notify — show one TUI notice when a session is promoted.

Verify

Run /anchored-tools inside pi — it reports the current model, whether it matches a target pattern, the phase (bootstrap vs promoted), and the minimal system-prompt switch. The console log also shows one line per session when the system prompt is first rewritten.

Development

Zero runtime dependencies. Tests run on Bun:

npm test   # bun test — 25 tests over src/core.ts pure logic

License

MIT. Concept ported from xiaobright/dsh-anchored-standard (MIT), itself derived from the DeepSeek Harness Standard preset — see the upstream project for the original notices. This package is not affiliated with or endorsed by DeepSeek or the pi project.