Routing automatically selects the best model for each prompt based on its complexity. Simple tasks go to faster, cheaper models. Complex tasks go to more capable ones. You control the thresholds.
How It Works
When routing is enabled, every prompt goes through a classifier:
- Score the prompt — scan for low-signal and high-signal keywords
- Factor in length — longer prompts get a complexity boost
- Pick a tier —
Low,Medium, orHigh - Select model — ask the provider for the best model at that tier
Enabling Routing
[agent.routing]
enabled = true
low_keywords = ["typo", "rename", "format"]
high_keywords = ["refactor", "architect", "security audit"]
Classification Logic
The classifier uses two keyword lists (built-in defaults + your custom keywords):
Low-signal keywords (simple tasks):
typo, rename, format, lint, simple, quick, docs
High-signal keywords (complex tasks):
architect, design, refactor, security, optimize, performance, debug, analyze
Scoring:
- Count matches against low keywords → low score
- Count matches against high keywords → high score
- Length boost:
- More than 200 words → high score +2
- More than 80 words → high score +1
- Result:
- High score > low score → High tier
- Low score > high score → Low tier
- Tie → Medium tier
Model Selection
Once a tier is determined, Nyzhi asks the provider for an appropriate model:
select_model_for_prompt(prompt, provider, config)
The provider returns its best model for the tier. If no tier-specific model exists, it falls back to the provider’s default model.
Example
With this config:
[agent.routing]
enabled = true
low_keywords = ["fix typo", "rename variable"]
high_keywords = ["redesign the auth system", "optimize database queries"]
| Prompt | Tier | Why |
|---|---|---|
| ”Fix the typo in README” | Low | Matches “fix typo" |
| "Add a new endpoint for /users” | Medium | No strong signals either way |
| ”Redesign the auth system to use JWT with refresh tokens and role-based access” | High | Matches “redesign the auth system” + long prompt |
When to Use Routing
Routing works best when:
- Your provider has distinct model tiers (fast/cheap vs powerful/expensive)
- You have a mix of simple and complex tasks
- You want to reduce costs without sacrificing quality on hard problems
Tips
- Keep keyword lists short — 5-10 keywords per list is plenty
- Use specific phrases — “fix typo” is better than “fix”
- Test your keywords — make sure simple prompts actually route to the low tier
- Don’t over-engineer — if you mostly do complex work, routing may not save much
Next Steps
- Providers — model tiers by provider
- Configuration — routing config reference