Overview
ModelRouter implements ModelProvider and selects from configured tiers. It uses explicit rules first, then a local complexity heuristic. It does not measure model capability, compare prices, or guarantee savings. Choose tier models with evaluation data for your application.
Quick Start
This factory accepts two configured providers. It constructs an Agent without making a request; the caller owns running and closing that Agent.gpt-6-luna for the fast tier and gpt-6.1-sol for the capable tier, then measures both with the same quality cases.
Built-in Complexity Classifier
The v4 classifier inspects the last user message, conversation depth, tools, and response format. Signals include text length, code markers, reasoning keywords, complex instructions, tool count, and structured output. It makes no model call. These signals estimate prompt shape, not whether the answer will be correct. Tiers are sorted bymaxComplexity; the first threshold containing the score wins. If none matches, fallbackTier selects the tier, defaulting to the final sorted tier. Keep thresholds increasing and rule indices aligned with that order.
The exported configuration type includes classifier, but the v4 implementation always calls the built-in heuristic. Do not expect supplying a provider in that field to invoke an alternate classifier.
Custom Routing Rules
Rules run in order before heuristic routing. This host factory sends requests with more than five tools to the second tier.Outcome Tracking
Callrouter.getOutcomeStats() after requests. Each entry has tierIndex, total, successes, and rate. The bounded history records whether provider execution succeeded. A successful call is not a quality score; use eval scorers for answer correctness.
Events
The v4 router does not emit amodel.routed EventBus event. Use outcome statistics and provider-level instrumentation for visibility. See observability for the surrounding run and tool lifecycle.