How does slot_was_set work?

I recently started working with rasa and am a little unsure of how slot_was_set works. Specifically,

  • does slot_was_set tell rasa about slots set in the immediately preceding intent or custom action or can it be used as a conditional check for slots populated much earlier in the conversation?

For example, if I wanted to greet a customer based on whether the slot customer_id is set or not, does it make sense to do this:

    story: greet new customer
    steps:
        - intent: greet
        - slot_was_set:
            - customer_id: null
        - action: utter_greet_new_customer

    story: greet existing customer
    steps:
        - intent: greet
        - slot_was_set:
            - customer_id: 123
        - action: utter_greet_existing_customer

I know I could just use a custom action which reads the slot customer_id and utter the correct response based on that, but I want to understand how slot_was_set works. Since customer_id isn’t exactly being set in this story, would slot_was_set actually work as expected? For me, this seems to work most of the time but since there’s a lot going on in the project, I’m not sure if there are some other factors affecting this.

One way to be sure would be to just use a “slot_setter” custom action that just reads all relevant slots and sets them to the same value again. The run method would look something like this:

class ActionSlotSetter(...)
    ..
    .. 
    def run(...):
        customer_id = tracker.get_slot('customer_id')
        return [SlotSet('customer_id', customer_id)]

And can be used like this:

    story: greet new customer
    steps:
        - intent: greet
        - action: action_slot_setter
        - slot_was_set:
            - customer_id: null
        - action: utter_greet_new_customer

    story: greet existing customer
    steps:
        - intent: greet
        - action: action_slot_setter
        - slot_was_set:
            - customer_id: 123
        - action: utter_greet_existing_customer

TLDR:
Does slot_was_set tell rasa about slots set in the immediately preceding intent or custom action or can it be used as a conditional check for slots populated much earlier in the conversation or slots yet to be populated (currently having their defaullt value)? How does slot_was_set exactly work?

Thanks in advance!

3 Likes

Just in case this post got buried under the newer ones…

Yes for both questions. It can be used for conditional stories by checking if the slot had a particular value.

To be honest I don’t know about a null value for slot_was_set, since, as you said later, "customer_id isn’t exactly being set in this story". I would usually use Custom Actions in that case.

Just try if it works like that and keep us updated!

Try to use a rule instead of a story for the null slot.

Yeah that’s a nice way to make sure the slot is set even if it is null. Again, just try out your multiple options and keep the best one!

I know I’m telling you to try a lot. I’ve seen your question since it was posted and hoped someone more knowledgeable than me would reply, but nobody did and you’re still waiting so I answered.

Thanks a lot for the reply @ChrisRahme ! You answered one of my main questions here:

  • Does slot_was_set work even for slots set much earlier in the conversation. Ans: Yes

My second query, which you said you weren’t sure about is:

  • Can it be used for checking if slots haven’t been modified yet (still with their default values) even if that default value is null?

Hopefully, someone will have an answer for that.

My biggest issue regarding this is that certain things work most of the time, most likely due to the model learning from the stories. So though I can try (and already have, in most cases) different implementations, I’m never really confident if something is working just because of the model as opposed to a correct implementation on my part.

So though using slot_was_set to check for a slot being in its default value (null in this case) works, I’m not certain if its a good practise to do it this way.

1 Like

Just in case this post got buried under the newer ones…

bump

bump

@Polaris000 If I can suggest to you, please try use rasa interactive and you will be able to see how slot and slot_was_set is working, as you input it will display all the values and for next requested slots etc. I hope you will try :slight_smile:

Thanks for the reply @nik202 . By rasa interactive, do you mean using the interactive command line mode by running rasa interactive? I’ve used that once before (prefer rasa x over that) but don’t remember anything that would suggest how slot_was_set works.

In any case, I’ll try that again and let you know if I find my answer. Thanks for pointing me in the right direction.