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 domain.yml file.

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.

- story: booking a flight ticket

- intent: book_a_ticket

- 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.

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.

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.

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.

influence_conversation: true

Slot type boolean can be used to store information that can get the values True or False.

influence_conversation: true

Slot type categorical can be used to store values that can get one of a predefined set of possible values.

Slot type float can be used to store numerical values.

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.

Try to answer the following questions to test your knowledge.

Apa Itu SL dalam Trading?

You can’t perform that action at this time.

I wonder what’s the best way of creating slots, that are not obligatory.

What I mean by that? Let me define a form as presented below:

Now, in order to perform an actual search in my database I need either ‘5_service’ or ‘6_specialist_name’ or ‘7_specialization’. I don’t need all 3, although if user provides them in one sentence, then that’s not a problem. I will run a DB search with 3 parameters, not 1 or 2. So how to make form take this into account? It should accept just one response with either 1,2 or 3 parameters (slots). If just one is provided, then it shouldn’t investigate other two? And if two or three are given (in one response), then that’s okey as well.

I saw this issue add possibility to define optional slots for forms · Issue #6939 · RasaHQ/rasa · GitHub, but as I understand - it’s currently on hold, so… What’s the best alternative?

There are two solutions, that I’ve thought of:

What I don’t like about these solutions is neither of them seems to be an elegant one.

You could write validation methods for each of the three slots which fill the other two slots if there’s enough information already. That way it will consider them all filled; they won’t be “optional”, but the user won’t be prompted for them.

Yes. This solution works pretty well Thanks!

The default implementation of the Form Action mandates that all the fields listed in required_fields have to be filled before the submit method is triggered. But I have a slightly different scenario where submit can be triggered as long as some of the slots are filled. For ex: I have the following slots - city, state, country, category, product type. I just need one of city / state / country and one of category / product type to be filled before calling the submit method. I implemented a complicated way of doing it by making required_fields a list of lists as follows: [[city, state, category], [category, skills]] & checking if one slot in each of the list is filled. But is there a better way of implementing this? Any help would be appreciated

Basically I would make an option slot by doing this:

NOT adding it to required_slots

Adding it to slot_mappings

So if the slot is found on the text it would map anyway even when not required. But this would mean it would not ask for the slot. That means if you want to actively ask for it. The best way would be to put it on required_slots and give an “skip” option. It could be a quick-reply for example.

In your case specific case I would do one of the following:

Put everything on required and slotmapping. Add “request_next_slot” and “validate” to the method. On request_next_slot, I would check if at least one of the city/state/country was mapped if yes I would pass in the return: return [SlotSet(REQUESTED_SLOT, slot)] where “slot” would be equal to category or product. Otherwise if category or product was also filled you would return None

Hi @Sekhar-jami can u explain more on how to implement optional slots using your approach list of lists…In my case i just want to check for 2 slots (account number/trans ID)…so i feel your approach will do the job for me.

there are several ways to achieve this @custodio suggests a working example. For the sake of simplicity and if there is no need to validate the slots through the FormAction validators, you could also use a CustomAction instead of a FormAction by using:

So you just would have to decide when to trigger whatever is triggered in your previous submit method.

Rekening BCA menjadi salah satu pilihan favorit masyarakat Indonesia karena keamanannya, jaringan luas, serta kemudahan akses. Namun, memiliki rekening BCA…