Conditional Branching
Add decision logic to your flows with conditions and branches.
Difficulty: Intermediate Time: 15 minutes
What You'll Build
A flow that:
- Evaluates structured conditions
- Routes to different paths based on context data
- Handles multiple outcomes
TBD: Replace with screenshot of conditional flow
Prerequisites
- Completed Simple Sequential Flow
- Understanding of flow basics
Understanding Conditions
Condition nodes evaluate structured FlowCondition rules and route execution:
┌──── [match] ──── Target Node
Condition ─┤
└──── [default] ── Default NodeEach condition checks a path in the flow context against a value using an operator.
How Conditions Work
A ConditionNode has:
- conditions — Array of
FlowConditionrules to evaluate - logicOperator — How to combine multiple conditions:
and,or, orxor(default:and) - negate — If
true, inverts the final result (AND+negate = NAND, OR+negate = NOR) - targetNodeId — Where to go when conditions match
- defaultTargetNodeId — Where to go when conditions don't match
Step 1: Create the Flow
- Go to Flows → + New Flow
- Name it "Support Ticket Router"
Step 2: Add Initial Nodes
┌──────────┐ ┌───────────┐ ┌───────────┐
│ Trigger │───>│ Analyze │───>│ Condition │
│ │ │ Agent │ │ │
└──────────┘ └───────────┘ └───────────┘Trigger:
triggerType: manual
triggerConfig:
inputSchema:
type: object
properties:
message:
type: string
priority:
type: string
enum: [low, medium, high, critical]Analyzer Agent:
name: Ticket Analyzer
systemPrompt: |
Analyze support tickets and categorize:
- type: bug, feature, question, billing
- sentiment: positive, neutral, negative, angry
- complexity: simple, moderate, complex
model: claude-haiku-4-5-20251001
outputSchema:
type: object
properties:
type:
type: string
sentiment:
type: string
complexity:
type: stringAgent node config:
agentId: ticket-analyzer
inputMapping:
message: "trigger.input.message"
priority: "trigger.input.priority"
outputMapping: {}Step 3: Add the Condition
- Drag a Condition node after the Analyzer
- Configure with structured conditions:
conditions:
- path: "nodes.analyzer.output.sentiment"
operator: "eq"
value: "angry"
- path: "trigger.input.priority"
operator: "eq"
value: "critical"
logicOperator: "or"
targetNodeId: "escalation"
defaultTargetNodeId: "standard"This routes to the escalation path if the sentiment is angry OR the priority is critical.
Step 4: Create Branch Paths
Match path (Urgent):
Condition ─── [match] ─── Escalation Agent ─── End (success)Default path (Normal):
Condition ─── [default] ─── Standard Response Agent ─── End (success)Escalation Path
name: Escalation Handler
systemPrompt: |
Handle urgent tickets with care:
- Acknowledge the urgency
- Provide immediate assistance
- Escalate to human if needed
model: claude-opus-4-6
thinkingLevel: thinkStandard Path
name: Standard Responder
systemPrompt: |
Respond to routine tickets:
- Answer questions clearly
- Provide helpful resources
- Offer next steps
model: claude-sonnet-5-0Step 5: Complete Flow Diagram
┌── Escalation ── End ──┐
Trigger → Analyze → Condition ─┤ │
└── Standard ── End ─────┘FlowCondition Reference
Each condition is a structured rule:
path: "nodes.analyzer.output.type" # JSONPath in context
operator: "eq" # Comparison operator
value: "bug" # Value to compare againstOperators
| Operator | Meaning |
|---|---|
eq | Equals |
ne | Not equals |
gt | Greater than |
lt | Less than |
gte | Greater or equal |
lte | Less or equal |
contains | String/array contains |
matches | Regex pattern match |
Logic Operators
| Operator | Meaning |
|---|---|
and | All conditions must be true (default) |
or | At least one condition must be true |
xor | Exactly one condition must be true |
Negate Flag
Setting negate: true inverts the combined result:
| Logic | Negate | Behavior |
|---|---|---|
and | false | All must match |
and | true | NOT all match (NAND) |
or | false | At least one matches |
or | true | None match (NOR) |
Multiple Conditions
AND — All Must Match
conditions:
- path: "nodes.analyzer.output.type"
operator: "eq"
value: "bug"
- path: "nodes.analyzer.output.complexity"
operator: "eq"
value: "complex"
logicOperator: "and"
targetNodeId: "senior-dev"
defaultTargetNodeId: "junior-dev"Routes to senior dev only for complex bugs.
OR — Any Must Match
conditions:
- path: "nodes.analyzer.output.sentiment"
operator: "eq"
value: "angry"
- path: "nodes.analyzer.output.type"
operator: "eq"
value: "security"
logicOperator: "or"
targetNodeId: "urgent-handler"
defaultTargetNodeId: "normal-handler"Routes to urgent handler if angry sentiment OR security issue.
Chained Conditions
For more than two outcomes, chain condition nodes:
┌── [critical] ── Immediate Response
Condition 1 ───┤
└── Condition 2 ─── [high] ── Priority Queue
└── [default] ── Standard QueueCondition 1:
conditions:
- path: "trigger.input.priority"
operator: "eq"
value: "critical"
targetNodeId: "immediate"
defaultTargetNodeId: "condition2"Condition 2:
conditions:
- path: "trigger.input.priority"
operator: "eq"
value: "high"
targetNodeId: "priority-queue"
defaultTargetNodeId: "standard-queue"Switch-Style Routing
For many branches, use a Transform node to compute a routing key, then chain conditions:
# Transform node (type: script)
transformType: script
expression: |
const type = context.nodes.analyzer.output.type;
return { route: type };Then use conditions on the route:
conditions:
- path: "nodes.router.output.route"
operator: "eq"
value: "bug"
targetNodeId: "bug-handler"
defaultTargetNodeId: "next-condition"Merge Branches
Rejoin branches with a Merge node:
Path A ──┐
├─── Merge ─── End
Path B ──┘The merge node waits for whichever path executed. See Parallel Execution for merge strategies.
Example: Content Moderation Flow
┌── [flagged] ── Human Review (Wait) ── End
Input → Moderation Agent → ──┤
└── [safe] ── Publish (TicketAction) ── EndModeration condition:
conditions:
- path: "nodes.moderator.output.flagged"
operator: "eq"
value: true
- path: "nodes.moderator.output.confidence"
operator: "lt"
value: 0.8
logicOperator: "or"
targetNodeId: "human-review"
defaultTargetNodeId: "publish"The Wait node (waitType: approval) pauses for human review before continuing.
Tips
- Keep conditions simple: One or two rules per condition node
- Test both paths: Verify all branches work
- Name meaningfully: "Is Urgent?" not "Condition 1"
- Use debug mode: Step through conditions to verify routing
- Chain for complexity: Multiple simple conditions beat one complex condition
