How to manage a lot of actions in actions.py

I have a lot of actions defined in actions.py file. As a result, my actions.py file is now very large (in terms of code). Is there any way to partition this file (actions.py) into different number of actions.py files, each related to a specific category action?

Hi @Sajjadmanal, yes you can partition your actions in multiple files! Just create a directory actions and place your code in it, splitting it as you see fit.
As far as I’m aware, as long as it’s in actions, Rasa will pick up and register the relevant classes based on the rasa_sdk classes like FormValidationAction, Action, etc, and not based on which module they’re in.

When starting the server, rasa run actions should work just as well.
Hope that helps!

1 Like

@E-dC Thanks for the reply. Okay, so each of the file will import everything that gets imported in actions.py? And for dockerfile, do we need to add these new files?

For running locally everything in the actions folder will be imported. If you have a dockerfile for actions just add “RUN mkdir -p actions” and “COPY . ./actions/”.

2 Likes

Not quite: say you have an actions directory as follows:

actions/__init__.py
       /some_common_code.py
       /actions1.py
       /actions2.py
       /actions3.py

You can organise your actions as a regular python package: perhaps some modules import other, etc
As far as I’m aware, the server will load all your code this way, but will register actions by looking at your classes definitions (ActionAbc(Action)will get registered, but SomeOtherClass(object) won’t).

For Dockerfile, yes, as @simonm3 wrote, you need to copy the whole actions folder

2 Likes

Thanks @E-dC

Thanks @simonm3