switch.mdx
Overview
The Switch component is a critical control element designed to evaluate specified conditions based on outputs from other components and direct the flow of execution accordingly. It enables complex branching logic within workflows or automation pipelines, allowing different paths of execution depending on rule-based evaluations.
Unlike decision-making components that rely on AI (e.g., the Categorize component which uses large language models for classification), the Switch component strictly uses deterministic, rule-based logic to evaluate conditions and determine the next steps in a process.
Detailed Description
Purpose
To facilitate conditional branching in workflows.
To evaluate multiple conditions grouped into "cases".
To support logical operations (AND / OR) between multiple conditions within each case.
To specify downstream components that should be executed when a case evaluates to true.
Key Concepts
Case: A grouping of one or more conditions that collectively define a rule for branching.
Condition: An atomic expression that compares the output of a component against a value using an operator.
Logical Operator: Defines how multiple conditions within a case are combined (AND or OR).
Downstream Component: The next component(s) to execute if the case matches.
Configurations and Usage
1. Cases
You must configure at least one case in a Switch component.
Each case contains one or more conditions.
When multiple conditions exist in a case, you must explicitly set the logical operator (AND/OR).
2. Conditions
Each condition includes:
Operator: Defines the comparison type between the component output and the specified value.
Supported operators:
Operator
Description
Equals
Checks equality (default)
Not equal
Checks inequality
Greater than
Numeric comparison
Greater equal
Numeric comparison
Less than
Numeric comparison
Less equal
Numeric comparison
Contains
Checks if value is substring
Not contains
Checks if value is not substring
Starts with
Checks prefix in string
Ends with
Checks suffix in string
Is empty
Checks if output is empty
Not empty
Checks if output is not empty
Value: The literal value to compare against. Must be a single value (integer, float, or string). Expressions or multiple values with delimiters are not supported.
3. Specifying Downstream Components
After configuring each case, you can specify downstream components by clicking the + button next to the case on the canvas.
This links the case to next steps in the workflow.
Important Notes
When multiple conditions exist in a single case, the logical operator (AND/OR) is mandatory.
The component strictly supports rule-based logic and does not interpret or evaluate expressions or multiple values.
The Switch component is typically part of a larger system of components, where it receives outputs from upstream components and directs execution flow to downstream components.
Example Usage
Suppose you have a workflow where you want to branch based on the result of a previous component called GetUserAge.
Case 1: If GetUserAge output is greater than 18 AND less than 65, proceed to "AdultWorkflow".
Case 2: If GetUserAge output is less or equal to 18, proceed to "MinorWorkflow".
Case 3: If GetUserAge output is greater or equal to 65, proceed to "SeniorWorkflow".
This setup uses multiple conditions combined with logical operators to route execution according to age brackets.
Interaction with Other System Components
Upstream Components: The Switch component depends on outputs from other components in the workflow. These outputs are used as the input for condition evaluation.
Downstream Components: Based on the evaluation of cases, the Switch routes execution to one or multiple downstream components to continue the workflow.
Canvas/UI: The component is configured and visualized on a canvas interface where users define cases, conditions, and connect downstream components.
Other Control Components: It complements other branching components like Categorize, which uses AI-based decision logic, whereas Switch is rule-based.
Implementation Details
The component evaluates each case sequentially or based on priority.
For each case, it applies the logical operator to the results of each condition.
If a case evaluates to true, the flow is directed to the associated downstream components.
If no cases match, the behavior depends on system defaults (e.g., stop execution or proceed to a default path).
Mermaid Diagram: Class Structure of Switch Component
classDiagram
class Switch {
+cases: List~Case~
+evaluate(): String
+addCase(case: Case)
+removeCase(caseId: String)
}
class Case {
+id: String
+conditions: List~Condition~
+logicalOperator: String "AND" or "OR"
+evaluate(): Boolean
+addCondition(condition: Condition)
+removeCondition(conditionId: String)
}
class Condition {
+componentOutput: String
+operator: String
+value: String | Number
+evaluate(): Boolean
}
Switch "1" o-- "*" Case : contains
Case "1" o-- "*" Condition : contains
Summary
The Switch component is a fundamental building block for rule-based branching in workflows. By defining multiple cases with one or more conditions connected via logical operators, it evaluates component outputs and directs execution flow accordingly. It is designed for deterministic, non-AI based decision-making, complementing other components that may use machine learning or AI. Its configuration and integration into the system enable complex, multi-path workflows with clear, maintainable logic rules.
End of Documentation for switch.mdx