Unable to understand the exception error for custom action

I’m still playing around with Rasa, so please let me know if I’m doing something very obviously wrong.

I’m trying out the use case where a user expresses an interest in one slot/entity but then in the conversation later, changes interest to another slot. Here’s the domain file that I’m trying to work with -

domain.yml

intents:
  - interested
  - switch_interest

entities:
  - foo

slots:
  foo:
    type: categorical
    values:
    - A
    - B
    - C

actions:
- utter_confirm_interest
- custom_switch_interest

templates:
  utter_confirm_interest:
  - text: "You are interested in {foo}"

I understand that simply using slots itself I should be able to update the slot through the conversation. But I wanted to use a custom action to update the slot and respond via the custom action (dispatcher).

Here’s my action.py: from future import absolute_import from future import division from future import unicode_literals

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

import requests

# Update slot for the alternative foo
class switchInterest(Action):
	def name(self):
		return 'custom_switch_interest'

	def run(self, dispatcher, tracker, domain):
		new_foo = tracker.get_slot('foo')
		response = """Okay, switching foo to {}.""".format(new_foo)
						
		dispatcher.utter_message(response)
		return [SlotSet('foo',new_foo)]

Upon getting to the custom action however, I’m getting the following error -

ERROR rasa.core.processor - Encountered an exception while running action 'custom_switch_interest'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

The reason I wanted to do this approach is for a later use case where as the business, I can suggest a “foo”: “bar” and the user would only need to say Yes/No for me to update the “foo” to “bar” via the same or through another custom action. Any thoughts on both these use cases would be greatly appreciated! Thanks in advance :slight_smile:

See the action logs for helpful information. It will show the Exception that led to the error message.

Edit: FYI, did you know about python’s f-strings? Relatively new feature

Simpler and easier readable than .format(…)

Edit2: Triple Quote strings are used for docstrings in python. Rather use single single- or double quotes for strings.

@IgNoRaNt23 Thanks for your reply! Could you share how to view action logs? When I run rasa run actions, it shows me the endpoint running as

2019-09-10 10:04:25 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
/usr/local/lib/python3.7/site-packages/rasa_core_sdk/__init__.py:12: UserWarning: The 'rasa_core_sdk' package has been renamed. You should change your imports to use 'rasa_sdk' instead.
  UserWarning,
2019-09-10 10:04:25 INFO     rasa_sdk.executor  - Registered function for 'custom_switch_interest'.
2019-09-10 10:04:25 INFO     rasa_sdk.endpoint  - Action endpoint is up and running. on ('0.0.0.0', 5055)

However, the endpoint that I had configured in endpoints.yml was

action_endpoint:
  url: "http://localhost:3000/rasa-test"

Could you help? Much appreciated. I’ll make the changes and use f-string and single quotes in the actions.py as you suggested.

Guess your problem is the wrong endpoint in that case. Anyway this is how I start my action server

rasa run actions \
    -vv \ #debug flag, gives lots of output
    -p $actions_port \ # in your case actions_port=3000
    --actions actions \
    > logs/actions.log 2>&1 &

And this is for the CLI

rasa shell \
    --model models/ \
    --endpoints endpoints.yml \
    --log-file logs/botrun.log \
    -vv \ #again debug flag
    -p $rasa_port

And this is endpoints.yml

action_endpoint:
url: http://localhost:$actions_port/webhook
1 Like

This is fantastic! Thank you so much Heiner S! It worked for me!

Also another question if you don’t mind.

When I tried rasa shell as you have in the CLI portion of your solution, upon entering the first user utterance, the shell quits and goes back to the command line.

I used rasa interactive to get the custom action working, but was just curious if I can use the regular rasa shell to work.

Strange, maybe look into the logfile (logs/botrun.log if you CPed everything) and see if you find any related messages

Will try this today and confirm. Thanks @IgNoRaNt23!