Tutorial: Building Assistants
These docs are for version 1.x of Rasa Open Source.
Tutorial: Building Assistants
After following the basics of setting up an assistant in the Rasa Tutorial, we’ll now walk through building a basic FAQ chatbot and then build a bot that can handle contextual conversations.
Building a simple FAQ assistant
FAQ assistants are the simplest assistants to build and a good place to get started. These assistants allow the user to ask a simple question and get a response. We’re going to build a basic FAQ assistant using features of Rasa designed specifically for this type of assistant.
In this section we’re going to cover the following topics:
Responding to simple intents with the MemoizationPolicy
Handling FAQs using the ResponseSelector
...
Memoization Policy
The MemoizationPolicy remembers examples from training stories for up to a max_history of turns. The number of “turns” includes messages the user sent, and actions the assistant performed. For the purpose of a simple, context-less FAQ bot, we only need to pay attention to the last message the user sent, and therefore we’ll set that to 1.
policies:
- name: MemoizationPolicy
max_history: 1
- name: MappingPolicy
Now that we’ve defined our policies, we can add some stories for the goodbye, thank and greet intents to the stories.md file:
## greet
* greet
- utter_greet
## thank
* thank
- utter_noworries
## goodbye
* bye
- utter_bye
...
Building a contextual assistant
Whether you’ve just created an FAQ bot or are starting from scratch, the next step is to expand your bot to handle contextual conversations.
In this tutorial we’re going to cover a variety of topics:
Please make sure you’ve got all the data from the Building a simple FAQ assistant section before starting this part. You will need to make some adjustments to your configuration file, since we now need to pay attention to context:
policies:
- name: MemoizationPolicy
- name: MappingPolicy
...
Handling unexpected user input
All expected user inputs should be handled by the form we defined above, i.e. if the user provides the information the bot asks for. However, in real situations, the user will often behave differently. In this section we’ll go through various forms of “interjections” and how to handle them within Rasa.
Generic interjections
If you have generic interjections that should always have the same single response no matter the context, you can use the Mapping Policy to handle these. It will always predict the same action for an intent.
...
Failing gracefully
Even if you design your bot perfectly, users will inevitably say things to your assistant that you did not anticipate. In these cases, your assistant will fail, and it’s important you ensure it does so gracefully.
Fallback policy
One of the most common failures is low NLU confidence, which is handled very nicely with the TwoStageFallbackPolicy. You can enable it by adding the following to your configuration file,
policies:
- name: TwoStageFallbackPolicy
nlu_threshold: 0.8
...
More complex contextual conversations
Not every user goal you define will fall under the category of business logic. For the other cases, you will need to use stories and context to help the user achieve their goal.
If we take the example of the “getting started” skill from Sara, we want to give them different information based on whether they’ve built an AI assistant before and are migrating from a different tool etc. This can be done quite simply with stories and the concept of max history.
## new to rasa + built a bot before
* how_to_get_started
- utter_getstarted
- utter_first_bot_with_rasa
* affirm
- action_set_onboarding
- slot{"onboarding": true}
- utter_built_bot_before
By utilizing the features we described in this tutorial, you can easily build a context-less assistant. When you’re ready to enhance your assistant with context, check out Building a contextual assistant.