Routing
Routing classifies an incoming request and directs it to a specialist durable task. A single entry point handles all requests; the routing logic (an LLM call, a rule-based check, or a keyword match) determines which downstream task runs. Only one branch executes per request.
This pattern improves response quality because each specialist task has its own prompt, tools, and context optimized for that category. It also simplifies the caller: trigger one task and let the router decide where to send it.
When to use
| Scenario | Fit |
|---|---|
| Customer service (support vs. sales vs. billing) | Good: distinct domains with different prompts and tools |
| Document processing (invoice vs. receipt vs. contract) | Good: each type needs different extraction logic |
| Request triage (simple auto-reply vs. complex agent) | Good: avoid expensive agent loops for easy questions |
| All requests follow the same path | Skip: no benefit from routing |
| Routing rules are simple and known at definition time | Use Parent Conditions in a DAG instead |
How it maps to Hatchet
The router is a durable task. It spawns a classifier child task (or does classification inline), then spawns the matching specialist as a child run. Since each specialist is a separate durable task, they can have their own timeouts, retries, rate limits, and concurrency settings.
Routing decisions are checkpointed. If the worker dies after classification but before the specialist finishes, the router resumes and does not re-classify.
Step-by-step walkthrough
Define the classifier task
A separate task classifies the incoming message. This lets you observe the classification result and retry independently if the LLM fails.
Define the specialist tasks
Each specialist is a standalone durable task with its own prompt and tools. They run independently with their own timeout and retry settings.
Route with a durable task
The router classifies the message, then spawns the matching specialist. The classification result is checkpointed, so if the worker dies after classifying, it resumes and spawns the specialist without re-classifying.
Run the worker
Register all tasks and start the worker.
For simple routing based on input fields (not LLM classification), you can
skip the classify task and route directly in the durable task body based on
input.type or similar fields.
Routing vs. DAG branching
| Routing (durable task) | DAG Parent Conditions | |
|---|---|---|
| Branch decided by | Runtime code (if/else, LLM call) | Declared conditions on parent task output |
| Use when | Category is unknown until an LLM classifies it | Branch criteria are known at workflow definition time |
| Observability | Router + specialist appear as separate runs | All branches visible in the DAG graph |
Related Patterns
Like routing but with a loop: the orchestrator may call multiple specialists across iterations.
Multi-AgentDAG-level branching for when routing rules are fixed at definition time.
Parent ConditionsAn agent loop can use routing internally to pick tools per iteration.
Reasoning LoopFixed-sequence pipelines; route to different pipelines based on input type.
LLM PipelinesNext Steps
- Durable Task Execution: understand how the router and specialists checkpoint
- Child Spawning: spawn specialist tasks from the router
- Timeouts: set execution timeouts on the router and each specialist
- Retry Policies: configure retries for classification and specialist tasks