@alexeiled/pi-model-router

中文文档
0.19.0发布于 2026/11/04MITES Module零依赖构建来源已验证近 30 天下载 2762

Pi model router with classifier-model routing, soft budget controls, and custom-provider support.

原始使用文档
文档目录10 节
  1. Why use it?
  2. Optional routing advice
  3. Inspect routing in Pi
  4. A turn in Pi
  5. Upgrading to 0.18.0
  6. Upgrading to 0.16.0
  7. Upgrading to 0.15.1
  8. From 0.14
  9. From versions before 0.12.0
  10. Install

pi-model-router

CI npm License: MIT

Stop changing models by hand.

Keep one profile in Pi. pi-model-router can select a different model and reasoning effort as the task changes, including between tool-loop requests. Optional advice uses any text-capable classifier registered in Pi. The router uses Pi’s typed classifier API and requires explicit per-profile approval for the exact model.

Why use it?

  • Fewer manual changes. One profile can combine fast, low-cost routes with stronger models.
  • Control over cost and quality. You choose the models, effort levels, fallback order, and baseline. You can pin a route at any time.
  • Routing modes. cost, balanced or quality chooses a preferred model/effort pair, per profile, project or session. OpenAI defaults use Luna, Terra and Sol; custom routes keep deterministic transforms. Choose a mode.
  • Built-in activity routes. Recognized OpenAI and Claude profiles get defaults for code, debug, explore, plan, review, ops and docs. Tune one cell or opt out. Defaults and tuning.
  • Adaptive tool loops. Periodic background reviews assess current work without delaying generation. Eligible recommendations can change tier, activity and effort between requests, with explicit switch-cost controls.
  • Visible decisions. A compact Signal Panel shows actual activity, model and effort. Held proposals stay distinct. Open /router for native bars/sparklines, observed usage and session controls.

The aim is selective use of expensive models, not the cheapest answer at any cost. Savings depend on your profiles, task mix, output size, and cache reuse. Advisors add latency. Their fees are separate from generation costs.

Optional routing advice

Use Jev, Clef/Clef Flash/Clef Omni, OpenAI Decisions, or a local Ollama or llama.cpp classifier registered in Pi. It reads bounded recent context and advises a model and effort from your profile. The selected generation model produces the answer, not the advisor.

flowchart LR
    Task["Your task"] --> Router["Pi model router"]
    Advisor["Configured Pi classifier"] -.-> Router
    Router --> Light["Micro / low"]
    Router --> Strong["Medium / high"]
    Light --> Answer["Answer and tool calls"]
    Strong --> Answer
    classDef policy fill:#dbeafe,stroke:#2563eb,color:#0f172a
    classDef advisor fill:#fef3c7,stroke:#b45309,color:#451a03
    classDef generation fill:#dcfce7,stroke:#15803d,color:#14532d
    class Router policy
    class Advisor advisor
    class Light,Strong generation

Configure classifier credentials in Pi and approve its exact provider/model reference per profile. Selected text can contain private data. The router sends text only. Without an advisor, it uses a compatible local route. Supported models, credentials and configuration →

The reference config selects pinned Jev 1.14 but leaves advice disabled until you opt in. Missing catalog entries need a Pi provider extension; the optional catalog example requires Pi 1.3+. The router uses one selected classifier, not voting or classifier failover.

Inspect routing in Pi

Run /router for five tabs: Now · Routes · Classifier · Usage · Settings. Open any tab with /router routes, /router classifier, /router usage or /router settings. /router status returns short text. The two-line strip is on in new sessions. /router widget switches to a quiet footer status instead.

╭──────────────────────────────────────────────────────╮
│ Router / auto                                        │
│ ›Now | Routes | Classifier | Usage | Settings        │
│ ▂▄ GLM 5.3 Flash · low ⏵ pinned                      │
│ zai/glm-5.3-flash · effort low                       │
│ Pinned route                                         │
│ Mode: balanced (default) · bypassed by pin · /router │
│ mode                                                 │
│                                                      │
│ Switch history · retained active branch              │
│ History collection is on · last 50 observations      │
│ Observed: ▂▄▆ MiMo V2.6 Flash · high · baseline      │
│ Model switch: ▂▄▆ MiMo V2.6 Flash · high → ▂▄ GLM    │
│ 5.3 Flash · low · pinned                             │
│ Why this route? | Done                               │
╰──────────────────────────────────────────────────────╯

