Conditions
How do I create conditional paths? How do I create conditions?
As conversation designers, we are in control of every action, intent and function our conversation carries out.
We can add another element to our conversations/assistants that will alter the conversation's path: Conditions.
Similar to programming, conditions are basic “if, then” logic functions/paths that modify how our conversations are executed. Conditions are a key part of the flow/path-selection or following process for your conversations.
Ex. Conditions are part of our everyday lives. As people, we can think about situations and make decisions based on what we observe or know to be true. For example, “If it is raining out, then we will have recess inside.” Or “If it is my birthday, then I can have a birthday cake.” Conditions are cause and effect: “If this, then that.”
Conditions allow us to control what the conversation does and perform different actions based on these “if, then” logic statements.
Since conversations are interfaces that can’t do anything without the designer and/or user directing them, we direct the conversation using the Condition Step. This tells the conversation what to do and the flow/path to do it.
The Condition Step allows you to send the user down different conversation paths depending on the value of the variable and associated conditions.
By default, your first condition step will have one condition field ready to be configured. Conditions are checked from top-to-bottom.
Adding Conditional Paths
The Condition Step can have multiple condition paths. To create a path, click on Add Condition. You can choose to assign a label to your Condition(s) so it's easier to read on the canvas.
Note: Similar to the Set Step, each condition has a label that you can use to provide a plain-language description of the condition that will be displayed on the assistant canvas.
Remember that if you do not provide a label, the actual condition statement (code-friendly view of the logic expression) will appear on the canvas instead.
Building a Condition
The Condition Step provides you the flexibility to check/evaluate multiple pieces of logic or functions. Your condition can be an evaluation of four items:
- Variable — you will define a variable from your assistant (i.e., Set or Input), and the set value will be evaluated
- Value — this is a static, plain text value you can define
- Logic Group — this is a collection of conditions using and/or statements
- Expression — this is a JavaScript expression. For the condition to work, it must be a valid JavaScript statement that evaluates to “True”
Using AI for conditional logic steps
If the logic you want to parse is less clear-cut than checking if a value is empty or not, you might want to use an LLM to branch paths. This can be done by using a Set AI step and a prompt clearly giving instructions on what to output in which condition. This strategy was used for example in this video to ask an LLM if there were hallucinations or inconsistency that needed to be re-written, and if so to branch to a re-write step.
Nesting Multiple Conditions/Logic Groups
You can get pretty sophisticated with your logic in your conversations with the Condition step. You can add multiple sub-conditions to get specific with your desired condition.
Under your main desired condition, you can hit 'Add a Condition' to add another Variable, Value, or Logic Group to your sub-condition.
These sub-conditions can be nested under your main condition as an 'AND' or 'OR'. Under traditional programming logic, these conditions can either be conditional of being both conditions required to be fulfilled (AND) or one condition or the either (OR).
Evaluating Conditions
Every condition evaluates the value of a variable you select against another value you define. If the variable is equal to the value you defined, the path will activate.
Ex.You can select and compare a variable such as {score} to the value of '5' ; meaning if the {score} variable has been filled and is equal to '5' , the conversation will follow that condition statement's path.
Note: Conditions require exact matches. Condition statements require exact matches when comparing the selected variable and value. This means if you are comparing an {animal} variable and value of "dog", and the user says "Dog" with a capital D and ends up being stored in the {animal} variable, then the condition will not be met as it is not an exact match.
Adding Actions to Conditions
In addition to porting a connection in your Condition step, you can use Actions to nest navigation and backend logic in a single Condition within the step. This can be configured under the Actions menu, following each respective Condition configuration & selection.
Under the Condition step, you can perform these nested actions per Choice:
- Go to Block — Goes to a specific block referenced within the assistant
- Go to Intent — Goes to an existing intent contained in the assistant
- End — Ends the conversation at its current state
- Set variable — Allows you to set and change the value of variables
- API — Allows you to set up, configure and execute API calls & functions
- Code — Allows you to set up and code custom JavaScript functions & commands
The Else Path
The Else condition path within the Condition Step is similar to that of the Choice Step as it is activated when none of the other paths can be activated. You can select what you want to happen when none of the conditions are fulfilled. Either you can have the assistant end the conversation, or it can follow a path.
You can configure this by navigating into No Match inside the Condition step.
Updated 3 days ago