Router Pattern
The Router Pattern is an architectural pattern used in AI Agents and Agentic RAG where a classifier or LLM acts as a dispatcher, evaluating incoming user queries and routing them to the most appropriate execution path, index, or tool.
Core Functions
- Query Classification: Classifies intent (e.g., technical support vs. billing vs. general conversation).
- Index/Tool Selection: Directs queries to specific search indexes (e.g.,
vector_search(),sql_query(), orweb_search()). - Cost & Latency Optimization: Can route simpler queries to SLMs (Small Language Models) or cache, reserving larger models for complex tasks.
Common Approaches
- LLM-based Routing: Using function calling or structured outputs (Pydantic/JSON schema) to return a destination route.
- Semantic Routing: Computing query embeddings and using vector distance against fixed route vectors for ultra-fast, low-cost routing.
- Keyword / Heuristic Routing: Using deterministic rules or BM25 classifiers for predictable routing.
