omp packages

pi-smart-model-routing0.2.0

Configurable daily and expert model routing for Pi

bpldbt Published 4 days ago MIT ~670 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-smart-model-routing

Pi extension for a configurable daily model plus an on-demand expert model. The main conversation uses the daily model for ordinary work; it can call ask_master for difficult architecture, consistency, concurrency, security, root-cause or review questions without switching the main model. Each expert consultation has fresh context and portable read-only tools to independently inspect workspace source. You can also explicitly ask Pi to call ask_master in chat.

Install

pi install npm:pi-smart-model-routing

For local development before publishing:

pi install C:/Dev/pi-extensions/pi-smart-model-routing

Restart Pi or run /reload after installing. Disable any older standalone extension that also registers ask_master; only one extension should own this tool. Installation does not set up model access or credentials.

Global configuration

Create <Pi agent directory>/pi-smart-model-routing.json only if you want to override defaults. Pi's normal agent directory is ~/.pi/agent/ (or the directory selected by PI_CODING_AGENT_DIR). No project configuration is read, and installing the package does not create a config file.

{
  "dailyModel": {
    "provider": "openai-codex",
    "id": "gpt-6.1-sol",
    "thinking": "high"
  },
  "expertModel": {
    "provider": "openai-codex",
    "id": "gpt-6-astra",
    "thinking": "xhigh"
  }
}

The above values are also the defaults when the file is absent. When a file exists, both model objects and all three fields in each object are required. thinking accepts off, minimal, low, medium, high, xhigh, or max. Model provider/ID must be present in your Pi model registry and authenticated. An invalid or unreadable file does not fall back to the defaults: Pi reports the configuration error and expert calls fail until it is corrected. Missing models or authentication are reported explicitly; the extension never silently substitutes a different model.

In an interactive Pi session, run /smart-model-routing to choose Daily or Expert, then change its model or thinking level. The action menu shows the configured provider/model and thinking level beside each action, refreshing after every save. The model picker lists only available authenticated models; the thinking picker lists levels supported by the selected model. Cancelling a picker leaves the file unchanged and returns to the action menu. Saving writes the global JSON file, refreshes the status line, and returns to the selected role's action menu so you can change its other setting. Esc from that menu returns to the Daily/Expert menu; Esc again exits. Daily changes take effect only in the next genuinely new session (the current model stays unchanged); expert changes take effect on the next ask_master call. An invalid existing file must be corrected before using the command; saving never silently replaces it.

Only a genuinely new, empty session automatically selects the configured daily model and thinking level. Resuming, forking and reloading an existing session do not override a manual model selection. Expert calls leave the main session's model unchanged. While an expert request runs, the tool displays the provider's streamed thinking text or reasoning summary when available (a rolling 3,000-character preview); otherwise it displays elapsed waiting time. Providers may not expose their full internal reasoning. The final tool result contains the expert's answer and any incompleteness notice, not its thinking preview or intermediate commentary. There is no fixed 24K-character initial-evidence cap; the input budget is derived from the expert model's context window. Referenced file ranges and text artifacts are admitted whole within that budget, and omitted evidence is disclosed rather than silently cut. Internal investigation rounds have the limits described below.

Independent read-only investigation

ask_master exposes only four tools to the expert: expert_read (numbered source lines), expert_list (one directory), expert_find (literal filename substring), and expert_search (literal content search, optionally case-insensitive). They use Node's filesystem APIs: no CodeGraph, Git, rg/fd, helper downloads or additional packages are required. Definitions and call sites can be investigated through source searches; this is not a complete structural call graph. The configured expert provider/model must support tool calling; provider errors are reported, not silently routed to another model.

The expert does not inherit the main conversation, main-session tools, extensions, skills or automatic project instructions. It starts from the explicit request/evidence and its own investigation. It cannot edit files, execute Shell/Git commands, run tests, access network tools or delegate to another agent. It still uses the normal configured model provider for inference.

