Is there any way to set Slot by API not by action

Hi Folks,

I have a different requirement here. I want to set slots not by Action/Custom Action but want to set it by API.

I am using

rasa-core==0.13.8 rasa-core-sdk==0.12.2 rasa-nlu==0.14.4

Can anybody help me out?

Thanks

You can use the endpoint /conversations/<sender_id>/tracker/events. Here the link to the documentation: HTTP API

And here is an example request:

curl -X POST \
  'http://localhost:5005/conversations/default/tracker/events?include_events=NONE' \
  -H 'Content-Type: application/json' \
  -d '{"event":"slot","name":"<name-of-slot>","value":"<value-of-slot>","timestamp":0}'

Make sure to fill out <name-of-slot> and <value-of-slot> with proper values. The name of the slot should also be present in your domain file.

2 Likes

Thanks, @Tanja for your input. But I am still facing the same issue. It shows me that slot is set but when I called it in custom action it gives me None.

1 Like

Can you please explain in more detail what exactly you are doing:

  • What commands do you execute?
  • What is the request?
  • In which order are you executing the steps?

Thanks.

Hi @Tanja

What i exactly doing is, I hit the request given by you via postman and then i tried to access it on my custom action it gives me the None.

Thanks

I have some trouble reproducing the error. I have a simple bot, that has a slot called name and an action called action_greet. I get the value of slot name and utter Hello {name}! or just Hello! depending on whether the slot is set or not in that action.

I’m executing the following steps:

  1. Start the action server
python -m rasa_core_sdk.endpoint --actions actions
  1. Start the rasa server
python -m rasa_core.run --endpoint endpoints.yml --enable_api -d models/current/dialogue -u models/current/nlu -o out.log
  1. Set the slot via the API
curl -X POST \
  'http://localhost:5005/conversations/default/tracker/events?include_events=NONE' \
  -H 'Content-Type: application/json' \
  -d '{"event":"slot","name":"name","value":"Tanja","timestamp":0}'
  1. Trigger the action
curl -X POST \
  'http://localhost:5005/conversations/default/execute?include_events=AFTER_RESTART' \
  -H 'Content-Type: application/json' \
  -d '{"name":"action_greet"}'

The last request successfully returns the message Hello Tanja!. So the slot I set before, was used in the action action_greet.

What steps are you executing?

1 Like

Hello @Tanja, I’m working with RASA HTTP API, when I set slot by API the next action predicted was wrong, but in my local the next action predicted was correct. How can I fixe the order of my conversation (input user --> predict action --> execute action --> …) ?

@illi88 Can you please open a new thread for your question as your question is not related to the previous conversation but rather a complete new question. Thanks. Also please add some more information to your question, such as, what requests are you doing, what Rasa version are you using, otherwise it is hard to reproduce the problem you have.

@Tanja I had already posted the question with the title : " Wrong action predicted with RASA HTTP API ". I’ll add some updates about requests that i’m doing. The version of RASA i’m using is RASA 1.1.4

@Tanja I’m having the same problem with rasa 1.4.6 (I’m unable to upgrade to > 1.5.0 because of this bug: Loss of confidence in Rasa > 1.6.0 nlu (compared to 1.4.6) · Issue #5004 · RasaHQ/rasa · GitHub). Did you find out what was happening?

I have an action called show_profile that just utters the profile slot.

(from domain.yml)
  utter_profile:
  - text: "I am {profile}"

(from data/stories.md)
## show_profile
* show_profile
  - utter_profile

If I set the slot with /show_profile{"profile":"broker"}, Rasa starts responding correctly. If I set the slot with a call to the tracker, I keep getting fallback actions instead of conversation.

I have a slot called “Profile” (categorical), that can be “broker”, “standard” or “anon”.

Before sending any message to rest/webhook, I set the slot with this snippet:

#profile contains the string "broker"

headers = { 'Content-type':'application/json' }
payload = '{ "event": "slot", "name": "profile", "value": "' + profile + '", "timestamp":0 }'
r = requests.post(event_uri, data=payload.encode('utf-8'), headers=headers)

The problem is that the tracker gets completely lost and nearly everything calls the fallback action.

Here’s a log extract (I’m translating the intent names and text from portuguese):

call to tracker/events with profile "broker"
call to webhook with message "Hi":

2020-02-05 12:39:46 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.
2020-02-05 12:40:16 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'. 2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Received user message 'Hi' with intent '{'name': 'greeting', 'confidence': 0.9709830284118652}' and entities '[]'
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 376 events
2020-02-05 12:40:23 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'slot_user_name_0': 1.0, 'intent_greeting': 1.0, 'prev_action_listen': 1.0}]
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'intent_greeting': 1.0, 'prev_action_listen': 1.0}]
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-02-05 12:40:23 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.6).
2020-02-05 12:40:23 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_4_FallbackPolicy
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Predicted next action 'action_myfallback' with confidence 0.60.
2020-02-05 12:40:23 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_myfallback'.
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Action 'action_myfallback' ended with events '['BotUttered(text: Sorry, could you rephrase that?, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})', 'Form(None)', 'SlotSet(key: requested_slot, value: None)']'
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Current slot values:
         profile: broker
         user_name: Simon
