routing
Routing
Routing acts as the traffic controller for an agentic system. Instead of a single generalist agent trying to handle every type of user request, a "Router" (often a fast, lightweight LLM or a classifier) analyzes the intent of the incoming message and delegates it to a specialized handler. This creates a system that is modular, scalable, and easier to maintain.
When to Use
- Specialization: When you have diverse tasks that require different prompts, tools, or context (e.g., Tech Support vs. Sales vs. Refund).
- Cost Optimization: To route simple queries to smaller/cheaper models and complex queries to reasoning models.
- Security: To ensure sensitive requests are handled by agents with stricter guardrails.
- SoC (Separation of Concerns): To keep individual agent prompts focused and clean.
Use Cases
- Customer Service Dispatch: Routing "My internet is down" to Tech Support and "How much is the upgrade?" to Sales.
- Model Selection: Routing logic puzzles to o1 and creative writing to GPT-4.
- Tool Selection: Deciding whether to use a Search tool, a Calculator, or a Database Query tool based on the question.
Implementation Pattern
def routing_workflow(user_query):
# Step 1: Classification
# The router's only job is to pick the right path.
intent = classify_intent(
prompt="Classify this query into: [SALES, SUPPORT, BILLING]",
input=user_query
)
# Step 2: Delegation
# Based on the intent, we call a specific sub-agent.
if intent == "SALES":
return sales_agent.run(user_query)
elif intent == "SUPPORT":
return support_agent.run(user_query)
elif intent == "BILLING":
return billing_agent.run(user_query)
else:
return default_agent.run(user_query)
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Wrong agent selected | Classifier underfitted | Add 50+ labeled examples per class; re-train or few-shot prompt |
| New query types not routed | No catch-all route | Add a "general" fallback route that handles out-of-distribution inputs |
| Routing adds too much latency | Heavy classifier | Use a lightweight keyword router as first stage; only call LLM when uncertain |
| Router and agent disagree on task scope | Misaligned schemas | Define a shared task schema; router populates it, agent consumes it |
More from lauraflorentin/skills-marketplace
multi-agent-collaboration
A structural pattern where multiple specialized agents communicate and coordinate to solve a problem that is too complex for a single agent. Use when user asks to "build a multi-agent system", "agents working together", "agent collaboration", or mentions team of agents, distributed agents, or swarm.
21reflection
A recursive pattern where an agent evaluates and critiques its own output to iteratively improve quality and catch errors. Use when user asks to "add self-reflection", "agent introspection", "self-critique", or mentions self-evaluation, meta-cognition, or quality self-assessment.
18human-in-the-loop
A hybrid pattern where the system pauses execution to request human approval, input, or disambiguation before proceeding with critical actions. Use when user asks to "add human approval", "require human review", "human-in-the-loop", or mentions approval workflows, human oversight, or escalation.
16planning
A high-level cognitive pattern where an agent formulates a structured sequence of actions (a plan) before executing any of them, ensuring goal-directed behavior. Use when user asks to "add planning to my agent", "task planning", "agent planning", or mentions plan generation, plan execution, or step-by-step planning.
14parallelization
A concurrency pattern where multiple agent tasks are executed at the same time to speed up processing or gather diverse perspectives. Use when user asks to "run agents in parallel", "parallelize tasks", "concurrent execution", or mentions parallel processing, fan-out, or batch execution.
13adaptation
A dynamic pattern where an agent system modifies its own behavior, prompts, or tools over time based on feedback or performance metrics. Use when user asks to "make my agent adaptive", "add learning capabilities", "self-improving agent", or mentions adaptive behavior, online learning, or feedback loops.
12