You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All requests are currently routed to whichever provider/model the caller specifies. Simple prompts (short, no tools) are sent to the same expensive model as complex multi-turn reasoning tasks. Routing simple prompts to cheaper model tiers (Haiku, gpt-4o-mini, Flash) is the single largest cost multiplier after caching — potentially 8–60x reduction on those requests.
Reference: docs/LLM-COST-OPTIMIZATION.md — Intelligent Model Routing section.
Proposed Design
// types.go or router.gotypeComplexityTierintconst (
TierFastComplexityTier=iota// Haiku, gpt-4o-mini, FlashTierBalanced// Sonnet, gpt-4o, ProTierPowerful// Opus, o1, Pro Deep Research
)
typeComplexityClassifierinterface {
Classify(req*Request) ComplexityTier
}
Default heuristic (middleware/complexity.go):
TierFast: prompt < 500 tokens AND no tools defined
TierPowerful: tools present OR prompt > 2000 tokens
TierBalanced: everything else
WithComplexityClassifier(classifier ComplexityClassifier, tierModels map[ComplexityTier]string) router option maps tiers to model names, overriding the request's model field before dispatch.
Why this is a library concern
The tier→model mapping is provider-agnostic. The heuristic default is universally applicable. Service-level code (cai-llm-router) wires concrete model names per agent; the library provides the interface and classification logic.
Acceptance Criteria
ComplexityClassifier interface and ComplexityTier constants defined
Default heuristic classifier implemented with the thresholds above
Activity