Intelligent Routing
How Brainstorm selects the optimal model for each task using 6 routing strategies.
Intelligent Routing
Brainstorm's router analyzes each task and selects the optimal model from your configured providers. Instead of using one model for everything, routing matches task characteristics to model strengths -- sending complex architecture questions to Opus, quick edits to Flash, and cost-sensitive bulk work to DeepSeek.
Routing Strategies
Quality-First
Selects the highest-quality model available for the task type. Best for critical code changes, architecture decisions, and complex debugging where accuracy matters more than cost.
``toml
[routing]
strategy = "quality"
`
Cost-First
Minimizes cost while meeting a minimum quality threshold. Ideal for high-volume tasks like documentation generation, simple refactoring, and bulk code formatting.
`toml
[routing]
strategy = "cost"
min_quality = 0.6 # minimum acceptable quality score
`
Combined (Default)
Balances quality and cost using a weighted score. The default strategy and recommended for most workflows.
`toml
[routing]
strategy = "combined"
quality_weight = 0.7
cost_weight = 0.3
`
Capability
Routes based on specific model capabilities rather than general quality scores. When a task requires tool calling, long context, or structured output, this strategy ensures the selected model supports those features.
`toml
[routing]
strategy = "capability"
`
Learned (Thompson Sampling)
Uses Bayesian optimization to learn which models perform best for your specific usage patterns. This is the most sophisticated strategy and improves over time.
The algorithm works in two phases:
1. Cold-start (UCB1): When data is sparse, uses Upper Confidence Bound to balance exploration and exploitation. Models with fewer observations get a confidence bonus to encourage trying them.
2. Steady-state (Gaussian Thompson Sampling): After sufficient observations, samples from a Gaussian posterior for each model and selects the one with the highest sampled value. This naturally balances exploration with exploitation.
`toml
[routing]
strategy = "learned"
exploration_factor = 0.1 # higher = more exploration
`
Rule-Based
Applies explicit routing rules you define. Rules match on task type, content patterns, or metadata and map to specific models.
`toml
[routing]
strategy = "rules"
[[routing.rules]]
match = { task_type = "code_generation", language = "python" }
model = "claude-opus-4-6"
[[routing.rules]]
match = { task_type = "explanation" }
model = "gemini-3.1-flash"
`
Understanding Routing Decisions
Use the storm route explain command to see why a particular model was selected:
`bash
storm route explain
``
This shows the task classification, candidate models, scoring breakdown, and final selection rationale. Useful for tuning your routing configuration.
Task Classification
The heuristic classifier analyzes each prompt and assigns a task profile with dimensions including:
- Complexity: How architecturally complex the task is
- Creativity: Whether the task needs creative problem-solving
- Precision: How exact the output needs to be
- Context dependency: How much project context is required
- Speed sensitivity: Whether latency matters
These dimensions feed into the routing strategy to produce the final model selection.
Fallback Chain
If the selected model is unavailable (rate limited, provider outage, or timeout), Brainstorm automatically falls back through a ranked chain of alternatives. The fallback chain respects your routing strategy -- a quality-first fallback still prefers high-quality alternatives.