Custom action endpoints

Hi everyone,

I’m new to Rasa and I’m trying to make it work with Haystack. I followed the tutorial Haystack has published on their website for integrating with Rasa. Everything works well, except I get this error:

Failed to execute custom action 'call_haystack' because no endpoint is configured to run this custom action. Please take a look at the docs and set an endpoint configuration via the --endpoints flag.

I looked at the custom action documentation and can’t find a clear solution.

At the bottom of my domain.yml I defined the custom action:

actions:
  - call_haystack

In endpoints.yml I have this uncommented:

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

And this is a custom action code in actions.py:

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher

class ActionHaystack(Action):


    def name(self) -> Text:
        return "call_haystack"


    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:


        url = "http://localhost:8000/query"
        payload = {"query": str(tracker.latest_message["text"])}
        headers = {
            'Content-Type': 'application/json'
        }
        response = requests.request("POST", url, headers=headers, json=payload).json()


        if response["answers"]:
            answer = response["answers"][0]["answer"]
        else:
            answer = "No Answer Found!"


        dispatcher.utter_message(text=answer)


        return []

I also defined a rule in the rules.yml and the intents in the nlu.yml

After I’ve done this, I ran:

rasa train
rasa run actions

I have Haystack running in another container.

I use rasa shell to talk to the bot, everything is fine, but when I ask something that should be delegated to Haystack I get the error I mentioned.

Can someone please tell me what am I missing?

Thanks

Also, rasa run actions gives the following:

2022-04-01 16:46:58 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2022-04-01 16:46:58 INFO     rasa_sdk.executor  - Registered function for 'call_haystack'.
2022-04-01 16:46:58 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055

I also realized the following, I think I had an indentation error in my endpoints.yml file.

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

I didn’t have the indentation at the start of the second line above.

Now that I “fixed” the indenatation, I get the following error:

Encountered an exception while running action 'call_haystack'.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/ml/rasa/venv/lib/python3.8/site-packages/rasa/core/actions/action.py", line 742, in run
    response: Any = await self.action_endpoint.request(
  File "/home/ml/rasa/venv/lib/python3.8/site-packages/rasa/utils/endpoints.py", line 173, in request
    raise ClientResponseError(
rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body='b'{"description":"Internal Server Error","status":500,"message":"The server encountered an internal error and cannot complete your request."}''

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

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

I hope this additional info helps. Thanks