alinaqi/maggy/model-routing
- community
Checking that the SKILL.md file is still in the repository.
9-tier model routing system with cascading classifier fallback and result auto-evaluation
Install
npx vskill@latest install alinaqi/maggy/model-routingSKILL.md
Model Routing System
How Routing Decisions Are Made
Every user prompt goes through a 9-tier classification pipeline before any AI model processes it. The system answers three questions:
- Which model should handle this? — 9-tier cost/complexity classification
- Is the classifier itself working? — Cascading fallback (qwen3 → kimi → deepseek → cache)
- Can we verify the result? — Tool-level fallback + auto-evaluation
The Pipeline
9-Tier Routing Table
| Tier | Model | Input (per M) | Output (per M) | Handles | |
|---|---|---|---|---|---|
| 1 | Gemini 2.5 Flash-Lite | $0.10 | $0.40 | Bulk extraction, classification, CIG pipelines | |
| 2 | DeepSeek V4 Flash | $0.14 | $0.28 | Simple code, CRUD, test writing, small fixes | |
| 3 | DeepSeek V4 Pro | $0.44 | $0.87 | Multi-file features, refactors, debugging (~80% of work) | |
| 4 | Gemini 2.5 Flash | $0.15 | $0.60 | Multimodal (images, video, audio), brand analysis | |
| 5 | Kimi K2.6 | $0.60 | $2.50 | Code review, commit messages, diff summaries | |
| 6 | Gemini 3.1 Pro + Search | $1.25 | $10.00 | Deep research, Google grounding, 2M context | |
| 7 | Codex | varies | varies | Bulk generation, code review | |
| 8 | Claude Sonnet/Opus | $3-5 | $15-25 | Architecture, security, quality-critical |
Delegation Commands
When the hook says "delegate to X", run the matching command and return its output:
Delegation Script Contract
Every ~/bin/ script follows the same pattern:
- Accepts prompt as argument:
script "what is 2+2" - Model flags:
--flash,--pro,--flash-lite,--pro-search - Quiet mode:
--quiet(where applicable) - Output: writes response to stdout, errors to stderr
- Exit codes: 0 on success, non-zero on failure
Available Scripts
Classifier Fallback Chain
The classifier itself can fail. When it does, cascading fallback kicks in:
| Level | Classifier | Cost | Threshold | |
|---|---|---|---|---|
| 1 | qwen3 (Ollama) | $0 | 2s connect, 8s classify | |
| 2 | kimi CLI | $0 | Local process | |
| 3 | deepseek-flash | ~$0.0001 | API call | |
| 4 | Cached tier | $0 | From ~/.claude/routing-cache.json |
The cache (~/.claude/routing-cache.json) saves the last successful tier and timestamp. After compaction, when Ollama may be briefly unreachable, the cache ensures routing continues without dropping to CLAUDE by default.
Missing Wrapper Fallback
Before the hook emits a delegation instruction it checks that the tier's wrapper exists (the resolved flash/pro binary, ~/bin/gemini-api, ~/bin/gemini-cli, ~/bin/kimi, ~/bin/grok, or codex on PATH). If it is missing, the decision becomes ROUTING DECISION: CLAUDE (fallback from <tier>) and Claude handles the task directly, without the PLAN FIRST step. A cached tier the hook no longer knows is discarded the same way. There is no qwen3 delegation tier any more.
Tool Fallback Protocol
When Claude's built-in tools fail, external backends take over:
| Failed Tool | Fallback 1 | Fallback 2 | |
|---|---|---|---|
| WebSearch / WebFetch | ~/bin/research "query" | ~/bin/deepseek --pro "query" | |
| Read / file access | cat via Bash | — | |
| Grep | grep -r via Bash | — |
Research Tool (~/bin/research)
Multi-backend research with auto-evaluation:
- Tries deepseek-flash → deepseek-pro in sequence
- Scores results 0-10 on content quality, structure, length
- Auto-adjusts preferred backend based on evaluation scores
- View stats:
~/bin/research --eval - Score log:
~/.claude/research-eval.jsonl
Maggy Integration
Maggy's model_router.py mirrors the same 9-tier structure in DEFAULT_TIERS. The PiAdapter uses the same delegation scripts for execution. Task type overrides in routing_rules_defaults.py ensure:
research,competitor→ Gemini Pro Search (Google grounding)bulk→ Gemini Flash-Lite (cheapest)security,architecture,planning→ Claude (quality-critical)docs,tests→ DeepSeek Pro (cost-efficient)review→ Claude (security + architecture depth)
Environment
Observability
- Routing log:
~/.claude/routing-log.jsonl— every classification with tier, classifier used, tokens saved - Routing cache:
~/.claude/routing-cache.json— last tier for post-compact recovery - Research eval:
~/.claude/research-eval.jsonl— per-query backend scoring - Maggy routing heatmap: Dashboard → Models tab → per-model reward scores
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/model-routing/SKILL.md
Popularity
- Repository stars
- 701
- Repository forks
- 55
- 7-day trend score
- 33
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alinaqi/maggy/model-routing)