Version: Latest

Restarting an Active Flow

A looping flow in Rasa lets users repeat actions in a conversation. You can use this for things like adding items to a list, making repeated requests, or providing iterative input.

To restart an active flow, add a unique identifier to the top of your flow. This id step is used as a reference point to loop back to the beginning of the flow when you want to restart it. It is important to note that you cannot use a link to restart the flow. This is because links are reserved for connecting an active flow to other flows. You cannot connect a flow to itself.

It's also important to clear any relevant slots before restarting the flow. This prevents Rasa from skipping required collect steps. You can do this by adding a set_slots step or by setting the ask_before_filling parameter to True in your collection steps.

Here's an example of a looping flow that lets users add multiple contacts:

  • Start the flow with id: "start".
  • Collect contact information.
  • Add the contact.
  • If successful, ask if the user wants to add another.
  • If yes, reset slots and restart the flow (using set_slots and jumping back to id: "start").
add_contact.yml
flows:
add_contact:
description: add a contact to your contact list
name: add a contact
steps:
- id: "start"
collect: "add_contact_handle"
description: "a user handle starting with @"
- collect: "add_contact_name"
description: "a name of a person"
- action: add_contact
next:
- if: "slots.return_value = 'success'"
then:
- action: utter_contact_added
next: "restart"
- if: "slots.return_value = 'already_exists'"
then:
- action: utter_contact_already_exists
next: "restart"
- else:
- action: utter_add_contact_error
next: END
- id: "restart"
collect: restart_add_contact
next:
- if: "slots.restart_add_contact is True"
then:
- set_slots:
- add_contact_handle: null
- add_contact_name: null
- restart_add_contact: null
next: "start"
- else: END

Another way to loop without resetting slots is to set ask_before_filling to True in all collect steps. This makes Rasa always ask for input, even if the slot was already filled.

add_contact.yml
# ...
- id: "start"
collect: "add_contact_handle"
description: "a user handle starting with @"
ask_before_filling: true
- collect: "add_contact_name"
description: "a name of a person"
ask_before_filling: true
# ...
- id: "restart"
collect: restart_add_contact
ask_before_filling: true
next:
- if: "slots.restart_add_contact is True"
then: "start"
- else: END