pi-model-assign
v0.1.0
Published
Pi extension that auto-assigns an executor model per task and exposes an advisor tool for high-leverage guidance.
Maintainers
Readme
pi-model-assign
pi-model-assign is a pi extension that automatically chooses an executor model for each user task and gives that executor an advisor tool for occasional high-intelligence guidance.
It is inspired by Anthropic's advisor strategy: a cheaper/faster executor runs the task end-to-end, while a stronger advisor model is consulted only when the executor needs help with architecture, uncertainty, repeated failures, security/correctness risk, or hard reasoning.
Install
From npm:
npm install pi-model-assign
# or
bun add pi-model-assign@mariozechner/pi-ai and @mariozechner/pi-coding-agent are peer dependencies — pi installs them as part of its runtime.
Use as a pi extension
For a quick test, point pi at the installed entry:
pi -e ./node_modules/pi-model-assign/dist/index.jsFor auto-discovery, symlink it into the global pi extensions directory:
mkdir -p ~/.pi/agent/extensions
ln -s "$PWD/node_modules/pi-model-assign" ~/.pi/agent/extensions/pi-model-assign
piThen use /reload after editing the config.
Develop locally
git clone <this repo>
cd pi-model-assign
bun install
bun run build # bundles to dist/ and emits .d.ts
bun test # runs bun's test runner (add *.test.ts files as needed)
bun run typecheck # tsc --noEmitFor local extension testing without building:
pi -e ./index.tsConfiguration
The extension loads config from these locations, later entries overriding earlier entries:
<extension>/pi-model-assign.json
~/.pi/agent/pi-model-assign.json
<project>/pi-model-assign.json
<project>/.pi/pi-model-assign.jsonThe first slot resolves to the directory of the loaded extension file (i.e. node_modules/pi-model-assign/dist/ when installed from npm, or the repo root during local dev). The global and project-local files override it.
Start from the example shipped with the package:
cp node_modules/pi-model-assign/pi-model-assign.config.example.json ~/.pi/agent/pi-model-assign.jsonEdit model IDs/providers to match your pi setup. The default example uses placeholder choices based on your requested setup:
openai/gpt-5.5for reasoninganthropic/claude-sonnet-4-6for codingblablador/fast-modelfor fast/cheap tasksanthropic/claude-opus-4-6as advisor/review model
If a configured model is not available or lacks an API key, pi will warn and keep the current model.
Commands
/autoassign status
/autoassign on
/autoassign off
/autoassign reload
/autoassign dry-run <prompt>
/assign status
/assign <name> # sticky manual route
/assign once <name> # next prompt only
/assign auto # clear manual route
/advisor status
/advisor on
/advisor off
/advisor ask <question>Examples:
/autoassign dry-run refactor the auth flow for SSO
/assign once reasoning
/advisor ask Is this migration plan safe?How it works
- On
before_agent_start, the extension classifies the user prompt using configured rules. - It applies the selected route with
pi.setModel()andpi.setThinkingLevel(). - It appends route/advisor guidance to the system prompt for that turn.
- It registers an
advisortool that the executor can call when it needs stronger guidance. - The advisor call uses
complete()with the configured advisor model and a curated recent conversation/tool context.
The advisor does not call tools or edit files. It returns guidance for the executor to use.
Rule format
Rules are evaluated by descending priority.
{
"name": "deep-reasoning",
"route": "reasoning",
"priority": 80,
"ifPromptMatches": ["architecture", "design", "/\\bprove\\b/i"],
"ifPromptNotMatches": ["quick"],
"ifAnyFileExists": ["package.json", "Cargo.toml"],
"ifAllFilesExist": ["package.json", "tsconfig.json"],
"minContextPercent": 75
}Pattern strings are case-insensitive substring matches unless written as JavaScript-style regex strings such as /\\bsecurity\\b/i.
File existence fields:
ifAnyFileExists— at least one of the listed paths must exist relative to cwd (OR semantics). Renamed from the deprecatedifFilesExist.ifAllFilesExist— every listed path must exist relative to cwd (AND semantics).ifFilesExist— deprecated alias forifAnyFileExists; still supported for backwards compatibility.
Route format
{
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"thinkingLevel": "medium",
"tools": ["read", "bash", "edit", "write"],
"advisor": false,
"instructions": "Extra system prompt instructions for this route."
}provider+model: selected viactx.modelRegistry.find().thinkingLevel: one ofoff,minimal,low,medium,high,xhigh.tools: optional active tool set for this route. Omit or leave empty to allow all tools.advisor: false: disables the advisor tool and guidance for that route. Omit the field to keep the advisor enabled.instructions: appended to the system prompt for that route.
Notes
- The extension avoids switching repeatedly inside a task. It chooses the executor at user-turn start; the executor can call
advisorduring the task. /assign <name>creates a sticky manual override until/assign auto./assign once <name>affects only the next user prompt.- Advisor calls are budgeted by
advisor.maxUsesPerTurn. Both/advisor askcommands and executor tool calls share the same per-turn budget — the remaining count is shown after each/advisor askresponse.
