Form Action utter_message not working

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

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

from rasa_sdk.forms import FormAction

class ActionHelloWorld(Action):

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

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

     dispatcher.utter_message("Hello World!")

     return []

class BalanceForm(FormAction):

def name(self):
    return "balance_form"

@staticmethod
def required_slots(tracker) -> List[Text]:
return["card_number"]

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


    dispatcher.utter_message("It's working!!!")
    return []

For the above python script, dispatcher.utter_message works for action_hello_world but not for FormAction in rasa shell. Very confused about why this is happening.

Hi @ria.pinjani

What does your debug log says ? Is the form action gets predicted as next action?

Your input -> check balance for 4000002485703167
2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Issuing ticket for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’. 2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Acquiring lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’. 2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Acquired lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’. 2020-11-29 15:15:42 DEBUG rasa.core.tracker_store - Creating a new tracker for id ‘6d722e5664ee4dc0a4be0ffbf28967c9’. 2020-11-29 15:15:42 DEBUG rasa.core.processor - Starting a new session for conversation ID ‘6d722e5664ee4dc0a4be0ffbf28967c9’. 2020-11-29 15:15:42 DEBUG rasa.core.processor - Action ‘action_session_start’ ended with events ‘[<rasa.shared.core.events.SessionStarted object at 0x7ff8bb074518>, <rasa.shared.core.events.ActionExecuted object at 0x7ff8bb0744e0>]’. 2020-11-29 15:15:42 DEBUG rasa.core.processor - Current slot values: amount_of_money: None card_number: None currency: None person: None requested_slot: None 2020-11-29 15:15:43 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: faq 2020-11-29 15:15:43 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: chitchat 2020-11-29 15:15:43 DEBUG rasa.core.processor - Received user message ‘check balance for 4000002485703167’ with intent ‘{‘id’: -164258592526541612, ‘name’: ‘check_balance’, ‘confidence’: 0.9976837635040283}’ and entities ‘[{‘entity’: ‘card_number’, ‘start’: 18, ‘end’: 34, ‘confidence_entity’: 0.7931957840919495, ‘value’: ‘4000002485703167’, ‘extractor’: ‘DIETClassifier’}]’ 2020-11-29 15:15:43 DEBUG rasa.core.processor - Current slot values: amount_of_money: None card_number: 4000002485703167 currency: None person: None requested_slot: None 2020-11-29 15:15:43 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 5 events. 2020-11-29 15:15:43 DEBUG rasa.core.policies.rule_policy - Current tracker state: [{}, {‘user’: {‘intent’: ‘check_balance’, ‘entities’: (‘card_number’,)}, ‘prev_action’: {‘action_name’: ‘action_listen’}}] 2020-11-29 15:15:43 DEBUG rasa.core.policies.rule_policy - There is no applicable rule. 2020-11-29 15:15:43 DEBUG rasa.core.policies.memoization - Current tracker state [{}, {‘user’: {‘intent’: ‘check_balance’, ‘entities’: (‘card_number’,)}, ‘prev_action’: {‘action_name’: ‘action_listen’}}] 2020-11-29 15:15:43 DEBUG rasa.core.policies.memoization - There is no memorised next action 2020-11-29 15:15:43 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy 2020-11-29 15:15:43 DEBUG rasa.core.processor - Predicted next action ‘action_default_fallback’ with confidence 0.30. 2020-11-29 15:15:43 DEBUG rasa.core.processor - Action ‘action_default_fallback’ ended with events ‘[<rasa.shared.core.events.UserUtteranceReverted object at 0x7ff8bac9b160>]’. 2020-11-29 15:15:43 DEBUG rasa.core.processor - Current slot values: amount_of_money: None card_number: None currency: None person: None requested_slot: None 2020-11-29 15:15:43 DEBUG rasa.core.processor - Predicted next action ‘action_listen’ with confidence 1.00. 2020-11-29 15:15:43 DEBUG rasa.core.processor - Action ‘action_listen’ ended with events ‘[]’. 2020-11-29 15:15:43 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’. Your input ->

