RASA - Slots in detail

petr7555

Petr Janik

Posted on June 3, 2021

RASA - Slots in detail

Entities are automatically saved to slots that have the same name.

Let's create a new age entity:



# domain.yml
# ... previous content ...
entities:
  # ... previous entities ...
  - age


Enter fullscreen mode Exit fullscreen mode

and a new age slot:



# domain.yml
# ... previous content ...
slots:
  # ... previous slots ...
  age:
    type: text
    influence_conversation: false


Enter fullscreen mode Exit fullscreen mode

Let's create a new intent as well:



# data/nlu.yml
# ... previous content ...
  - intent: inform_age
    examples: |
      - My age is [20 years](age)
      - I am [15](age)
      - I am [47 years](age)
      - I am [8 years](age) old


Enter fullscreen mode Exit fullscreen mode

and add it to domain.yml:



# domain.yml
# ... previous content ...
intents:
  # ... previous intents ...
  - inform_age


Enter fullscreen mode Exit fullscreen mode

We need the chatbot's response as well:



# domain.yml
# ... previous content ...
  utter_age_back:
    - text: Your age is {age}.


Enter fullscreen mode Exit fullscreen mode

The story now looks like this:



# stories.yml
# ... previous content ...
  - story: tell age
    steps:
      - intent: inform_age
      - action: utter_age_back


Enter fullscreen mode Exit fullscreen mode

Let's see this in action:

Utter back age slot

The age entity was automatically saved to the age slot, because the name is the same.
Also, you can see that slots can be overwritten. First, the value of the slot was 17 years and then 64.

If a form contains a slot that is filled before the form is activated, that slot is not asked anymore as part of the form loop.

To demonstrate this, let's create the following story:



# stories.yml
# ... previous content ...
  - story: tell email
    steps:
      - intent: inform_email
      - action: utter_email_back


Enter fullscreen mode Exit fullscreen mode

Normally, the chatbot would ask "What is your email address?" to fill the email slot. But since the slot is filled beforehand, it asks only frequency and notifications.

Email slot filled before form loop

You can learn more about slots in the documentation or in my previous article.

In the next chapter, we will look at rich responses, such as buttons and images.

Repository for this tutorial:

You can checkout the state of the repository at the end of this tutorial by running:



git clone --branch 15-slots-in-detail git@github.com:petr7555/rasa-dev-tutorial.git


Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
petr7555
Petr Janik

Posted on June 3, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

RASA - Session persistence
rasa RASA - Session persistence

July 28, 2022

RASA - Socket.IO integration
rasa RASA - Socket.IO integration

August 30, 2021

RASA - Google Chat integration
rasa RASA - Google Chat integration

August 9, 2021

RASA - Synonyms
rasa RASA - Synonyms

August 7, 2021