How to debug rasa-core?

In the project I’m working on, I have replaced rasa-nlu with a custom Interpreter subclass which returns a json in rasa nlu format. Now I want the chatbot to run the custom action form, when the intent is detected.

excerpt of my code:

endpoint = EndpointConfig(url="http://localhost:5055/webhook")
agent = Agent.load('chatbot/model/dialogue', interpreter=interpreter, action_endpoint=endpoint)
response = agent.handle_text(chat_text)

I ran the action endpoint local server and it registered my form action.

My FormAction returns a custom string message and I have also used a dispatcher to utter the same custom message.

When I run it, the nlu works fine and the agent is initialized without issues but there is no response and also NO debug / error messages.

I ran the examples and in the formbot example the rasa process starts, form action is activated and is run but in my code there is no error, no warning and no output.

Please tell me how to debug Agent and why I’m not getting any logging messages.

Update: I created a mock json that is to be sent to the action server with required entities and slots filled and POSTed it using Postman and the action correctly called the API and returned a response. So clearly the issue is occurring within the Agent.

Also, agent.is_ready() returns -> True

Update2: I was running the python chatbot as a service using nginx. So I was unable to debug without changing all the file paths etc. So I copied the project, removed all but essentials and the interpreter and rasa agent logic and debugged it. It ran correctly, sent a request to action server and received correct response. However, when I run the same code through the service, I get no response from the agent and the action server has nothing indicating the form action was called/executed like it did when debugging.

One way you can run your bot in a debub mode is adding the --debug flag when you start it. For example:

python -m rasa_core.run -d models/dialogue -u models/nlu/current --debug

With it you should be able to see much more output on what’s going on under the hood

I was running the chatbot as a nginx service and so debugging the code is not possible. What I did was to copy only the relevant files to a separate project, debug them in the IDE, and find out the issue.

The biggest issue was that the FormAction slot utterances were not being uttered. I realised that I hadn’t written them into the domain file. As soon as I added the utter_ask_SLOT utterances to the domain file, and trained it, the bot was correctly giving me the appropriate response.

I still cannot debug the nginx service however, I can write a bunch of app.logger.debug() statements to debug the flask app. I cannot debug the agent as that is running as a service.

Thanks for the reply anyways.

Hey @anurags, I want to use my own interpreter subclass. How and where did you exactly specify your own interpreter?

It’s solved now

@Juste, Is this still valid with latest release?

Hi @prakashdale. In Rasa 1.0 you can add the --debug flag when you run your bot. For example:

rasa shell --debug

@Juste, I have downloaded and installed rasa from the github source. I use VS Code as IDE. Created a test bot using rasa init. When I run this bot using rasa shell --debug, I want to hit the debug break point in rase core code. So just wondering how this can be set.

1 Like

Hi @Juste, Is there a way to debug actions.py properly? I’m trying to debug it on VSCode.

I’m using rasa_core_sdk version 0.13.0 but this should apply to other versions before 1.x.x. Open the package files (rasa_core_sdk), open endpoint.py, and find the following code:

# Running as standalone python application
# arg_parser = create_argument_parser()
# cmdline_args = arg_parser.parse_args()

You must be typing the command line script to run rasa action server. Instead of starting action server using that command, replace/comment the code shown above with:

from argparse import Namespace
cmdline_args = Namespace()
setattr(cmdline_args, "actions", "actions")
setattr(cmdline_args, "cors", None)
setattr(cmdline_args, "port", DEFAULT_SERVER_PORT)

This mimics the default args and will allow you to directly run/debug the action server from the IDE.

Add breakpoints and enjoy debugging.

Let me know if this works for you and I’m waiting for the official way to debug it line by line from the rasa team as well.

Rather than changing the distribution, I simply created a vscode debug configuration in .vscode/launch.json:

   {
        "name": "Rasa: actions",
        "type": "python",
        "request": "launch",
        "program": "/Users/edguy/miniconda3/bin/rasa",
        "console": "integratedTerminal",
        "cwd": "${workspaceFolder}",
        "args": ["run","actions","--debug"],
        "env": {               "PYTHONPATH":"/Users/edguy/miniconda3/bin:/Users/edguy/miniconda3/lib/python37.zip:/Users/edguy/miniconda3/lib/python3.7:/Users/edguy/miniconda3/lib/python3.7/lib-dynload:/Users/edguy/miniconda3/lib/python3.7/site-packages"
        }
    }

I determined the path by inserting, for one run, this line into the rasa file before the from rasa.main import line:

print(sys.path)

then running the rasa program and manually converting the json array into a shell array.

There are probably better, more portable, ways to set this up, but it works for me.


Nice to meet so many folks in SFO this past week!

1 Like