Conditional Routing with Switch Nodes¶
Intermediate
In this tutorial, you will build a workflow that classifies incoming messages and routes them to different specialized agents. A customer support scenario is used as the example: messages are categorized as billing, technical, or general, and each category is handled by a dedicated agent with domain-specific instructions.
Time: 20 minutes
What you will build:
flowchart LR
CT[Chat Trigger] --> Cat[Categorizer]
CatModel[AI Model<br/>gpt-4o-mini] -.->|llm| Cat
Cat --> SW[Switch]
SW -->|billing| BA[Billing Agent]
SW -->|technical| TA[Technical Agent]
SW -->|general| GA[General Agent]
BAModel[AI Model] -.->|llm| BA
TAModel[AI Model] -.->|llm| TA
GAModel[AI Model] -.->|llm| GA
style CT fill:#f97316,color:white
style CatModel fill:#3b82f6,color:white
style BAModel fill:#3b82f6,color:white
style TAModel fill:#3b82f6,color:white
style GAModel fill:#3b82f6,color:white
style SW fill:#3b82f6,color:white Prerequisites¶
- Pipelit is installed and running
- You have an LLM credential configured
- You have completed the Chat Agent tutorial (recommended)
Concepts¶
Before building, here is how conditional routing works in Pipelit:
- A Categorizer node uses an LLM to classify input text into one of several predefined categories.
- The Categorizer outputs a
_routevalue matching the category name. - A Switch node reads the route value from the workflow state.
- Conditional edges on the Switch node direct execution to different downstream nodes based on the route value.
Only the branch matching the current route executes -- the other branches are skipped.
Step 1: Create the workflow¶
- On the Dashboard, click New Workflow.
- Name it
Support Routerand click Create.
Step 2: Add a Chat Trigger¶
- From the Node Palette under Triggers, click Chat.
- A Chat Trigger node appears on the canvas.
Step 3: Add a Categorizer¶
The Categorizer uses an LLM to classify the incoming message into one of your defined categories.
- From the Node Palette under AI, click Categorizer.
- Click on the Categorizer node to select it.
-
In the Node Details Panel, configure the categories in Extra Config:
{ "categories": [ { "name": "billing", "description": "Questions about invoices, payments, refunds, pricing, or subscription plans" }, { "name": "technical", "description": "Bug reports, errors, feature requests, integration help, or API questions" }, { "name": "general", "description": "Greetings, general inquiries, feedback, or anything that does not fit the other categories" } ] } -
Optionally, add a System Prompt to provide classification guidance:
Connect an AI Model to the Categorizer¶
- Add an AI Model node from the Node Palette.
- Configure it with your credential and a model. A smaller, cheaper model like
gpt-4o-miniworks well for classification since the task is straightforward. - Connect the AI Model's top diamond handle to the Categorizer's "model" diamond handle (blue).
Use a cheaper model for classification
The Categorizer makes a single LLM call to classify input. A smaller model reduces cost and latency without sacrificing classification quality for well-defined categories.
Step 4: Add a Switch node¶
The Switch node reads the route value set by the Categorizer and directs execution down the matching conditional edge.
- From the Node Palette under Routing (or Logic), click Switch.
- A Switch node appears on the canvas.
The Switch node does not require configuration for this use case -- it reads the _route value from the workflow state, which the Categorizer sets automatically.
Step 5: Add specialized agents¶
Create three agent nodes, one for each category.
Billing Agent¶
- Add an Agent from the Node Palette.
-
Set its System Prompt:
You are a billing support specialist. Help customers with: - Invoice questions and payment issues - Subscription plan details and upgrades - Refund requests and billing disputes - Pricing clarification Be empathetic and solution-oriented. If the issue requires account access you do not have, escalate to a human agent. -
Add an AI Model node and connect it to this agent's model handle.
Technical Agent¶
- Add another Agent.
-
Set its System Prompt:
You are a technical support engineer. Help customers with: - Bug reports and error troubleshooting - API integration questions - Feature requests (acknowledge and log them) - Configuration and setup assistance Ask clarifying questions when the issue is ambiguous. Include specific steps in your solutions. -
Add an AI Model node and connect it.
General Agent¶
- Add a third Agent.
-
Set its System Prompt:
You are a friendly general support agent. Handle: - Greetings and casual conversation - General product inquiries - Feedback and suggestions - Anything that does not fit billing or technical categories Be warm and helpful. Redirect to specialized support if the conversation turns technical or billing-related. -
Add an AI Model node and connect it.
Sharing AI Model nodes
Each agent needs its own AI Model connection. You can use the same credential and model across all of them, but each requires a separate AI Model node on the canvas.
Step 6: Connect the nodes¶
Data flow connections¶
- Chat Trigger -> Categorizer: Right handle to left handle.
- Categorizer -> Switch: Right handle to left handle.
Conditional edges from the Switch¶
Conditional edges are created differently from regular edges. Each conditional edge carries a condition_value that must match the route.
- Switch -> Billing Agent: Drag from the Switch's right handle to the Billing Agent's left handle. When the edge creation dialog appears, set the condition value to
billing. - Switch -> Technical Agent: Same process, with condition value
technical. - Switch -> General Agent: Same process, with condition value
general.
Conditional edge labels
On the canvas, conditional edges display their condition value as a label on the edge (e.g., "billing", "technical", "general"). This makes it easy to see the routing logic at a glance.
The complete workflow¶
flowchart LR
CT[Chat Trigger] --> Cat[Categorizer]
CM[AI Model] -.->|llm| Cat
Cat --> SW[Switch]
SW -->|billing| BA[Billing Agent]
SW -->|technical| TA[Technical Agent]
SW -->|general| GA[General Agent]
BM[AI Model] -.->|llm| BA
TM[AI Model] -.->|llm| TA
GM[AI Model] -.->|llm| GA
style CT fill:#f97316,color:white
style CM fill:#3b82f6,color:white
style BM fill:#3b82f6,color:white
style TM fill:#3b82f6,color:white
style GM fill:#3b82f6,color:white
style SW fill:#3b82f6,color:white Step 7: Validate and test¶
Validate the workflow¶
Before testing, validate the workflow to catch any configuration errors:
- Click the Validate button (or use
POST /api/v1/workflows/{slug}/validate/). - Fix any reported issues (e.g., missing model connections, unconnected nodes).
Test with different messages¶
Open the Chat panel and try messages that should route to each category:
Billing message:
I was charged twice on my last invoice. Can you help me get a refund?
Expected: Categorizer outputs billing -> Switch routes to Billing Agent.
Technical message:
I am getting a 500 error when I try to use the API endpoint for user creation.
Expected: Categorizer outputs technical -> Switch routes to Technical Agent.
General message:
Hi there! I just wanted to say I love your product.
Expected: Categorizer outputs general -> Switch routes to General Agent.
Observe execution on the canvas¶
As each message is processed:
- The Chat Trigger lights up (running -> success).
- The Categorizer lights up and makes an LLM call to classify the message.
- The Switch node lights up and evaluates the route.
- Only the matching downstream agent lights up -- the other two stay idle.
Click the green "output" link on the Categorizer node after execution to see the classification result:
Variations¶
Using a Switch node with custom rules¶
Instead of using a Categorizer (which requires an LLM call), you can configure the Switch node with pattern-matching rules for simpler routing:
{
"rules": [
{"field": "text", "operator": "contains", "value": "invoice", "route": "billing"},
{"field": "text", "operator": "contains", "value": "refund", "route": "billing"},
{"field": "text", "operator": "contains", "value": "error", "route": "technical"},
{"field": "text", "operator": "contains", "value": "bug", "route": "technical"}
],
"default_route": "general"
}
This approach is faster and cheaper (no LLM call) but less flexible than LLM-based classification.
Adding a default/fallback route¶
If the Categorizer returns a category that does not match any conditional edge, the Switch node falls back to a default route. Add a conditional edge with condition value default to handle unrecognized categories:
flowchart LR
SW[Switch] -->|billing| BA[Billing Agent]
SW -->|technical| TA[Technical Agent]
SW -->|default| FA[Fallback Agent] Combining with conversation memory¶
Enable Conversation Memory on each specialized agent so they maintain context within their domain. A user who starts with a billing question and follows up with more details will get a continuous conversation thread with the Billing Agent.
Next steps¶
- Scheduled Workflows -- automate recurring tasks
- Multi-Agent Delegation -- coordinate agents across workflows
- Categorizer reference -- full configuration details
- Expressions -- use upstream outputs in system prompts