Restart bot anytime

Hi everyone. I have some issue with my bot. When user is in a formAction with some required slots. In there i cannot restart bot with '/restart '. How do i restart bot anytime if i want. Thank you so much

The way I did it was to create a custom action action_reset_full which resets all slots, restart the conversation and turns off any form.

from rasa_sdk import Action
from rasa_sdk.events import Form, AllSlotsReset, Restarted

class ActionResetFull(Action):
    def name(self):
        return "action_reset_full"

    def run(self, dispatcher, tracker, domain):
        dispatcher.utter_template("utter_reset_full", tracker)
        return [Form(None), AllSlotsReset(None), Restarted(None)]

I also have an intent reset that triggers this action so that you can just type “Reset” and the whole thing starts over. In our domain, it would look like (in the intents section of domain.yml):

- reset:
    name: reset
    triggers: action_reset_full

Hope that helps! Nicolas

2 Likes

Thank you so much for reply. I will try it

You’re welcome! Let me know if that works or if you have any issue

Hi Nicolas, sorry for the late reply.
your code worked but some issues appeared
because when user is in a formAction (some slots are filled and some slots are not filled)
user cannot reset chatbot. All type of slot are unfeaturized and text.
How can i reset chatbot anytime

Thank you so much,

@vunt39 what happens when the user tries to reset the slots? How is the slot mapping of your forms?

For us, it usually works but we have some issues sometimes in forms (it’s quite erratic though).

here is the slot mapping

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]: return { # “cuisine”: self.from_entity(entity=“cuisine”, not_intent=“chitchat”),

        "lunch_time_string": [self.from_entity(entity="lunch_time_string"), self.from_text()],
        "lunch_select_kitchen": [self.from_entity(entity="lunch_select_kitchen"), self.from_text()],
    }

the slot mapping of my bot capture text message from user because there are many slot is number. for example lunch_number_slot is number, and lunch_number_people is a number too. so i cannot capture that slots in 1 or multiple intent. i capture that by self.from_text(). i think it’s the issue

this is an idea of mine about that in file actions.py

def validate_lunch_select_kitchen(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Any:
print(value)
if(value == ‘restart’):
return [trackers(‘action_reset_full’)]
if vali.validate_kitchen(value):
value = vali.return_kitchen(value)
return {“lunch_select_kitchen”: value}
else:
dispatcher.utter_template(“utter_wrong_lunch_select_kitchen”,tracker)
return{“lunch_select_kitchen”: None}

but it isn’t work.

Two ideas:

  • Do you have the MappingPolicy at the beginning of your policies in config.yml? Without it, the mapped triggers won’t work (and as far as I understand, this policy must be at the beginning of yourp policies)
  • In the slot_mapping, you can also explicitely ignore some intents. self.from_text(not_intent=["reset"]) for example. That can also be achieved with stories I believe but it’s much more annoying to do.

On a side note regarding your numbers problem. We had a similar issue with number of bedrooms and number of bathrooms that could be specified in the same sentence. What I ended up doing was to create two entities bedrooms_count and bathrooms_count and added some training samples:

## intent:chose_apartment
- I need a [1](bedrooms_count) bed [2](bathrooms_count) bath apt
- Looking for a [one](bedrooms_count) bedroom flat
- ...

No idea if it’s best practice but that worked quite well with enough training samples as the CRFEntityExtractor would recognize that the number is followed by a specific word. Then, in our validation functions, we matched the number extracted by Duckling and the one extracted by the bedrooms_count/bathrooms_count entities.

Hope that helps!

Hi nicolas. thank you for your reply. i think that knowledge help me very much. i will try it and then notify you about my result. thank you so much again

Very happy to help :slight_smile: Let me know how it goes!

thank you nicolas that’s advice really really helpful to me. it’s worked. thank you so much

1 Like