Switch Node
Overview
The Switch Node Service is a flow control node that implements conditional branching logic in workflows. It evaluates expressions against defined cases to determine the next step in the workflow execution, similar to switch-case statements in programming languages. This enables sophisticated branching logic within a flow, allowing the xbot product to handle multiple scenarios or outcomes depending on evaluated criteria.
Configuration Details
name
The unique name of the switch node within the workflow
String
Yes
-
start
Indicates if this is the starting node of the workflow
Boolean
No
false
transition
Default transition used when none of the switch cases match. See TransitionDef
Object
No
-
cases
List of switch cases that define conditions and corresponding transitions. Cases are evaluated in order. See SwitchCaseDef
List
Yes
[]
loginRequired
Whether user authentication is required to evaluate this switch node
Boolean
No
-
Common Configuration Objects
SwitchCaseDef
Switch Case Definition. Represents a single case within a switch node that defines a condition and the corresponding transition to execute when that condition evaluates to true. Cases are evaluated in order within a switch node until a matching condition is found.
condition
Boolean expression that determines if this case should be executed. Uses workflow expression language to evaluate context variables, agent results, or other data. When this condition evaluates to true, the associated transition is executed
String
Yes
transition
The transition definition specifying the next step in the workflow when this case condition is matched. Defines the target node and any additional transition parameters. See TransitionDef
Object
No
TransitionDef
Transition Definition. Defines the flow control mechanism for moving between different states or agents in a workflow. Specifies either a target destination or workflow termination, enabling complex branching and routing logic in AI agent conversations.
end
Whether this transition marks the end of the workflow execution. When true, the workflow terminates. When false, execution continues to the target agent
Boolean
No
false
targetId
The unique identifier of the target agent or node to transition to. Must correspond to a valid agent name defined in the workflow. Ignored if 'end' is true
String
No
-
Example Configuration
Here's a comprehensive example showing how to configure a Switch Node for user type-based routing:
{
"type": "switch",
"name": "userTypeSwitch",
"description": "Route users to appropriate agents based on their subscription type and status",
"start": false,
"cases": [
{
"condition": "{{user.type}} == 'premium' && {{user.status}} == 'active'",
"transition": {
"targetId": "premiumSupportAgent"
}
},
{
"condition": "{{user.type}} == 'basic' && {{user.status}} == 'active'",
"transition": {
"targetId": "basicSupportAgent"
}
},
{
"condition": "{{user.status}} == 'suspended'",
"transition": {
"targetId": "accountRecoveryAgent"
}
},
{
"condition": "{{user.type}} == 'trial'",
"transition": {
"targetId": "trialSupportAgent"
}
}
],
"transition": {
"targetId": "defaultAgent"
},
"loginRequired": true
}
Simple Conditional Routing
A simpler example for basic conditional logic:
{
"type": "switch",
"name": "timeBasedSwitch",
"description": "Route based on time of day",
"cases": [
{
"condition": "{{context.hour}} >= 9 && {{context.hour}} < 17",
"transition": {
"targetId": "businessHoursAgent"
}
},
{
"condition": "{{context.hour}} >= 17 || {{context.hour}} < 9",
"transition": {
"targetId": "afterHoursAgent"
}
}
],
"transition": {
"end": true
}
}
Priority-based Routing
Example showing priority-based case evaluation:
{
"type": "switch",
"name": "prioritySwitch",
"description": "Route based on issue priority and customer tier",
"cases": [
{
"condition": "{{ticket.priority}} == 'critical'",
"transition": {
"targetId": "urgentSupportAgent"
}
},
{
"condition": "{{customer.tier}} == 'enterprise'",
"transition": {
"targetId": "enterpriseAgent"
}
},
{
"condition": "{{ticket.category}} == 'billing'",
"transition": {
"targetId": "billingAgent"
}
}
],
"transition": {
"targetId": "generalSupportAgent"
}
}
Complex Expression Evaluation
Example demonstrating complex condition expressions:
{
"type": "switch",
"name": "complexSwitch",
"description": "Advanced routing with complex conditions",
"cases": [
{
"condition": "{{user.country}} == 'US' && {{user.language}} == 'en' && {{user.subscription.plan}} in ['pro', 'enterprise']",
"transition": {
"targetId": "usEnglishPremiumAgent"
}
},
{
"condition": "({{user.country}} == 'FR' || {{user.country}} == 'CA') && {{user.language}} == 'fr'",
"transition": {
"targetId": "frenchSupportAgent"
}
},
{
"condition": "{{user.createdDate}} > '2024-01-01' && {{user.onboarding.completed}} == false",
"transition": {
"targetId": "newUserOnboardingAgent"
}
}
],
"transition": {
"targetId": "internationalAgent"
},
"loginRequired": true
}
Last updated