Handling multiple custom actions with a single class

I want to handle all custom actions in a generic way using only one Python class. Is that possible?

I found the same request here:

     https://github.com/RasaHQ/rasa/issues/2313

but I don’t know if the issue has been addressed.

No, I don’t think we currently have a way to create custom actions on the fly. Why do you want to do this?

I don’t really intend to register actions on the fly.

I intend to use a single class to treat several actions generically.

One use of this is to implement a utterance generator that varies the language according to the user profile, and allow the utterances to be specified by a designer who is not a programmer.

That, however, is just an example. I want the freedom to handle actions my way, without having to implement one class for each action.

I think I can achieve that goal using remote actions, but I have not studied till this point. Is that correct?

I imagine that an alternative would be to generate “actions.py” dynamically. Would that be a problem?

One use of this is to implement a utterance generator that varies the language according to the user profile, and allow the utterances to be specified by a designer who is not a programmer.

Can you not do this with dispatcher.utter_template, where you can add keyword args with user information in them?

I intend to use a single class to treat several actions generically.

I mean you could definitely code something to do this, we do a similar thing with action_chitchat and action_faq here: https://github.com/RasaHQ/rasa-demo/blob/master/demo/actions.py#L185

I want the freedom to handle actions my way, without having to implement one class for each action.

I still don’t understand what you have against writing multiple action classes. The way it works, it uses the name() method of the class to register and use that action, so yes, anything distinct muss be its own class with its own name method.

I imagine that an alternative would be to generate “actions.py” dynamically. Would that be a problem?

Yes, this would be a problem, as your actions code is loaded when you run the action server. In order to change it you would have to shut down and restart the action server.

I liked the examples of action_chitchat and action_faq.

In these examples, you handle several intents with a single action.

However, I imagined that this strategy would hide part of the dialog from rasa-core what could affect the learning process. There are actually several actions, but rasa-core will see them all as one.

I expected rasa-core to choose the action based on stories.

If I register only a single action and decide everything based on the prior intent, I think I will be loosing part of Rasa’s abilities

Is that really the way to go?

I am still getting acquainted to Rasa, but I will tell more about the architecture I have in mind.

Currently, we have a live chat running. Human employees are responding.

I want some supervisors, who are not programmers, to annotate stories from the live chat.

Using a GUI, they will mark the intents of the users, but also the intents of the employees who are responding to them. The intents of the employees will actually become actions in the stories I intend to generate to train rasa-core. I don’t want to have to implement a Python class every time the supervisors create new actions, but if I don’t tell rasa-core that these actions exist at all and use only one Python class, how can it learn?

My plan is that after some stories are annotated, I will be able to automatically select the most ambiguous stories that have not been annotated and ask the supervisors to annotate them.

Is rasa-x a solution to annotate live chat stories?

Using a GUI, they will mark the intents of the users, but also the intents of the employees who are responding to them. The intents of the employees will actually become actions in the stories I intend to generate to train rasa-core.

I don’t want to have to implement a Python class every time the supervisors create new actions, but if I don’t tell rasa-core that these actions exist at all and use only one Python class, how can it learn?

I don’t think it’s possible to have it learn to do separate things with the same action. If your supervisor is doing something different, then you’ll have to create a new action for it.

I think you’re going about this the wrong way. A bot always has a restricted domain of the number of things that it can do. Instead of trying to get it to do everything that all the different human supervisors do, I would create the bot to handle some popular actions, with a fallback for things it cannot yet do, and then add more supervisor actions on priority basis.

Is rasa-x a solution to annotate live chat stories?

yes, you can use rasa x to annotate and correct live chat stories, in the sense that you can change the predicted intents and actions if they were wrong, however, you can’t create new actions in that annotation.

I really expected that handling several actions with a single class would be easy.

Do you have a reason for not allowing that?

As I mentioned, it is possible, but you’ll run into this issue:

I expected rasa-core to choose the action based on stories.

If I register only a single action and decide everything based on the prior intent, I think I will be loosing part of Rasa’s abilities

because each story will handle that action in the same way. Otherwise I don’t really know what to tell you

hello @erohmensing if I send response using dispatcher.utter_message(template=‘utter_confirm’) then how to match that reply with intent and again respond back ?

Hi @erohmensing , That github link seems to be broken. I am trying to implement a similar use case. Current config: I have about 50 small talk intents and mapped responses in domain.yml

What I want to achieve: I have a parent intent lets say chitchat, and in these 50 sub-intents. The response could come based on sub-intent of chitchat and a slot value which I could check programatically and respond by using utter. Would this be possible?

Hey @sushrutt12! Good news – since this thread there is a much better answer, actually! For a parent/sub intent like chitchat where they should all be handled the same way, you should use the response selector! Check out the docs on answering FAQs here (similar use case) Tutorial: Building Assistants

@erohmensing Thanks! Sorry to go off thread topic here, I saw this article for multilingual bots. Anyway I can serve various language models via 1 api? or programatically route to various models based on a slot value?

Please try not to change the topic as others may have the same question about handling multiple custom actions and it can make it confusing. For multi-language I recommend watching this video from N26 about how they have multiple NLU models and a language-agnostic Core.

1 Like