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.

Hey @Polaris000 - did you discover an answer to your question?

Coming from a classical CS/programming background (object-oriented programming, state machines, etc) I find myself struggling to get Rasa to do what I want, and your question in this thread really resonated for me.

i.e. Can I use slot_was_set with specific values at the beginning of each story, to achieve which story gets ā€˜activatedā€™ based on current state? This would enable - for my use-case - an easy way to modularize stories into smaller sub-stories (similar to Dialogflow CXā€™s workflow, which works like a state machine).

If anyone can direct me to other questions which may target an audience like me (someone who is trying to break down a bot in a manner similar to state machine), and why that is a good or bad idea, Iā€™d very much appreciate it.

Many thanks!

2 Likes

Hi @invalid-access . What worked for me was starting and ending modularized stories with the same action and setting a slot again at key points where I want it to have a stronger impact on the conversation.

eg:

story:
- intent
- action1
- intent
- action2

You could break this into something like:

story:
- intent
- action1

story:
- action1
- intent
- action2

Not sure if this is the right way to do it, but definitely works for me

yea. Something that would explain the nitty-gritty would be a time saver for sure.

there have been talk that using a null can be weird or unpredictable, but

14:54 there is explicit talk of using slot with a data or with no data, how I can implement this if not when using a ā€œnullā€? Is it not a regular thing to do if it is in tutorial vide of Rasa? In the video there is no talk about using custom actions as was mentioned above, there is talk only about slots and influecnce_conversation: true