← All Patterns
Model Router Pattern diagram
Model Router Pattern — structural diagram

Motivation

Agents that hardcode model choices cannot adapt to cost constraints, latency requirements, or governance policies. As model providers and capabilities evolve, every agent would require modification.

The Model Router Pattern introduces a routing layer between agents and model providers. Routing decisions are governed, scored, persisted, and auditable. Agents simply declare what they need — the router decides which model serves that need.

Structure

Key Concepts

BaseModelRouter K9ModelRouter InferenceRequest RouteDecision routing state store weighted scoring: +3 task_type, +2 sensitivity, +2 latency, +2 cost

Used in K9-AIF

BaseModelRouter K9ModelRouter ModelRouterFactory llm_invoke() routing_state_store (SQLite / PostgreSQL) all K9-AIF agents