smart-model-run
v0.2.0
Published
Benchmark-driven smart model selection and fallback runner for agent workloads.
Readme
smart-model-run
Benchmark-driven smart model selection and fallback execution for agent workloads.
Install
pnpm add smart-model-runFor local development from the-watch:
{
"dependencies": {
"smart-model-run": "file:../smart-model-run"
}
}Usage
import { smartRun } from "smart-model-run";
const result = await smartRun({
budget: "cheap",
ceiling: "mid",
thinking: "low",
prompt: "Review this diff for correctness issues.",
tools: ["read", "grep", "find", "ls"],
needs: ["tools", "correctness", "codeQuality"],
cwd: process.cwd(),
runner: async (input) => runYourAgent(input),
fallbackSelectors: ["openai/gpt-4o-mini"],
});The library fetches model benchmark metadata from aistupidlevel.info, caches it at
~/.pi/agent/model-rankings.json for 6 hours, and falls back to cached rankings
on network failure.
Local-only mode
Use local: true when callers must stay on local providers (ollama/*,
lmstudio/*, or local/*):
await smartRun({
prompt,
budget: "cheap",
local: true,
needs: ["correctness", "codeQuality"],
modelRegistry,
runner,
thinking: "low",
tools: ["read", "grep", "find", "ls"],
cwd: process.cwd(),
});Local mode prefers enumerable local models from the Pi model registry, ranks them for code/review work, skips remote benchmark fetching by default, and appends this fallback chain for brittle or non-enumerable local setups:
ollama/ornith:35bollama/qwen2.5-coder:32bollama/qwen2.5-coder:14bollama/ornith:9bollama/ornith:7bollama/qwen2.5-coder:7bollama/llama3.1:8b
Local runs also use a longer default timeout of 10 minutes unless timeoutMs is
provided.
Core exports
smartRun()— select ranked candidates, run them, and fallback on failure.pickModels()— rank models within a budget tier.pickModelsAcrossBudget()— escalate across allowed budget tiers when no model meetsminMatch.getRankings()/forceRefreshRankings()— fetch and cache live benchmark rankings.formatSmartRunSummary()/formatRankings()— human-readable summaries.
