Skip to content

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

Conditional FlowTBD: Replace with screenshot of conditional flow

Prerequisites ​

Understanding Conditions ​

Condition nodes evaluate structured FlowCondition rules and route execution:

           ┌──── [match] ──── Target Node
Condition ─┤
           └──── [default] ── Default Node

Each condition checks a path in the flow context against a value using an operator.

How Conditions Work ​

A ConditionNode has:

  • conditions — Array of FlowCondition rules to evaluate
  • logicOperator — How to combine multiple conditions: and, or, or xor (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 ​

  1. Go to Flows → + New Flow
  2. Name it "Support Ticket Router"

Step 2: Add Initial Nodes ​

┌──────────┐    ┌───────────┐    ┌───────────┐
│  Trigger  │───>│  Analyze  │───>│ Condition │
│           │    │   Agent   │    │           │
└──────────┘    └───────────┘    └───────────┘

Trigger:

yaml
triggerType: manual
triggerConfig:
  inputSchema:
    type: object
    properties:
      message:
        type: string
      priority:
        type: string
        enum: [low, medium, high, critical]

Analyzer Agent:

yaml
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: string

Agent node config:

yaml
agentId: ticket-analyzer
inputMapping:
  message: "trigger.input.message"
  priority: "trigger.input.priority"
outputMapping: {}

Step 3: Add the Condition ​

  1. Drag a Condition node after the Analyzer
  2. Configure with structured conditions:
yaml
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 ​

yaml
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: think

Standard Path ​

yaml
name: Standard Responder
systemPrompt: |
  Respond to routine tickets:
  - Answer questions clearly
  - Provide helpful resources
  - Offer next steps

model: claude-sonnet-5-0

Step 5: Complete Flow Diagram ​

                              ┌── Escalation ── End ──┐
Trigger → Analyze → Condition ─┤                       │
                              └── Standard ── End ─────┘

FlowCondition Reference ​

Each condition is a structured rule:

yaml
path: "nodes.analyzer.output.type"  # JSONPath in context
operator: "eq"                       # Comparison operator
value: "bug"                         # Value to compare against

Operators ​

OperatorMeaning
eqEquals
neNot equals
gtGreater than
ltLess than
gteGreater or equal
lteLess or equal
containsString/array contains
matchesRegex pattern match

Logic Operators ​

OperatorMeaning
andAll conditions must be true (default)
orAt least one condition must be true
xorExactly one condition must be true

Negate Flag ​

Setting negate: true inverts the combined result:

LogicNegateBehavior
andfalseAll must match
andtrueNOT all match (NAND)
orfalseAt least one matches
ortrueNone match (NOR)

Multiple Conditions ​

AND — All Must Match ​

yaml
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 ​

yaml
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 Queue

Condition 1:

yaml
conditions:
  - path: "trigger.input.priority"
    operator: "eq"
    value: "critical"
targetNodeId: "immediate"
defaultTargetNodeId: "condition2"

Condition 2:

yaml
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:

yaml
# Transform node (type: script)
transformType: script
expression: |
  const type = context.nodes.analyzer.output.type;
  return { route: type };

Then use conditions on the route:

yaml
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) ── End

Moderation condition:

yaml
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

Sciorex is proprietary software.