feat(virtualmodels): add the auto strategy that routes by target level
SA
3d ago+2936+2936+0123456789012345678901234567890123456789-326-326-012345678901234567890123456789
Description
Adds a virtual-model strategy, auto, that routes by level. Each target declares how capable it is, and a request goes to the lowest level that covers what it needs.
virtual_models:
- source: claude-auto
strategy: auto
targets:
- { model: anthropic/claude-haiku-5-5, level: light }
- { model: anthropic/claude-sonnet-5-5, level: smart }
- { model: anthropic/claude-opus-5-5, level: smartest }
Behaviour
- Levels are
light,normal,smart,smartest. Underautoevery target needs one; other strategies drop them. - A request is served from the lowest level at or above the one it needs. A request nothing classified gets the highest level, so without a classifier the route always uses its most capable targets.
- When no target at or above the needed level can serve (down, denied, rate limited), the highest level below it serves.
- Targets sharing a level are balanced by weighted round robin, or by the adaptive route selector when one is registered. Each level has its own rotation, and a session keeps one pin per level.
- Failover tries the rest of the served level, then higher levels going up, then lower ones going down.
- An auto route cannot route into another auto route (rejected at save). A single-target alias of one works.
X-GoModel-Route-Levelreports the level of the target the route chose first.
Who says what a request needs
Core has no classifier. A request rewriter names the level in the new ext.Result.RouteLevel, and can ask whether a model is an auto route through ext.AutoRoutes (ext.AutoRoutesAware). GoModel Pro's smart routing uses both; its docs page is rewritten here. Internal model calls made on a request's behalf (guardrails, plugins) do not inherit the request's level.
Also in this PR
- Dashboard:
Autoin the strategy picker, a level select per target, a warning when no target issmartest, and level pills in the models list. - Docs in en/de/pl/zh,
config.example.yaml,.env.template, and regenerated OpenAPI. The de/pl/zh text has not had a native review.
Notes for review
- Existing strategies are unchanged: for them the failover order and pin keys are what they were.
- A level is validated before a snapshot is built, so a stored row without one cannot reach the level logic.
- The route level travels in the request context from the rewrite middleware to resolution; the level the route chose travels back through
core.WithServedRouteLevel, so the header and the failover order follow the target that was actually chosen.
Summary by CodeRabbit
- New Features
- Added automatic routing for virtual models based on request needs and target capability levels, with fallback and failover across levels.
- Added per-level load balancing and session affinity, plus a response header identifying the initially selected level.
- Added dashboard controls, level indicators, validation, and configuration guidance for automatic routing.
- Smart Routing can classify requests into capability levels for automatic routes; adaptive routing can select providers within a level.
- Documentation
- Updated routing guides and examples across supported languages to explain automatic routing, levels, session behavior, and configuration.