The bars ▂ ▂▄ ▂▄▆ ▂▄▆█ name the tier, micro to high, on every surface. Captured from Pi 1.5 in agterm with two cheap test models. Inspector controls · Classifier setup

A turn in Pi

This illustrative strip shows a low-tier choice after completion. It is not a routing promise or a latency benchmark.

▂▄ GPT 6 Luna · low  = fits
auto · balanced (default) · classifier 807 ms

The model answers and calls tools. Periodic background reviews use bounded current-loop progress; a fresh recommendation may apply at the next request. Cost sensitivity and a short horizon can hold a costly switch, while strong capability advice can override the estimate. Pins, consent and generation safeguards still apply. Adaptive routing and switch policy → Read the status and take control →

Recent records cover 1,967 Pi responses across 25 sessions. They show route use, not guaranteed savings. See the chart, cost calculations, and limits →

Upgrading to 0.18.0

Recognized OpenAI activity defaults now use Terra at medium and cost/high. Quality defaults prefer a stronger model before more effort. Physical models and spending can change on reload, even for existing profiles. Generic user declarations and explicit activity overrides are not rewritten. Before upgrading, set profiles.<name>.activityPreset: "off" to retain legacy tier-mode behavior. Restart Pi or run /reload after updating; inspect Routes. See default ownership, opt-outs and mode tables.

Upgrading to 0.16.0

Restart Pi after updating. Configuration without mode routes as before. Project .pi/model-router.json files can now set only routes, activityRouting, display and mode (security fix). off/minimal effort at low and above disables that tier. Repeated tool failures now escalate one tier in every mode. Upgrade details →

Upgrading to 0.15.1

If you installed the optional classifier-catalog extension, replace its copy with the updated example before restarting Pi. This fixes startup failures in Pi 1.3.0's bundled loader. Updating the router package alone does not update that separate extension; follow the catalog update steps.

From 0.14

Restart Pi after updating. No routing-policy or configuration migration is required from 0.14. Routes and classifier controls now have their own tabs. Classifier enablement and profile approval remain in user configuration. History collection is still opt-in: /router log on collects new decisions. The inspector makes logging-off state explicit. Existing pins, effort settings, eligible-route safeguards and four-request review cadence remain unchanged.

From versions before 0.12.0

After updating, restart Pi. Replace /router-ui with /router, and /router <profile> with /router profile <name>. Classifier advice now uses any Pi-registered classifier. Replace provider-specific configuration with the generic advisor model and exact per-profile approvals. Classifier migration →

Old Jev/Clef/chat-classifier settings do not enable the current advisor. Follow the migration steps above even if the old file still loads without a warning.

Install

Requires Pi 1.1.0 or later in the 1.x series and Node.js 22.19.0+. Automated SDK/host gates run against Pi 1.1.0. The 0.15 native TUI checks use Pi 1.3.0 in agterm. The optional classifier-catalog example requires Pi 1.3+.

pi install npm:@alexeiled/pi-model-router

Then start a new Pi session. Create a profile with your available models →

If you use the upstream package, remove it first. Both packages register the router provider.


Independent fork of Ye Liu's pi-model-router, with the original MIT license and attribution.

版本与发布记录

@alexeiled/pi-model-router 共发布 29 个版本,首次发布于 2026/09/20;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.0latest2026/11/043 天前
0.18.22026/10/2810 天前
0.18.12026/10/2810 天前
0.18.02026/10/2711 天前
0.17.02026/10/2513 天前
0.16.02026/10/2216 天前

关于 @alexeiled/pi-model-router 的常见问题

@alexeiled/pi-model-router 是什么?

Pi model router with classifier-model routing, soft budget controls, and custom-provider support.

如何安装 @alexeiled/pi-model-router?

在项目目录运行 npm install @alexeiled/pi-model-router,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@earendil-works/pi-ai(^1.1.0)、@earendil-works/pi-tui(^1.1.0)、@earendil-works/pi-agent-core(^1.1.0)、@earendil-works/pi-coding-agent(^1.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alexeiled/pi-model-router 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/alexeiled__pi-model-router 是否存在。

@alexeiled/pi-model-router 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alexeiled/pi-model-router 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alexeiled/pi-model-router 可以商用吗?

@alexeiled/pi-model-router 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alexeiled/pi-model-router 的下载量有多少?

根据 npm 官方下载统计,@alexeiled/pi-model-router 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,762 次,日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alexeiled/pi-model-router 还在维护吗?

最新版本 0.19.0 发布于 2026/11/04(3 天前);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/09/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。