RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.92k stars 4.63k forks source link

Rasa 3.2 custom action not called when agent is loaded with action endpoint from another python file #11468

Closed getnsv closed 1 year ago

getnsv commented 2 years ago

Rasa Open Source version

Rasa Version : 3.2.6 Minimum Compatible Version: 3.0.0 Rasa SDK Version : 3.2.0 Python Version : 3.7.13 Operating System : Windows-10-10.0.19041-SP0

Rasa SDK version

3.2.0

Python version

3.7

What operating system are you using?

Windows

What happened?

I have the following code to load agent in a python file - bot.py from rasa.core.agent import Agent from rasa.core.http_interpreter import RasaNLUHttpInterpreter from rasa.core.utils import AvailableEndpoints from rasa.utils.endpoints import EndpointConfig

… agent = Agent.load(model_path=path_to_model, action_endpoint=EndpointConfig(url=‘http://localhost:5055/webhook’))

Am running my action server with command - “rasa run actions” And it is showing the registered custom action like this - 2022-08-17 23:55:01 INFO rasa_sdk.endpoint - Starting action endpoint server… 2022-08-17 23:55:01 INFO rasa_sdk.executor - Registered function for ‘action_hello_world’. 2022-08-17 23:55:01 INFO rasa_sdk.endpoint - Action endpoint is up and running on http://0.0.0.0:5055/

When I run the python file - it is showing the prediction of the custom action, but the endpoint is never called. All other utterances without custom action is working.

Again when I run rasa shell command its fine, custom action is getting picked up.

All this code was running fine with rasa 2.8, and its not working with rasa.

Please help with the correct syntax to run the agent with the actions endpoint in rasa 3.2. I have spent more than 16 hours to figure out this problem. All help is much appreciated.

Command / Request

No response

Relevant log output

No response

ancalita commented 2 years ago

@getnsv Could you please provide:

In addition, it would be great if you could give more explanation why do you need the custom agent code?

A4Ayub commented 2 years ago

@ancalita I have a slightly similar issue. I have successfully deployed rasa 3.2.10 with rasa action server, mongodb and mongo-express on okteto infrastructure.

The intent is correctly predicted and passed to the action server but on the action server logs i get the errors below:

2022-10-21 14:37:38.29 UTCrasa-actions-7b859f86df-grlttrasa-actions2022-10-21 14:37:38 DEBUG rasa_sdk.executor - Received request to run 'action_show_time' 2022-10-21 14:37:38.29 UTCrasa-actions-7b859f86df-grlttrasa-actions2022-10-21 14:37:38 ERROR rasa_sdk.endpoint - No registered action found for name 'action_show_time'. 2022-10-21 14:37:38.29 UTCrasa-actions-7b859f86df-grlttrasa-actions2022-10-21 14:37:38 DEBUG rasa_sdk.executor - Received request to run 'action_show_time' 2022-10-21 14:37:38.29 UTCrasa-actions-7b859f86df-grlttrasa-actions2022-10-21 14:37:38 ERROR rasa_sdk.endpoint - No registered action found for name 'action_show_time'.

The actions.py is as below:

**import datetime as dt from typing import Any, Text, Dict, List

import arrow

import dateparser

from rasa_sdk import Action, Tracker

from rasa_sdk.events import SlotSet

from rasa_sdk.executor import CollectingDispatcher

This files contains your custom actions which can be used to run

custom Python code.

#

See this guide on how to implement these action:

https://rasa.com/docs/rasa/custom-actions

city_db = { 'brussels': 'Europe/Brussels', 'zagreb': 'Europe/Zagreb', 'london': 'Europe/Dublin', 'lisbon': 'Europe/Lisbon', 'amsterdam': 'Europe/Amsterdam', 'seattle': 'US/Pacific', 'nairobi': 'Africa/Nairobi' }

This is a simple example for a custom action which utters "Hello World!"

class ActionShowTime(Action):

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

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

    #current_place = next(tracker.get_latest_entity_values("place"), None)
    #utc = arrow.utcnow()

    #if not current_place:
    #    msg = f"It's {utc.format('HH:mm')} utc now. You can also give me a place."
    #    dispatcher.utter_message(text=msg)
    #    return []

    #tz_string = city_db.get(current_place, None)
    #if not tz_string:
    #    msg = f"It's I didn't recognize {current_place}. Is it spelled correctly?"
    #    dispatcher.utter_message(text=msg)
    #    return []

    #msg = f"It's {utc.to(city_db[current_place]).format('HH:mm')} in {current_place} now."
    #dispatcher.utter_message(text=msg)

    #dispatcher.utter_message(text=f"{dt.datetime.now()}")
    dispatcher.utter_message("The time is still not known!")

    return []**

And the actions.py file is under the actions folder.

I only have one action that is in the actions.py file. However, upon starting the action server, i figured that the custom action is not being registered as expected. It skips the registration of the customer actions and that explains why it cannot be found

Please see below the logs for the actions server upon restarting the action server:

2022-10-21 14:42:54.00 UTCrasa-actions-655dfbc4c5-28p6n[pod-event]Created container rasa-actions 2022-10-21 14:42:54.00 UTCrasa-actions-655dfbc4c5-28p6n[pod-event]Started container rasa-actions 2022-10-21 14:42:55.81 UTCrasa-actions-655dfbc4c5-28p6nrasa-actions2022-10-21 14:42:55 DEBUG rasa.telemetry - Could not read telemetry settings from configuration file: Configuration 'metrics' key not found. 2022-10-21 14:42:56.00 UTCrasa-actions-655dfbc4c5-28p6nrasa-actions2022-10-21 14:42:56 INFO rasa_sdk.endpoint - Starting action endpoint server... 2022-10-21 14:42:56.01 UTCrasa-actions-655dfbc4c5-28p6nrasa-actions2022-10-21 14:42:56 INFO rasa_sdk.endpoint - Action endpoint is up and running on http://0.0.0.0:5055/ 2022-10-21 14:42:56.01 UTCrasa-actions-655dfbc4c5-28p6nrasa-actions2022-10-21 14:42:56 DEBUG rasa_sdk.utils - Using the default number of Sanic workers (1).

I do not know what needs to be done in order to ensure that the custom actions are registered successfully.

Below is the endpoints.yml entry

action_endpoint: url: "https://rasa-actions-a4ayub.cloud.okteto.net/webhook"

I have struggled with this for one week and custom actions is not working. 98% of the work ahead is to store and retrieve information from the database and i have been stuck at this for one week.

Please help me unravel what could be the issue.

Thanks

A4Ayub commented 2 years ago

When i run rasa run actions -vv (same command used in docker compose file), then the custom action is successfully registered. However, it seems not to be registered when rasa action server is started through docker compose

image

A4Ayub commented 2 years ago

Managed to resolve. It was a mistake on my side. In the docker ignore i had included the actions folder.

sync-by-unito[bot] commented 1 year ago

➤ Maxime Verger commented:

:bulb: Heads up! We're moving issues to Jira: https://rasa-open-source.atlassian.net/browse/OSS.

From now on, this Jira board is the place where you can browse (without an account) and create issues (you'll need a free Jira account for that). This GitHub issue has already been migrated to Jira and will be closed on January 9th, 2023. Do not forget to subscribe to the corresponding Jira issue!

:arrow_right: More information in the forum: https://forum.rasa.com/t/migration-of-rasa-oss-issues-to-jira/56569.