Confusion about SlotSet. Why does it not work in my case [Solved]

Probably a silly question. I have this code in my custom action:

# city slot equals "Berlin"
SlotSet("city", None)
print(tracker.slots["city"]) # outputs Berlin

I also tried:

tracker.slots["city"] = None
print(tracker.slots["city"]) # outputs none but it is actually not none in rasa

Finally, i tried AllSlotsReset() and this did also not work.

My expected behaviour is that the slot is resetted. This is not the case and my form just keeps remembering it. What am I doing wrong here? I want the slot to be resetted so that the form can start requesting all variables from the user.

Rasa version: Version: 2.2.5

Version

Hi @mauricetk, try the below, you can reset the slot value using the below custom action:
class ResetSlot(Action):

def name(self):
    return "action_reset_slot"

def run(self, dispatcher, tracker, domain):
    return [SlotSet("comments", None),
            SlotSet("day_from",None),
            SlotSet("day_to",None),

Add the action name in your domain file and your stories when u need to reset the value. You can also print slot value using the below command:
email=tracker.get_slot(“email”)
print(email).

I hope it can help you :slight_smile:

1 Like

This worked like a charm. In hindsight of course, the problem is obvious to me.

For future users running into this issue: you also need to follow this approach when resetting all form values. Example:

class ResetFormValues(Action):

    def name(self) -> Text:
        return "reset_form_values"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        
        dispatcher.utter_message(text="resetted values in custom action v2")

        return [AllSlotsReset()]
1 Like

Yup, key thing to understand here is that events are only applied when they are returned by the custom action, not if they are called elsewhere in the action code.