# Conversation flows

# Branching conversations

Conversations are often designed as tree-like flow charts. Stories are real conversation examples. Simply click on the Branch Story button on the story footer:

Several events can be at the beginning of branches:

  • user utterances (intents and entities)
  • slots (context)

# Branching with intents

The simplest way to branch a conversation is to use different intents at some point. Consider the following stories where two different paths (happy and sad) are implemented:

# Branching with entity values

Another way is to use entity values. You can check how you can annotate with entities in the conversation builder guide.

Here we want to implement the following use case: a user can ask to book in eco or business. The third path covers the case where no class is specified. This can be done as follows with branches:

But wait, that doesn't work!

If you train and try this story, you'll see that if you type /book the agent will utter utter_which_class as expected, but if you type /book{"class":"eco"} or /book{"class":"business"} the response will be random. The reason is that if the value of the entity is not stored somewhere, Rasa only differentiates the flow looking at if the entity class exists or not in the user utterance.

If you want the stories above to work, you need to create a slot. In this case we're going to create a categorical slot, and add the categories business and eco. Then retrain and it should work.

Categorical slot

# Branching with slots

Once you define a slot with the same name as an entity, any entity value extracted from a user message will be set as the slot value, and this value will persist accross the conversation until it is changed or reset. This means that if a user said one of the sentences above (I want to book in economy book{"class":"eco"} or I want to book in businessbook{"class":"business"}), you can still use that information to branch your conversation.

Use case: a user wants to cancel a booking, but only business bookings are cancellable. You can implement that as follows with branches:

As you can see, the - slot{"class":"..."} in the branches guides the conversation into different paths.

What if the class has not been set yet?

You can add a third category not_set to the class slot in a new branch, and set the initial value to not_set. Then you can gracefully handle the case where no class is set like this:

# How branches are handled

Under the hood, Botfront uses Rasa checkpoints. When you click branch story, the parent and child stories are linked seamlessly with checkpoints, without the need of additional handling on the front end.

# Other branching features

You can easily see which branch you're on by looking at the breadcrumbs on the story footer: