Slots in Rasa Open Source 2.x
Note: This is material for Rasa 2.x. The syntax has updated slightly in Rasa 3.0 so we recommend new users to check the new course on Custom Actions found here.
Video
In Rasa, slots are your long term memory in a conversation. If there's any information you'd like to store for later use, you'd typically want to store it in a slot. It's important to understand that a slot is not the same thing as an entity. You could store any information in a slot, even if no entity has been detected. That said, it is very common to fill a slot value with an entity value.
If you want to define a slot, you'll need to define it in your domain.yml
file.
slots: destination: type: text influence_conversation: false
You'll notice that in this configuration we've added a influence_conversation
tag.
The reason is that slots can influence a story. You might have something like this
in your stories.yml
file.
stories:- story: booking a flight ticket steps: - intent: book_a_ticket - slot_was_set: - destination: Toronto
If your slots are configured to influence the flow of the conversation, you have to include them in your training stories.
Setting Slots
Typically, your slot values will be set by detected entities. In these situations your
domain.yml
file should also include entities.
entities: - destination
slots: destination: type: text influence_conversation: false
This way, when an entity is detected it can fill in the slot value. You can also set slot values with custom actions, but we'll discuss how to do that in a later video.
Auto Fill
By default, slots that have matching entity names will automatically be filled with
the values of those entities. You can disable this behaviour by changing the configuration
of the auto_fill
parameter to false.
entities:- destination
slots: destination type: text auto_fill: false
Types
In Rasa, slots have types. This is useful, because certain types of information are better served as a number than a string of text.
Text Slots
Slot type text can be used to store any text information. It can influence the conversation based on whether or not the slot has been set.
slots: destination: type: text influence_conversation: true
Boolean Slots
Slot type boolean can be used to store information that can get the values True
or False
.
slots: authenticated: type: boolean influence_conversation: true
Categorical Slots
Slot type categorical can be used to store values that can get one of a predefined set of possible values.
slots: price_range: type: categorical values: - low - medium - high
Float Slots
Slot type float can be used to store numerical values.
slots: radius: type: float min_value: 0 max_value: 100
List Slots
List slots can be used to store a list of values. When configured, only the presence of the slot can have influence on the flow of the conversation. The values themselves won't be taken into account.
slots: items: type: list
'Any' Slots
The "any" slot type can be used to store any arbitrary values. Slots of this type don’t have any influence on the conversation flow which means that the value and the presence of the slot doesn’t have any influence on how the conversation goes.
slots: shopping_items: type: any
Initial Values
Finally, it's good to know that you can also set a default value on a slot
by configuring the initial_value
parameter. The value will be assigned
to the slot from the beginning of the conversation and can be reset later
on by NLU or custom actions.
slots: current_account: type: float initial_value: 100
Links
Exercises
Try to answer the following questions to test your knowledge.
- When does a slot influence a conversation? When does it not?
- What's the difference between a slot and an entity?