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:
| Preset | Ability (run1/run2) | let me count | Tool catalog |
|---|---|---|---|
| Standard | 91 | 208 | full (25 tools) |
| PTC | 92 | 194 | run_code |
| Minimal | 99 / 96 | 0 / 0 | 2 tools |
| Anchored Standard | 98 / 99 | 1 / 0 | 2 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:
- First model request → expose only one shell +
read(anchors the Minimal trajectory). - 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.toolsis filtered down to the bootstrap set before the first durable tool call, andpayload.messages[0](or top-levelpayload.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
toolResultmessage or an assistant message containing atoolCall), 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 —
/resumeand/reloadpreserve 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: truein 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-standard | pi-anchored-tool-for-dspro | |
|---|---|---|
| Host | DeepSeek Harness (Cordis) | pi (ExtensionAPI) |
| Hook layer | system-prompt/assemble | before_provider_request (payload) |
| Phase source | session.events (tool/call) | sessionManager.buildContextEntries() |
| Platform shell | bash or pwsh (one per platform) | bash (pi's unified shell tool) |
| Minimal persona | preset persona row, complete: true | payload system-message rewrite, permanent |
| Config failure | throws (loud fail) | warns + skips (fail safe) |
| Config | preset YAML | pi 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.jsonis the base. - A trusted project's
.pi/settings.jsondeep-merges over it — nested objects merge recursively, arrays are replaced wholesale (never concatenated),undefinedskips, 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 againstprovider/modelIdand baremodelId. 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 Harnessminimalpreset) on every request for a target model. Setfalseto 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.