No it’s not i believe.

This is my stories.md file;

greet

  • greet
    • utter_greet
    • utter_help

happy path

  • greet
    • utter_greet
    • utter_help
  • mood_great
    • utter_happy

sad path 1

  • greet
    • utter_greet
    • utter_help
  • mood_unhappy
    • utter_cheer_up
    • utter_did_that_help
  • affirm
    • utter_happy

sad path 2

  • greet
    • utter_greet
    • utter_help
  • mood_unhappy
    • utter_cheer_up
    • utter_did_that_help
  • deny
    • utter_goodbye

say goodbye

  • goodbye
    • utter_goodbye

bot challenge

  • bot_challenge
    • utter_iamabot

check balance

  • check_balance
    • balance_form
    • form{“name” : “balance_form”}
    • form{“name” : null}
  • affirm
    • utter_goodbye

greet & check balance

  • greet
    • utter_greet
    • utter_help
  • check_balance
    • balance_form
    • form{“name” : “balance_form”}
    • form{“name” : null}

check balance continue

  • greet
    • utter_greet
    • utter_help
  • check_balance
    • balance_form
    • form{“name”: “balance_form”}
  • out_of_scope
    • utter_ask_continue
  • affirm
    • balance_form
    • form{“name”: null}

check balance stop

  • greet
    • utter_greet
    • utter_help
  • check_balance
    • balance_form
    • form{“name”: “balance_form”}
  • out_of_scope
    • utter_ask_continue
  • deny
    • action_deactivate_form
    • form{“name”: null}
    • utter_goodbye

transfer money

  • transfer_money
    • transfer_form
    • form{“name” : “transfer_form”}
    • form{“name” : null}
    • utter_transfer_completed
  • affirm
    • utter_goodbye

greet, check balance and transfer money

  • greet
    • utter_greet
    • utter_help
  • check_balance
    • balance_form
    • form{“name” : “balance_form”}
    • form{“name” : null}
  • transfer_money
    • transfer_form
    • form{“name” : “transfer_form”}
    • form{“name” : null}
    • utter_transfer_completed
  • affirm
    • utter_goodbye

hello world

  • hello_world
    • action_hello_world

Hi @ria.pinjani

I could not see your form action getting predicted. Your stories also looks fine.

Have you included form action policy in your config ? I could see you haven’t intended return statement line for static method in action.py. Doesn’t it throw error?

Yeah i fixed the indentation so thats not the issue.

I used the RulePolicy is my config file as mentioned here (end of page) - Policies

The docs you referred are for version 2.x Which rasa version are you using ?

Rasa Version : 2.0.2 Rasa SDK Version : 2.1.1 Rasa X Version : 0.33.2 Python Version : 3.6.10

Since your version is 2.x, Can you update the stories to latest format as in yaml

Also share your domain file content

domain.yml (2.9 KB)

Hi @ria.pinjani

Domain.yml looks good. Did you got chance to upgrade your stories to latest format stories.yml

I did - it still does not work.

stories_converted.yml (2.6 KB)

Hi @ria.pinjani,

I just noticed another error in your actions.py Since your version is 2.x, Please make the below changes as well in your form action class.

class BalanceForm(FormAction): to class BalanceForm(Action):

def submit to def run

your stories looks good. Retrain your model & make the above updates to your actions file.

Let me know if it works.

It still does not seem to predict balance form in rasa shell. I don’t understand whats happening.

This is the updated project if it helps - GitHub - riapinjani/rasa_demo

Thanks for all your help!!

Hi @ria.pinjani

I have fixed the code and its available here GitHub - rajaduraisingam/rasa_demo

Main issue is demo bot was developed in 1.x version but you have been trying that in 2.x . There were lot of changes happened since 1.x and hence it was throwing errors.

Have a look at the files to understand the flow. r1

In the above screenshot, if you enter the card number it will execute the action successfully.

r3

However, if we don’t specify the card number, it will ask the card number. After providing the card number, it says Bye which requires small fix which you can take it forward.

1 Like

Thanks! it worked now