Running Rasa within an IDE for debugging purposes

I do most of my development in IntelliJ. It allows you to run python code in it’s debugger which is very useful because you can insert breakpoints and look at variables at that point in the code.

Since I have to use Rasa’s entry point from the command line: ($rasa shell) and run custom actions as a server ($rasa run actions). I do not see any obvious way in which I can make use of my debugger, either to debug the actions.py file or to observe the inner workings of Rasa itself.

Is there a way to do this? Thank you.

1 Like

Hi @zeroangel, welcome to the forum!

You can configure your IDE debugger by running rasa as a module rather than script. Create a new debug configuration and supply the module you want to run in interpreter options. For example, to run the debugger on rasa init, you’d have to put

The same goes for rasa shell with -m rasa shell. I hope that helps!

I am getting the following Warning and not seeing any output:

Warning: Output is not to a terminal (fd=1).
Warning: Input is not to a terminal (fd=0).

Any ideas?

What exactly did you do that caused those warnings?

Within IntelliJ:

Run -> Edit Configurations

I added a new config:

Script Path =

<Virtual Environment DIR>/lib/python3.6/site-packages/rasa/__main__.py Parameters =

shell --m <Project directory>/models --log-file <Project directory>/rasa_core.log --endpoints <Project directory>/endpoints.yml

It runs and hits breakpoints within rasa’s code but I cannot navigate any buttons in the Two Stage Fallback for example. Furthermore, I cannot stop at breakpoints within the actions.py custom actions file. Obviously that is because it is run as a web hosted service via:

rasa run actions

So how could one accomplish that as well? Can “rasa run actions” be run as a module? When I run -help for that command I don’t see an argument to specify where the actions.py file is located. In any case, it seems like since that command runs actions.py as a web hosted service (even locally) and that would not allow me to stop at breakpoints within IntelliJ for the actions.py file.

You could run the action server as a module with the rasa_sdk package (GitHub - RasaHQ/rasa-sdk: SDK for the development of custom actions for Rasa):

python -m rasa_sdk --actions actions

Also have a look at Actions for documentation.

I find it easiest to use this little startup script. I tested it with the Wing IDE, but it should work for any python debugger.

file: run_action_server_with_IDE.py

"""This script allows use of an IDE (Wing, Pycharm, ...) to debug custom actions:

(-) Place this script in same location as your actions.py
(-) Open & run it from within your IDE
(-) Now you can put breakpoints in your actions.py, but also explore the internals of the
    rasa_sdk action server itself.
"""

import os
import sys

# insert path of this script in syspath so actions.py will be found
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))

#
# This is exactly like issuing the command:
#  $ rasa run actions
#
sys.argv.append('run')
sys.argv.append('actions')
from rasa.__main__ import main
main()

This is how I run server via pycharm. This also will work for debug mode.