Tutorial: Building Assistants

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:

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.

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.

You can do this by editing your config.yml file as follows:

policies:
- name: MemoizationPolicy
  max_history: 1
- name: MappingPolicy

Adding Stories

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

We’ll also need to add the intents, actions and templates to our domain.yml file in the following sections:

intents:
  - greet
  - bye
  - thank

templates:
  utter_noworries:
    - text: No worries!
  utter_greet:
    - text: Hi
  utter_bye:
    - text: Bye!

You can now train a first model and test the bot, by running the following commands:

rasa train
rasa shell

Response Selectors

The ResponseSelector NLU component is designed to make it easier to handle dialogue elements like Small Talk and FAQ messages in a simple manner. To use the Response Selector we need to add it to the end of the expanded supervised_embeddings NLU pipeline in our config.yml:

pipeline:
- name: "WhitespaceTokenizer"
- name: "ResponseSelector"

Next Steps

Using 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 contextual assistants.

Building contextual assistants

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:

Business logic

A lot of conversational assistants have user goals that involve collecting a bunch of information from the user before being able to do something for them. This is called slot filling. For this type of use case, we can use Forms and our FormPolicy.

As an example, we will build out the SalesForm from Sara. The user wants to contact our sales team and for this we need to gather the following pieces of information:

from rasa_sdk.forms import FormAction

class SalesForm(FormAction):
    def name(self):
        return "sales_form"
slots:
  company:
    type: unfeaturized
  job_function:
    type: unfeaturized
  person_name:
    type: unfeaturized
  budget:
    type: unfeaturized
  business_email:
    type: unfeaturized
  use_case:
    type: unfeaturized

Handling unexpected user input

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. The decision to handle these types of user input should come from reviewing real conversations.

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.

Failing gracefully

It's important to ensure your assistant fails gracefully. One common failure is low NLU confidence, which can be handled with the TwoStageFallbackPolicy.

policies:
  - name: TwoStageFallbackPolicy
    nlu_threshold: 0.8

More complex contextual conversations

For user goals that don't fall under the category of simple business logic, you will need to use stories and context to help the user achieve their goals. The AugmentedMemoizationPolicy can provide more robust handling for conversational flows.

In summary, using Rasa you can create a powerful contextual assistant by taking advantage of its features to manage both simple FAQ tasks and more complex interactions.