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!

1 Like

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()
8 Likes

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

2 Likes

Perfect answer @Arjaan

Hi, can you please add some screen shots of pycharm how and where to add this. Am quite new to the IDE and still learning.

It is helpful for me, thank you, great answer

1 Like

super helpful

what is the from rasa.__main__ import main? it is giving me an error that the module is unknown

@joeymizrahi,

Probably you do not have rasa properly installed.

Can you run rasa from the command line? For example:

rasa --version

The line from rasa.__main__ import main is a regular import of the main() method in the __main__.py module, (see here).

These responses are very useful if you want to run the rasa action server in an IDE such as IntelliJ or Pycharm. Just to add on to this, if you want to run the rasa shell, you have to create another (similar) custom Run/Debug configuration where you:

  • provide the rasa executable as the “Script path”
  • provide corresponding model/endpoints/etc arguments in “Parameters”.
  • check the box which says “Emulate terminal in output console” under “Execution”

The first two steps are similar to what’s required for running the action server. The last step is important, otherwise you’ll get

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

in the console.

Select the checkbox.

Have to mention here that the fix suggested by @Arjaan on Sep '19 worked for me as well in Rasa 3.0.

Managed to put breakpoints in actions.py using Pycharm.