๐Ÿšฆ Routing

July 10, 2026 ยท View on GitHub

๐Ÿ  Home โ€บ Workflows โ€บ ๐Ÿšฆ Routing

โ† 01 Prompt Chaining โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 03 Parallelization โ†’


๐Ÿšฆ Routing

TL;DR: Classify an input and direct it to a specialized handler. Like a train switch โ€” one input takes ONE track.


Diagram

%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
    classDef user fill:#6366f1,stroke:#4f46e5,stroke-width:2px,color:#ffffff
    classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
    classDef subagent fill:#ec4899,stroke:#db2777,stroke-width:2px,color:#ffffff
    classDef idle fill:#94a3b8,stroke:#64748b,stroke-width:2px,color:#ffffff

    INPUT["๐Ÿ™‹โ€โ™€๏ธ๐Ÿ“ฅ User Request"]:::user --> ROUTER{"๐Ÿ”๐Ÿšฆ Classify & Route"}:::main

    ROUTER -.->|"Type A"| HA["๐Ÿฆ๐Ÿ’ค Handler A"]:::idle
    ROUTER -->|"๐Ÿ”๐Ÿชบ Type B"| HB["๐Ÿฆโšก Handler B"]:::subagent
    ROUTER -.->|"Type C"| HC["๐Ÿฆ๐Ÿ’ค Handler C"]:::idle
    ROUTER -.->|"Unknown"| DEFAULT["๐Ÿ”๐Ÿ’ค Default"]:::idle

    HB -->|"๐Ÿฆ๐Ÿ“ค"| FINAL["๐Ÿ’โ€โ™€๏ธ๐Ÿ“ค User Receives"]:::user

Key Insight

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿšฆ ROUTING: Choose ONE branch                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚  Logic: if/else, switch/case                                                โ”‚
โ”‚  Question: "Where should I send this?"                                      โ”‚
โ”‚  Result: Single output from chosen handler                                  โ”‚
โ”‚                                                                             โ”‚
โ”‚  Analogy: Train switch โ†’ One train takes ONE track                          โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Characteristics

PropertyValue
ComplexityLow
ParallelismNone
Human-LoopNone
IterationNone

When to Use

Routing works well for complex tasks where there are distinct categories that are better handled separately, and where classification can be handled accurately.

Use CaseRoutes
Customer supportBug โ†’ Tech Team, Billing โ†’ Finance, General โ†’ FAQ
Code tasksBug fix โ†’ Debugger, New feature โ†’ Builder
Model routingEasy โ†’ Claude Haiku 4.5, Hard โ†’ Claude Sonnet 4.5
ContentQuestion โ†’ Q&A handler, Task โ†’ Executor

When NOT to Use

  • All inputs require same processing
  • Classification is unreliable
  • Categories overlap significantly


๐Ÿ“œ This pattern, as a file

Runnable version (offline mock, no API key ยท nika check proves the DAG before any token is spent): patterns-as-code/02-routing.nika.yaml โ€” see Patterns as Code.

โ† 01 Prompt Chaining โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 03 Parallelization โ†’