New in 3.7Flows are part of Rasa’s new Conversational AI with Language Models (CALM) approach
and available starting with version
3.7.0.Overview
In CALM, the business logic of your AI assistant is implemented as a set of flows. Each flow describes the logical steps your AI assistant uses to complete a task. It describes the information you need from the user, data you need to retrieve from an API or a database, and branching logic based on the information collected. A flow in Rasa only describes the logic your assistant follows, not all the potential paths conversations can take. If you’re used to designing AI assistants by creating flow charts of how conversations should go, you’ll see that flows in Rasa are much simpler. Check out Rasa Studio to build flows with a web interface. To get familiar with how flows work, follow the tutorial. This page provides a reference of the format and properties of flows.Hello World
A Flow is defined using YAML syntax. Here is an example of a simple flow:flows.yml
Flow Properties
A flow is defined using the following properties:flows.yml
Flow ID
The id is required and uniquely identifies the flow among all flows. It allows only alphanumeric characters, underscores, and hyphens, with the restriction that the first character cannot be a hyphen.Name
Thename field is an optional human readable name for the flow.
Description
Thedescription field is a summary of the flow. It is required, and should
describe what the flow does for the user.
Writing a clear description is important, because it is used by the
Dialogue Understanding component to decide when
to start this flow.
See Starting Flows for more details.
Additionally, for guidelines on how to write concise and clear descriptions
see the section provided here.
Always Include in Prompt
Ifalways_include_in_prompt field is set to true and the flow guard
defined in the if field evaluates to true, the flow will be
always be included in the prompt
NLU Trigger property
Thenlu_trigger field is used to add intents that can start the flow.
Run Pattern Completed
Therun_pattern_completed field is used to determine if the
pattern_completed flow
should be run when the conversation is finished.
This field is only applicable to the parent flows which are not called by other flows.
If property
Theif field is used to add flow guards.
Persisted Slots
By default, slots set in acollect and set_slot step are reset when the flow ends.
To change this behavior, you can add these slots to the persisted_slots field.
The persisted_slots field is used to specify a list of slots whose value should be persisted after the flow ends.
These slots have to be filled in either a collect or set_slots step in the flow.
flows.yml
Validation Rules for persisted_slots property
During training, Rasa implements the following strict validation checks for the persisted_slots property:
-
The
persisted_slotsproperty cannot be simultaneously used with thereset_after_flow_endsproperty of thecollectstep in a flow. A validation error will be thrown by Rasa during training if both properties are used in a flow. Only one of the two properties can be used in a flow, not both. -
The
persisted_slotsproperty should only contain slots that are filled in either acollectorset_slotsstep in the flow. A validation error will be thrown by Rasa during training if a slot that is not set in acollectorset_slotsstep is added to thepersisted_slotsproperty. Please note, slots set in custom actions are automatically persistent by default and should not be added to thepersisted_slotsproperty. Attempting to do so will also result in a validation error.
Steps
Thesteps field is required and lists the flow steps.
For details please refer to Flow Steps.
Examples
A basic flow with branching
age slot collected from a user message.
Linking multiple flows
link step in flows enables the start of
another flow as a follow-up flow. Specifically, the flow collect_feedback is
initiated as a follow up flow after transfer_money is terminated at the link step.
Embedding a flow inside another flow
Let’s assume a financial assistant needs to serve two use cases:- Transferring money to another individual
- Adding a new recipient for transferring money
call step lets you accomplish both the
possibilities without needing to create redundant flows. To accomplish the above use cases,
you can leverage the call step in your flows as shown below:
flows.yml
prompt.txt
Optionally ask for information
Imagine a dress shopping AI assistant created to help users find and purchase dresses. This AI assistant includes two types of features: primary features (i.e., dress type, size) and optional features (i.e., color, material, price range, etc.). The assistant should ask for the primary features and avoid asking for the optional features, unless the user specifically requests them. This approach is key to avoid asking too many questions and overwhelming the user. You can achieve this by setting theask_before_filling property to false on the collect step and setting an
initial_value for the slot in the domain file.
domain.yml
ask_before_filling set to false and given that the slots (dress_color and dress_material) already have initial values,
the corresponding collect steps will not be asked. Instead, the assistant will move to the next step.
If the user explicitly provides a value for a slot, this new value will overwrite the initial one.