Error with Custom Actions

Hi All,

As a preface, I have updated rasa x, rasa-sdk, and rasa to all of their latest versions as of 9/8/19.
I am attempting to use custom actions in rasa x, and I have scoured through multiple forum posts, particularly this one: Can't Get my Custom Action to Work Yet, I am still unable to resolve the custom action error.

I also looked through this one which has my exact error: Custom action not found error

Essentially, I have the same error of: Encountered an exception while running action 'action_get_hotel_link'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.

I have followed all of the steps (as far as I can tell) that were mentioned in that post, and ultimately, here are all my associated files:

Action.py:

from typing import Dict, Text, Any, List, Union, Optional

from rasa_sdk import Action, Tracker, ActionExecutionRejection
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction, REQUESTED_SLOT
from rasa_sdk.events import Restarted


class BookHotel (Action):
    def name(self):
        return 'action_get_hotel_link'
    
    def run(self, dispatcher, tracker, domain):
        
        sp_data = "this is a test"
        
        dispatcher.utter_message(sp_data)
        return []

domain.yml (necessary info)

actions:

- action_default_ask_affirmation

- action_default_fallback

- action_get_hotel_link

endpoints.yml

action_endpoint:
  url: "http://localhost:5055/webhook"

#core_endpoint: 
#  url: http://localhost:5005

Note I was trying with both the core lines uncommented and commented, should I leave it uncommented?

Error message

I ran rasa run actions --actions actions (and I also tried rasa run actions --actions testbot.actions but I got: ModuleNotFoundError: No module named ‘testbot’ error so I just did it without testbot)

Any insight would be greatly appreciated! I am at a loss after reading all of the forum posts on this error, so I am beginning to think that it is the incompatibility issue between the sdk and rasa versions or I am missing something blatantly obvious (which is very likely).

Thank you all so much!

I’m sorry if i’m asking a silly question but is your Action.py actually named ‘Action.py’ ? If yes can you try changing to ‘actions.py’ and see how it goes ?

Thank you for the reply. It is called “actions.py”, and I mistyped it in my post. Thanks!

First of all, thanks for providing so much revelant information! I’ve edited your comment to format code and console output with the three ticks (```) above and below for readibility.

It’s not an issue with the compatibility – we just hadn’t released a compatibility release for SDK yet since nothing changed (i.e. sdk 1.1.1 is compatible with rasa 1.2.x), however since you posted we did release sdk 1.2.0 if you want that error message to go away :slight_smile:

The action endpoint looks good, you want to keep it uncommented as it is. Core endpoint you don’t need.

The issue is that it’s registering some sort of action server but not your actual action. For reference, if it’s registered it correctly, this is what you should see upon starting the server:

rasa ❯ rasa run actions
2019-08-21 01:29:47 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2019-08-21 01:29:47 INFO     rasa_sdk.executor  - Registered function for 'action_get_hotel_link'.
2019-08-21 01:29:47 INFO     rasa_sdk.endpoint  - Action endpoint is up and running. on ('0.0.0.0', 5055)

Can you share your project directory structure, as well as your working directory when you run your actions command, and what that command is? I want to make sure the correct path is being passed to the rasa run actions command. My guess is that it’s registering the commented out actions.py file from rasa init instead of the one you wrote, or something like that. I copied your code into my example bot and it registered the action correctly, so it’s no issue with your code, just something with the path.

1 Like

Thank you Ella! It was indeed a directory structure issue, and I reformatted it to put my actions.py in a demo folder and called it from there. Thanks for your help again!

1 Like

Coolio. No worries! Keep on truckin :rocket:

1 Like

Action server is running showing this result.

2021-08-11 03:30:56 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2021-08-11 03:30:56 INFO     rasa_sdk.executor  - Registered function for 'action_weather_api'.
2021-08-11 03:30:56 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055
2021-08-11 03:30:56 DEBUG    rasa_sdk.utils  - Using the default number of Sanic workers (1).

actions.py

    from typing import Any, Text, Dict, List

    from rasa_sdk import Action, Tracker
    from rasa_sdk.executor import CollectingDispatcher
    from weather import Weather

    class ActionHelloWorld(Action):
        def name(self) -> Text:
            return "action_weather_api"

        def run(self, dispatcher: CollectingDispatcher,
                 tracker: Tracker,
                 domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
             city=tracker.latest_message['text']
             temp=int(Weather(city)['temp']-273)
             dispatcher.utter_message("utter_temp",tracker,temp=temp)

             return []

   Action_endpoint:
      url: "http://34.125.200.140:8080"

     credentials.yml
     rasa:
     url: "http://34.125.200.140:5055/api"

Bot loaded. Type a message and press enter (use '/stop' to exit):
Your input ->  Hi
Hey! How are you?
Your input ->  Weather
Which city you want to check for?
Your input ->  Dubai
2021-08-11 03:32:12 ERROR    rasa.core.actions.action  - Failed to run custom ac                                                                                        tion 'action_weather_api'. Couldn't connect to the server at 'http://34.125.200.                                                                                        140:8080'. Is the server running? Error: Cannot connect to host 34.125.200.140:8                                                                                        080 ssl:default [Connection refused]
2021-08-11 03:32:12 ERROR    rasa.core.processor  - Encountered an exception whi                                                                                        le running action 'action_weather_api'.Bot will continue, but the actions events                                                                                         are lost. Please check the logs of your action server for more information.
Traceback (most recent call last):
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)  # type: ignore                                                                                          # noqa
  File "uvloop/loop.pyx", line 1974, in create_connection
  File "uvloop/loop.pyx", line 1951, in uvloop.loop.Loop.create_connection
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/Rishabh/venv/lib/python3.8/site-packages/rasa/core/actions/action.                                                                                        py", line 685, in run
response = await self.action_endpoint.request(
  File "/home/Rishabh/venv/lib/python3.8/site-packages/rasa/utils/endpoints.py",                                                                                         line 163, in request
async with session.request(
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/client.py", line                                                                                         1117, in __aenter__
self._resp = await self._coro
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/client.py", line                                                                                         520, in _request
conn = await self._connector.connect(
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 535, in connect
proto = await self._create_connection(req, traces, timeout)
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 1051, in _create_direct_connection
raise last_exc
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
  File "/home/Rishabh/venv/lib/python3.8/site-packages/aiohttp/connector.py", li                                                                                        ne 975, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 34.125.20                                                                                        0.140:8080 ssl:default [Connection refused]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Rishabh/venv/lib/python3.8/site-packages/rasa/core/processor.py",                                                                                         line 772, in _run_action
events = await action.run(
  File "/home/Rishabh/venv/lib/python3.8/site-packages/rasa/core/actions/action.                                                                                        py", line 717, in run
raise RasaException("Failed to execute custom action.")
rasa.shared.exceptions.RasaException: Failed to execute custom action.

Thanks for raising this question… I am also facing the same problem can anybody help me to fix this.