2020-02-05 12:40:23 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'prev_action_myfallback': 1.0, 'slot_user_name_0': 1.0, 'intent_greeting': 1.0}]
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_action_myfallback': 1.0}]
2020-02-05 12:40:23 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-02-05 12:40:23 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'greeting'.
2020-02-05 12:40:23 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_4_FallbackPolicy
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-02-05 12:40:23 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2020-02-05 12:40:23 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.

call to rest/webhook with message /show_profile{"profile":"broker"} (without sending tracker/events):

2020-02-05 12:40:49 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.
2020-02-05 12:40:49 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Received user message '/show_profile{"profile":"broker"}' with intent '{'name': 'show_profile', 'confidence': 1.0}' and entities '[{'entity': 'profile', 'start': 13, 'end': 35, 'value': 'broker'}]'
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Current slot values:
        profile: broker
        user_name: Simon
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 385 events
2020-02-05 12:40:49 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'intent_show_profile': 1.0, 'slot_user_name_0': 1.0, 'prev_action_listen': 1.0, 'entity_profile': 1.0}]
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'intent_show_profile': 1.0, 'slot_user_name_0': 1.0, 'prev_action_listen': 1.0, 'entity_profile': 1.0}]
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-02-05 12:40:49 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.6).
2020-02-05 12:40:49 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_KerasPolicy
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Predicted next action 'utter_profile' with confidence 0.65.
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Action 'utter_profile' ended with events '['BotUttered(text: I am broker, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})']'
2020-02-05 12:40:49 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'prev_utter_profile': 1.0, 'intent_show_profile': 1.0, 'slot_user_name_0': 1.0, 'entity_profile': 1.0}]
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_utter_profile': 1.0}]
2020-02-05 12:40:49 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-02-05 12:40:49 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'show_profile'.
2020-02-05 12:40:49 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.6).
2020-02-05 12:40:49 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_KerasPolicy
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-02-05 12:40:49 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2020-02-05 12:40:49 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.

call to webhook with message "Hi":

2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Received user message 'Hi' with intent '{'name': 'greeting', 'confidence': 0.9690574407577515}' and entities '[]'
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 389 events
2020-02-05 12:41:08 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slot_profile_0': 1.0, 'slot_user_name_0': 1.0, 'intent_greeting': 1.0, 'prev_action_listen': 1.0}]
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'intent_greeting': 1.0, 'prev_action_listen': 1.0}]
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '20'
2020-02-05 12:41:08 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.6).
2020-02-05 12:41:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_1_AugmentedMemoizationPolicy
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Predicted next action 'action_greeting' with confidence 1.00.
2020-02-05 12:41:08 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'action_greeting'.
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Action 'action_greeting' ended with events '['BotUttered(text: Hi there, glad you're back. How can I help you?, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})']'
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Current slot values:
        profile: broker
        user_name: Simon
2020-02-05 12:41:08 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_action_greeting': 1.0, 'slot_profile_0': 1.0, 'slot_user_name_0': 1.0, 'intent_greeting': 1.0}]
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_action_greeting': 1.0, 'intent_greeting': 1.0}]
2020-02-05 12:41:08 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '0'
2020-02-05 12:41:08 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'greeting'.
2020-02-05 12:41:08 DEBUG    rasa.core.policies.fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.6).
2020-02-05 12:41:08 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_1_AugmentedMemoizationPolicy
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-02-05 12:41:08 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2020-02-05 12:41:08 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '413'.

With Rasa X 0.35 the correct endpoint is:

/conversations/default/events

instead of:

/conversations/default/tracker/events

(note the missing tracker part)

Hello, i am trying the same method you have wrote but it doesnt work with me, did it changed over the years i am using rasa 3.0

that’s the message i get when i POST

 "version": "3.0.0",
    "status": "failure",
    "message": "Failed to validate the events format. For more information about the format visit the docs. Error: 'user' was expected\n\nFailed validating 'const' in schema[0]['properties']['event']:\n    {'const': 'user'}\n\nOn instance['event']:\n    'slot'",
    "reason": "BadRequest",
    "details": {},
    "help": "https://rasa.com/docs/rasa/pages/http-api",
    "code": 400

Any updates on how to do this with Rasa 3.1.0?