Learn Agentic Patterns
CoursesInterviewSchoolVideosAI agent videosAI now
Learn Agentic Patterns

Learn agentic AI, then get interviewed on it. A free course, four job paths, a daily broken agent, and the interview.

learnagenticpatterns.com

Navigation

HomeThe courseThe interviewPatterns (developer track)PM trackBlogCareer GuideAboutSign Up

Connect

Cheat sheet (free PDF)Reskilling guideLinkedIn (Mousa Jawaheri)

© 2026 learnagenticpatterns.com

Privacy PolicyTerms of Service

Based on “Agentic Design Patterns” by Antonio Gullí

> All Patterns

[01]Prompt Chaining[02]Routing[03]Parallelization[04]Reflection[05]Tool Use[06]Planning[07]Multi-Agent Collaboration[08]Memory Management[09]Learning & Adaptation[10]State Management (MCP)[11]Goal Setting & Monitoring[12]Exception Handling & Recovery[13]Human-in-the-Loop[14]Knowledge Retrieval (RAG)[15]Inter-Agent Communication (A2A)[16]Resource-Aware Optimization[17]Reasoning Techniques[18]Guardrails & Safety[19]Evaluation & Monitoring[20]Prioritization[21]Exploration & Discovery[22]Boundary Translation
HomeCurriculumRouting
Pattern [02]

Routing

≈ Load Balancer / API Gateway / Strategy Pattern

[02]

TL;DR

Dynamically directing a user request to the most appropriate specialized agent, model, or processing path based on the semantic intent and complexity of the query. A "Router" classifies the input and delegates execution to a downstream handler optimized for that specific task.

SWE: Load Balancer / API Gateway
Architecture Flow
agentgate
Intent ClassifieragentBilling AgentagentTechnical AgentagentGeneral Agentagent

> Agentic Definition

Routing involves dynamically directing a user request to the most appropriate specialized agent, model, or processing path based on the semantic intent and complexity of the query. Instead of a single general-purpose model handling everything, a "Router" (often a smaller, faster model) classifies the input and delegates execution to a downstream handler optimized for that specific task.

Before: Traditional Rule-Based Routing

Traditional Rule-Based Routing
1# Rule-based routing
2def route(request):
3 if request.path.startswith("/billing"):
4 return billingService.handle(request)
5 elif request.path.startswith("/support"):
6 return supportService.handle(request)
7 else:
8 return defaultService.handle(request)

After: Semantic Routing Architecture

Semantic Routing Architecture
1# Agentic Routing
2def route_request(user_query):
3 # The Router is an Agent (or a classifier) itself
4 # It decides the 'Strategy' at runtime
5 intent = classification_agent.invoke(
6 prompt="Classify intent: BILLING, SUPPORT, or GENERAL?",
7 input=user_query
8 )
9
10 if intent == "BILLING":
11 # Route to a model fine-tuned for financial data
12 return billing_agent.run(user_query)
13 elif intent == "SUPPORT":
14 # Route to a RAG-equipped agent with technical docs
15 return support_agent.run(user_query)
16 else:
17 # Route to a general-purpose frontier model
18 return general_agent.run(user_query)

Traditional SWE

Load Balancer / API Gateway

≈maps to

Agentic Pattern

Routing

≈How They're Similar

Both mechanisms exist to optimize resource usage, enforce separation of concerns, and ensure that a request is handled by the component best suited for it. Just as an API Gateway inspects a request header or URL path to route traffic to the correct backend microservice, an Agentic Router inspects the meaning of a prompt to route it to the correct downstream agent.

≠Key Divergence

Traditional routing is rule-based and syntactic (RegEx, URL paths, headers). Agentic routing is semantic; it requires an LLM call or a vector similarity search to classify intent. This introduces a probabilistic element at the very entry point of the system — the router itself can "misunderstand" the destination.

> Production Considerations

01

Using a frontier model (e.g., GPT-4) for the routing step is often overkill and expensive. A best practice is to use a smaller, faster model (e.g., fine-tuned Llama 3, Gemini Flash) or even a simple BERT classifier for the routing step to minimize overhead.

02

The router is a single point of failure. If it misclassifies, the user gets a wrong answer even if the downstream agents are perfect. You must evaluate the router using a Confusion Matrix to track misclassifications (e.g., Support queries routed to Billing).

💡

Key Takeaway

Adapt: The "Controller" in your MVC architecture is now an AI. You are architecting a system where control flow is determined by natural language classification, not hard-coded logic paths. You must verify the accuracy of this "Semantic Switch."

BuildBuild a Multi-Path Request Handler. Create a system that classifies incoming support requests and routes them to the correct specialist agent based on intent.

DebugDebug: Routing. Billing questions keep hitting the technical team. No request is going to the right agent. What's missing?

OptimizeOptimize a Request Router. Your routing system uses Claude 3.5 Sonnet for classification and three specialist agents. The classifier runs on every request but most requests are simple. Monthly cost: $8,500. Target: under $3,400.

PromptWrite an Intent Classifier Prompt. You're building a routing system that classifies incoming requests and sends them to specialist agents. Write the system prompt for the Intent Classifier that sits at the entry point.

Frequently Asked Questions

When should I use the Routing pattern?

Routing involves dynamically directing a user request to the most appropriate specialized agent, model, or processing path based on the semantic intent and complexity of the query. Instead of a single general-purpose model handling everything, a "Router" (often a smaller, faster model) classifies the input and delegates execution to a downstream handler optimized for that specific task.

How does Routing relate to Load Balancer / API Gateway / Strategy Pattern?

Both mechanisms exist to optimize resource usage, enforce separation of concerns, and ensure that a request is handled by the component best suited for it. Just as an API Gateway inspects a request header or URL path to route traffic to the correct backend microservice, an Agentic Router inspects the meaning of a prompt to route it to the correct downstream agent. However, there is a key divergence: Traditional routing is rule-based and syntactic (RegEx, URL paths, headers). Agentic routing is semantic; it requires an LLM call or a vector similarity search to classify intent. This introduces a probabilistic element at the very entry point of the system — the router itself can "misunderstand" the destination.

What are the production trade-offs of Routing?

Using a frontier model (e.g., GPT-4) for the routing step is often overkill and expensive. A best practice is to use a smaller, faster model (e.g., fine-tuned Llama 3, Gemini Flash) or even a simple BERT classifier for the routing step to minimize overhead. The router is a single point of failure. If it misclassifies, the user gets a wrong answer even if the downstream agents are perfect. You must evaluate the router using a Confusion Matrix to track misclassifications (e.g., Support queries routed to Billing).

Next Pattern

[03] · Parallelization