Conditional Nodes and Multiple Outputs
Last updated
Last updated
Within the workflow, there is often a need to make decisions about whether to proceed with one branch or another. These decisions can be made dynamically during the pipeline's execution. To support this, a specialized Choice
Node is used. This node allows us to set conditions based on the parameters of previous nodes, helping to determine the next step in the sequence.
In this case, the Choice
Node determines which Agent will be executed next. simple-agent
will be executed if the choice_is_correct_date condition is met, while simple-agent-2
will be executed if the choice_is_correct_next_date condition is met.
To ensure that nodes execute when a condition is met, they must be connected using the appropriate condition parameters. Note the difference between connecting the nodes themselves and connecting their parameters.
In this example, we have three conditions:
choice_is_correct_date
choice_is_correct_next_date
default
The first two conditions are manually created (see below), while the default condition is pre-defined and is met in all cases. The default condition serves as a valuable fallback mechanism when none of the custom conditions are met.
To create new condition, click on the Choice node to access its configuration. Here we can see all previously created conditions. We can either edit existing conditions or create new a branch by clicking Add branch.
To configure a branch/condition we have to specify:
Variable
- The variable we will use for the condition. The syntax follows the same format as the InputTransformers and OutputTransformers.
Operator
- Defines the operation we will use for the condition.
Value Type
- Defines the type of value. This can be a string, integer, or boolean, and either a constant or another variable.
Value
- If the Value Type
is a constant, we provide the specific value. If it is a variable, we must define the method for accessing it.
We can also configure more complex conditions using the AND and OR operators.
By clicking the Add dropdown, we can continue adding additional AND or OR statements, allowing us to create conditions of any complexity.
Workflow execution in different scenarios:
Scenarios | Actions |
---|---|
Multiple conditions (one or more) | If multiple conditions are met, only the first one will proceed, functioning like an if-elif-else structure. |
Neither condition | If no conditions are met after the Choice Node and the default condition is not connected, the workflow will exit. |