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.
Topics Covered
- Responding to simple intents with the MemoizationPolicy
- Handling FAQs using the ResponseSelector
Code Blocks
To prepare for this tutorial, we’re going to create a new directory and start a new Rasa project.
mkdir rasa-assistant
rasa init
Let’s remove the default content from this bot, so that the nlu.md, stories.md, and domain.yml files are empty.
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
Adding Selections to NLU Data
You should first install Rasa using the Step-by-step Installation Guide and then follow the Rasa Tutorial to make sure you know the basics.
To train a first model and test the bot, run the following commands:
rasa train
rasa shell
This bot should now be able to reply to the intents we defined consistently, and in any order.
While it’s good to test the bot interactively, we should also add end to end test cases that can later be included as part of our CI/CD system. Create a file called test_stories.md in the root directory with some test cases:
## greet + goodbye
* greet: Hi!
- utter_greet
* bye: Bye
- utter_bye
## greet + thanks
* greet: Hello there
- utter_greet
* thank: thanks a bunch
- utter_noworries
## greet + thanks + goodbye
* greet: Hey
- utter_greet
* thank: thank you
- utter_noworries
* bye: bye bye
- utter_bye
To test our model against the test file, run the command:
rasa test --e2e --stories test_stories.md
Response Selectors
The ResponseSelector NLU component is designed to make it easier to handle dialogue elements and FAQ messages in a simple manner. By using the ResponseSelector, you only need one story to handle all FAQs, instead of adding new stories every time you want to increase your bot’s scope.
Defining Responses
To define the responses associated with these FAQs in a new file called responses.md:
## ask channels
* faq/ask_channels
- We have a comprehensive list of [supported connectors](/content/docs/core/connectors/index.html).
## ask languages
* faq/ask_languages
- You can use Rasa to build assistants in any language you want!
## ask rasa x
* faq/ask_rasax
- Rasa X is a tool to learn from real conversations and improve your assistant.
Training the Rasa Assistant allows us to build more sophisticated bot that can handle various queries and intents gracefully.