Autonomous paths are relative to the captured workspace root. Parent traversal, absolute/device/drive/ADS paths, symlink/junction components and non-regular source files are rejected. Traversal excludes .git, node_modules, .pi, .agent and common credential names (.env/.env.*, .npmrc, .pypirc, .netrc, id_rsa, id_ed25519); direct autonomous reads of these protected paths are also rejected. Explicitly supplied evidence retains its existing workspace/session/temp authorization. Other files are not filtered through .gitignore; narrow the search path when useful. These capability restrictions are not an OS sandbox or a complete secret detector and do not eliminate hard-link, concurrent path-replacement or changing-workspace risks.

Each consultation permits at most 12 provider rounds (including one reserved tool-disabled wrap-up), 32 serial tool calls and a 10-minute local deadline. The dynamic output budget is cumulative across rounds; input accounting includes tool declarations and full investigation history. Files larger than 4 MiB are skipped, with a shared 32 MiB read budget and 10,000 traversed-entry budget. Each tool result is bounded to 32 KiB; directory listings return at most 500 entries, filename/content searches at most 100 matches. Binary, oversized or inaccessible files, exhausted budgets and truncated evidence are disclosed. Reaching a limit may prevent a final answer. A batch that would exceed the tool-call limit is rejected before execution, and the reserved tool-disabled wrap-up summarizes the evidence already observed; if that wrap-up request fails, the result keeps only the earlier evidence and stays marked incomplete. Incomplete results include recovery guidance in the tool response to the main model: gather missing evidence with its own tools, narrow the decision, and supply focused evidence if another consultation is needed rather than retrying the same request unchanged. The extension does not automatically retry. Result details include aggregate provider usage, investigation counts and bounded source hashes/provenance, not a guarantee that every relevant source was inspected or that tests ran.

Expert evidence contract

ask_master keeps caller-reported knownFacts separate from optional inferences (hypotheses) and openQuestions (uncertainties or missing evidence). Existing callers can omit both new fields. Claims are not automatically verified: supply supporting fileRanges or text artifacts for important decisions. Source paths and line ranges are retained even when you supply a custom label, including in omission disclosures. The expert is instructed to cite sources, disclose uncertainty, and treat evidence as data rather than instructions; this is not an independent fact-checking or prompt-injection security guarantee. Each consultation remains independent, so follow-ups must include their relevant context explicitly.

Request identity and lifecycle

Completed consultations store the original toolCallId, a SHA256 of the initial system/user prompts, captured workspace/tool-policy identity, expert provider/model/thinking/output-budget settings and bounded investigation provenance in Pi's existing session entries. The prompt hash identifies the initial request, not the complete autonomous transcript or an immutable workspace snapshot. Completed answers are not used to block repeated requests, including after branch restore: new files or edits can change the answer even when the question and supplied evidence are identical. Historical entries remain readable; no separate prompt database is created.

ask_master requests sequential execution from Pi and holds a single outstanding-investigation slot per extension instance, including across session/tree scope replacements. Other requests return a pending reference to the original call until its raw work settles. Cancellation/deadline ends the local wait promptly and stops progress updates, but does not release that slot while already-started provider/filesystem work remains outstanding. A provider that never settles keeps the slot occupied. Session replacement, reload, shutdown and tree navigation invalidate the old scope; late output cannot record completion or update the new UI. Reloading the extension/process is not proof that remote work stopped. Providers remain responsible for stopping network work and billing when cancellation is signalled.

Initial evidence preparation accepts only regular text files and shares a separate read allowance of min(32 MiB, maxInputTokens * 8 bytes) across file ranges and artifacts. Files exceeding the remaining allowance are omitted whole before reading, even when a small line range was requested; no unbounded whole-file read is used. File changes during reading fail explicitly. Initial prompt budgeting includes the system prompt, tool declarations and the final omission disclosure. If the complete prompt exceeds the estimated input budget, the last included evidence items are omitted whole until it fits; if even the all-omitted prompt cannot fit, the request fails explicitly. Any initial omission forces an incomplete result regardless of the model's wording. The estimate is not an exact provider tokenizer guarantee.

Development

npm test
npm pack --dry-run

The package does not include the separate local Android shell/logcat output guard. Never store credentials in this configuration file or in a published tarball. Review Pi extensions before installation: they execute with the host user's permissions.