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.
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
slots:destination:type: textinfluence_conversation: false
You'll notice that in this configuration we've added a
The reason is that slots can influence a story. You might have something like this
stories:- story: booking a flight ticketsteps:- 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.
Typically, your slot values will be set by detected entities. In these situations your
domain.yml file should also include entities.
entities:- destinationslots:destination:type: textinfluence_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.
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
auto_fill parameter to false.
entities:- destinationslots:destinationtype: textauto_fill: false
In Rasa, slots have types. This is useful, because certain types of information are better served as a number than a string of text.
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: textinfluence_conversation: true
Slot type boolean can be used to store information that can get the values
slots:authenticated:type: booleaninfluence_conversation: true
Slot type categorical can be used to store values that can get one of a predefined set of possible values.
slots:price_range:type: categoricalvalues:- low- medium- high
Slot type float can be used to store numerical values.
slots:radius:type: floatmin_value: 0max_value: 100
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.
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.
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: floatinitial_value: 100
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?