Using unfeaturized custom slots to keep information in bot memory

Let’s say I want to get some basic data that my bot will then access repeatedly and have to manipulate and present different parts of it. For example, a dictionary will have a definition of a word that is both a noun, verb and adjective, like “access” in English. I want to store the entire set of definitions in bot memory and then access different parts of it, like the verb part or the noun part, depending on what the user chooses via the bot. I could just store the information in a file and have the custom actions get it out of there, but it seems that there should be a way to do that inside Rasa itself. Is there a way to have a custom slot that could store that information as a Python dictionary object that then could be accessed by other custom actions?

Im not sure I understand your question is since you seem to have answered it yourself - you can use an unfeaturized slot that has a dictionary object set into it , and you can use it for the purpose you describe

My question was more about saving a custom class object. The dictionary I was referring to was not a python dictionary, but a dictionary with word, number definitions and parts of speeches etc. What I did find subsequently is that you CAN store a custom class object in a slot but that breaks online training since rasa_core tries to write it to a story and can’t, since my custom class is not a json object. It breaks in event/init.py:

def as_story_string(self):
    props = json.dumps(self._data_obj())
    return "{name}{props}".format(name=self.type_name, props=props)

If your class object is not JSON it won’t work. So I had to do this:

         def as_story_string(self):
   try:
       props = json.dumps({self.key: self.value})
   except:
       props={self.key: "class_object"}
   return "{name}{props}".format(name=self.type_name, props=props)

And that works. The only problem is that when the online-training story with this new class data is loaded, rasa_core breaks. So for now I have to manually this hacked class data from my generated stories. That’s ok though since it’s an unfeaturized slot and does not affect the dialogu. I hope this make sense.

Yes I believe there is an open issue about this https://github.com/RasaHQ/rasa_core/issues/668

Any update on this? What’s the best way to store information about a user? If I understand correctly, I could use an unfeaturized slot, right? But in that case, whenever the conversation is restarted, the data will be cleared as well, correct?

Why are you restarting the conversation? when the context continues to exist which is important to you.

Slots are not storage but rather giving context to your conversation, if you restart the conversation, it is normal to reset the slots

@souvikg10: I’m not intentionally restarting the conversation. But sometimes you end up in a situation where the bot is stuck. In that case I want the user to know that they can type /restart. However, if a user uses this quite often, I still don’t want him to enter some crucial data again and again, for example his name.

So I was wondering if there’s a ‘more persistant’ storage than the slots

Why is your bot getting stuck? have you checked your model?

Does restarting the bot solves the issue, use debug to detail the issue. it could be linked to stories.

depending on your user, i would advise not to tell them to restart.

@souvikg10 Yes, I believe it is my stories / training data lack. However, I haven’t found a good way to guarantee I never get stuck. How do you solve this?

For example, I could have a 30 min conversation without an issue, but then I run into a loop and get stuck because core is always predicting the same actions from there …

Or sometimes, it’s executing the right action, but then sending the default fallback right after as well …

Is your story 30min long? I think you need to check how much history is relevant for your conversation, your bot maybe is getting stuck because of a particular story

there is an article i wrote describing how policies work and what is been used and why. maybe it can help

No, sorry. It’s not 30 mins long. What I meant is that only after testing all kinds of different flows of conversations for 30 mins I run into situations where it gets stuck. So sometimes I just seem to end up at some certain history that causes the bot to get stuck or answer with default fallback all the time.

I’ll check your article, thanks!