#7770: feat(routing): Smart Router V2 - Configuration-driven model dispatching
agents
stale
Cluster:
Model Management Enhancements
Note: AI-assisted 🤖 | Verified locally ✅
Overview
This PR introduces Smart Router V2, an architectural upgrade to the model routing engine. It shifts the logic from hardcoded rules to a flexible, configuration-driven system (router_config.json), allowing for more granular control over model selection based on task type and context length.
Key Changes
SMRP-style Configuration: Routing is now managed via router_config.json. Users can define custom priority chains for different task categories (e.g., coding, creative, architecture).
Context Waterline Guard: Implements a "50% safety threshold" logic. The router automatically filters out models that are nearing their context limits to prevent overflow errors and optimize costs.
Improved Dispatching Logic: Re-orders model selection to prioritize best-fit models (like Kimi for logic/coding) while maintaining Gemini as a robust fallback for massive contexts.
Code Hygiene: Fully compliant with project Lint rules (including mandatory curly braces for control flow).
Testing Done
pnpm build: Verified that TypeScript compilation passes without errors.
pnpm check: Linted via oxlint to ensure 100% compliance with style guidelines.
Local Runtime Test:
Verified on a live Windows instance.
Confirmed successful model switching between Gemini, Kimi, and DeepSeek based on real conversation prompts.
Validated that router_config.json hot-reloads correctly without gateway restarts.
Transparency
This PR was developed with AI assistance (OpenClaw + Gemini 2.0). I have reviewed the generated code for security and architectural alignment. Importantly, this PR is focused solely on routing logic and contains no private configurations or experimental caching implementations.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new configuration-driven “Smart Router V2” layer (`src/agents/smart-router.ts`) plus a persistent “model experience” store (`src/agents/model-experience.ts`) intended to categorize tasks and maintain per-model performance/usage stats under `CONFIG_DIR`.
The router supports manual prompt prefixes (e.g. `!kimi`, `!pro`) and a config-defined `routes` priority chain, with a context “waterline” filter to drop models that are near their configured context limit. `pi-embedded-runner/run.ts` was touched to import the router, but it is not currently wired into the request flow.
Key concerns are around correctness of hot-reload behavior (stale config on invalid JSON), persistence robustness (experience save doesn’t ensure parent dir exists), and a shallow merge that can unintentionally discard default model data when a user file contains partial structures.
<h3>Confidence Score: 3/5</h3>
- This PR is moderately safe to merge but has a few correctness and integration gaps worth fixing first.
- The core additions are self-contained, but there are a couple of issues that will likely bite in real use: the embedded runner imports the router without using it, config hot-reload can silently keep stale state on parse errors, and experience persistence/merging can behave unexpectedly on first run or with partial user files. None look like security-critical vulnerabilities, but they affect expected behavior and reliability.
- src/agents/model-experience.ts, src/agents/smart-router.ts, src/agents/pi-embedded-runner/run.ts
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#9123: Feat/smart router backport and custom model provider
by JuliusYang3311 · 2026-02-04
81.7%
#16677: feat(routing): intelligent model routing via pre-route hook
by gonesurfing · 2026-02-15
79.4%
#7570: fix: allow models from providers with auth profiles configured
by DonSqualo · 2026-02-03
77.9%
#15264: feat: Dynamic thinking level pre-routing based on message complexity
by phani-D · 2026-02-13
77.1%
#8258: feat: Add smart model tiering for cost optimization
by revenuestack · 2026-02-03
75.9%
#5947: Feature/kimi reasoning support
by zzjj7000 · 2026-02-01
75.6%
#13376: fix: pass model directly to agent for sub-agent runs
by jrbobbyhansen-pixel · 2026-02-10
75.2%
#5945: fix: use configured model for slug generator (AI-assisted)
by HEDELKA · 2026-02-01
74.7%
#7981: fix(runner): use configured primary model as fallback default
by PiyushDuggal-source · 2026-02-03
74.6%
#14647: feat(plugins): allow before_agent_start hook to override model (#14...
by lailoo · 2026-02-12
74.3%