Router pattern
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn Router pattern
Overview
- A router chooses a specialized path based on the request.
- It can use deterministic rules, a classifier, or an LLM with a bounded enum output.
- Routing does not automatically require a full agent loop.
Why this matters
One prompt and toolset for every intent can be confusing and overprivileged.
An everyday example
Reception directs people to claims, policy support, or billing.
A technical example
claim_status → exact tool; policy_question → RAG; unclear → clarification.
How it works
- Validate request
- Classify
- Validate route enum
- Apply route-specific permissions
- Execute route.
Architecture and flow
Request → router → claim / policy / human path.
The insurance assistant example
Separate customer-data lookup from public policy explanations.
When to use it
Several clear task categories with different capabilities.
When to avoid it
A single narrow task needs no model-based router.
Interview answer
“Routing narrows the task and allowed capabilities. I use rules for obvious cases and a validated classifier for language ambiguity.”
Benefits, trade-offs, and production considerations
Routing mistakes must remain safe. Every destination rechecks authorization, and unknown categories have a clarification or escalation path.
Adapted from 13_AI.MD · “Router pattern”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.