Rasa multiple action files

Hi folks,

If i want to create multiple action files, how can i include it in single actions.py?

1 Like

Hello @BellaS,

You just need to create your custom action file normally. And then in the actions.py, you import those files accordingly, like this:

from somewhere import CustomAction 

While somewhere depends on the directory you put the CustomAction file in. Hope that helps :smile:.

3 Likes

Hi @fuih,

I am getting tracker not defined error while calling from different python file , and the bot dosnot utter message when doing the same ,

Can you please share the example code for the same

thank you

hey @Aashay1 share you action file

hey @bparikh99,

I did resolve this thank you for he reply

On Rasa 3 there is no need to import files to a single action.py file because all python actions on the folder are imported

image

If I renamed my ‘actions.py’ and created 3 more action files all in the folder actions: grafik

But if I run ‘rasa run actions’ i get the following error:

> 2022-01-06 21:21:17 ERROR    rasa_sdk.executor  - Failed to register package 'actions'.
> Traceback (most recent call last):
>   File "e:\masterarbeit_hannes\miniconda\envs\venv3\lib\site-packages\rasa_sdk\executor.py", line 262, in register_package
>     self._import_submodules(package)
>   File "e:\masterarbeit_hannes\miniconda\envs\venv3\lib\site-packages\rasa_sdk\executor.py", line 218, in _import_submodules
>     package = self._import_module(package)
>   File "e:\masterarbeit_hannes\miniconda\envs\venv3\lib\site-packages\rasa_sdk\executor.py", line 239, in _import_module
>     module = importlib.import_module(name)
>   File "e:\masterarbeit_hannes\miniconda\envs\venv3\lib\importlib\__init__.py", line 127, in import_module
>     return _bootstrap._gcd_import(name[level:], package, level)
>   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
>   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
>   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
> ModuleNotFoundError: No module named 'actions'

What am I doing wrong?

Hey @mxnno, You need to keep file name as @jona has kept.

<some_name>_actions.py

and it will work… working for me with

Rasa Version : 2.6.2

Rasa SDK Version : 2.6.0

1 Like