Custom action doesn't work

I’m trying a simple hello-world in custom action but the bot don’t reply.

this is my action.py file :

from rasa_sdk.events import SlotSet
from rasa_sdk import Action

class ActionHelloWorld(Action):
    def name(self):
        return "action_hello_world"

    def run(self, dispatcher, tracker, domain):
        dispatcher.utter_message("Hello world !")  # send the message back to the user
        return []

domain.yml :

actions:
- utter_greet
- utter_goodbye
- utter_searching
- action_hello_world

and stories.md :

## greet + ask_qst
* greet
  - action_hello_world

and this is the debugging during shell command :

Your input ->  hey
2019-11-14 13:03:40 DEBUG    rasa.core.tracker_store  - Creating a new tracker for id 'default'.
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Received user message 'hey' with intent '{'name': 'greet', 'confidence': 0.817916027907992}' and entities '[]'
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 2 events
2019-11-14 13:03:40 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'prev_action_listen': 1.0, 'intent_greet': 1.0}]
2019-11-14 13:03:40 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '8'
2019-11-14 13:03:40 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_MemoizationPolicy
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Predicted next action 'action_hello_world' with confidence 1.00.
2019-11-14 13:03:40 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_hello_world'.
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Action 'action_hello_world' ended with events '[]'
2019-11-14 13:03:40 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, {}, {'prev_action_listen': 1.0, 'intent_greet': 1.0}, {'prev_action_hello_world': 1.0, 'intent_greet': 1.0}]
2019-11-14 13:03:40 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '0'
2019-11-14 13:03:40 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'greet'.
2019-11-14 13:03:40 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_MemoizationPolicy
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2019-11-14 13:03:40 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2019-11-14 13:03:40 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'default'.
Your input ->

Why the bot don’t show the dispatcher.utter_message(“Hello world !”) message defined in the action.py ?

I’m running action server with Docker from rasa/rasa-sdk:latest. rasa version : Rasa 1.5.0a1

1 Like

Just to verify @vivitare you did also start up the action server as well with rasa run actions? If not the bot won’t respond

Nope, i’m using docker-compose wich is advisable in the docs : Running Rasa with Docker

this is my docker-compose.yml file :

version: '3.0'
services:
  action_server:
    image: rasa/rasa-sdk:latest
    ports:
      - 5005:5005
    volumes:
      - ./actions:/app/actions

It is not spécified to run “rasa run actions” with docker-compose but just “docker-compose up”.

see My Code Which is Working Perfectly it may help You…

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
class ActionHelloWorld(Action):
    def name(self):
        return "action_hello_world"
    def run(self, dispatcher, tracker, domain):
        print("Hello Your Name",(tracker.latest_message)['text'])
        print("Here oim ")
        # buttons = []
        print("this is tracker",tracker)
        # buttons.append({"title": "username ","payload": "pok"})
        # buttons.append({"title": "username1 ","payload": "ok"})
        # dispatcher.utter_button_message(buttons)
        dispatcher.utter_message("Hello World!")
        return []

and need to run this python -m rasa_sdk --actions actions

for run custom action server

now open another cmd window in your rasa project and check rasa shell

I can’t run python -m rasa_sdk --actions actions in Docker container. The port 5055 is already in use…

The custom action server is already running. I can show you the log with docker logs -f [custom action container id] :

[root@wqya1726 chatbot_rasa]# docker logs -f 91e81f9ffcc
2019-11-14 15:50:29 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2019-11-14 15:50:29 INFO     rasa_sdk.executor  - Registered function for 'action_hello_world'.
2019-11-14 15:50:29 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http ('0.0.0.0', 5055)

And after i run docker run -it --network="chatbot_rasa_default" -v $(pwd):/app rasa/fr:latest shell -vv

But no response is returned by the bot and there is nothing in custom action server logs.

Oh, i tried your code and look at this the action server respond :

2019-11-15 09:08:28 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2019-11-15 09:08:28 INFO     rasa_sdk.executor  - Registered function for 'action_hello_world'.
2019-11-15 09:08:28 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http ('0.0.0.0', 5055)
2019-11-15 09:15:20 WARNING  rasa_sdk.endpoint  - Your versions of rasa and rasa_sdk might not be compatible. You are currently running rasa version 1.4.5 and rasa_sdk version 1.5.0a1.
To ensure compatibility use the same version for both, modulo the last number, i.e. using version A.B.x the numbers A and B should be identical for both rasa and rasa_sdk.
Hello Your Name yo
Here oim
this is tracker <rasa_sdk.interfaces.Tracker object at 0x7fa2496eaf98>
172.20.0.2 - - [2019-11-15 09:15:20] "POST /webhook HTTP/1.1" 200 283 0.001558

i executed rasa interactive and always no response :

? Your input -> yo
? Your NLU model classified 'yo' with intent 'greet' and there are no entities, is this correct?  Yes
------
Chat History

 #    Bot                        You
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
 1    action_listen
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
 2                                       yo
                         intent: greet 0.74
------
? The bot wants to run 'action_hello_world', correct?  Yes
------
Chat History

 #    Bot                                  You
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
 1    action_listen
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
 2                                                 yo
                                   intent: greet 0.74
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
 3    action_hello_world 1.00
------
? The bot wants to run 'action_listen', correct?  (Y/n)

It’s Working correctly

Why the bot don’t respond “Hello wolrd !” ?

Why the bot don’t respond “Hello wolrd !” ?

Use Interactive Learning and set by using rasa interactive cmd and set your intent to your custom action

rasa interactive is the right way

It doesn’t working… I opened new topic that resume this topic better :

This is because, you have missed the import → from rasa_sdk.executor import CollectingDispatcher.

I have tested it and it’s working with no issues.

The problem is that, you have to import the default package/library which is available in actions.py itself. Then only the dispatcher works.

1 Like