How to set multiple slots in custom action

I’m trying to set slots in a custom action and run the template but template does not have update slot values. I’ve tried multiple ways to get this approach working but failed. After updating the slots template does not get the latest values in slot and shows None.

class Call(Action):
def name(self):
    return "action_call_user"

def run(self, dispatcher, tracker, domain):
    user_type = tracker.get_slot("user_type")

    if user_type in ["Doctor", "dr." "doctor", "dr", "Dr.", "DOCTOR"]:
        tracker.slots['doctor_name'] = tracker.get_slot("given_name")
        tracker.slots['doctor_lastname'] = tracker.get_slot("given_lastname")

        print(tracker.slots['doctor_name'])
        print(tracker.slots['doctor_lastname'])
        dispatcher.utter_template("utter_navigate_call_doctor", tracker)
        # return [SlotSet("doctor_name", tracker.get_slot("given_name")),
        #         SlotSet("doctor_lastname", tracker.get_slot("given_lastname"))]
        return []
    elif user_type in ["patient", "PATIENT"]:
        tracker.slots['patient_name'] = tracker.get_slot("given_name")
        tracker.slots['patient_lastname'] = tracker.get_slot("given_lastname")

        print(tracker.slots['patient_name'])
        print(tracker.slots['patient_lastname'])
        dispatcher.utter_template("utter_navigate_call_patient", tracker)
        # return [SlotSet("patient_name", tracker.get_slot("given_name")),
        #         SlotSet("patient_lastname", tracker.get_slot("given_lastname"))]
        return []
    else:
        dispatcher.utter_template("utter_navigate_call_follow_up_user", tracker)

Although slot values are being set but template does not get the updated values.

Templates:

 utter_navigate_call_patient:
 - "Calling {user_type} {patient_name}."
 utter_navigate_call_doctor:
 - "Calling {user_type} {doctor_name}."

Output:

call patient Usman Sharif
2018-10-04 12:24:03 DEBUG    rasa_core.tracker_store  - Recreating tracker for id 'default'
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Received user message 'call patient Usman Sharif' with intent '{'name': 'navigate.call', 'confidence': 0.9449410438537598}' and entities '[{'start': 0, 'end': 4, 'value': 'call', 'entity': 'command', 'confidence': 0.9565597808990413, 'extractor': 'ner_crf'}, {'start': 5, 'end': 12, 'value': 'patient', 'entity': 'user_type', 'confidence': 0.9367968120048038, 'extractor': 'ner_crf'}, {'start': 13, 'end': 18, 'value': 'Usman', 'entity': 'given_name', 'confidence': 0.9641212606072291, 'extractor': 'ner_crf'}, {'start': 19, 'end': 25, 'value': 'Sharif', 'entity': 'given_lastname', 'confidence': 0.9144945934024098, 'extractor': 'ner_crf'}]'
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 26 events
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Current slot values: 
	command: call
	diastolic: None
	doctor_lastname: None
	doctor_name: None
	given_lastname: Sharif
	given_name: Usman
	head_length: None
	head_unit: None
	height_length: None
	height_unit: in
	navModule: None
	patient_lastname: None
	patient_name: None
	pulse_rate: None
	respiration_rate: None
	saturation_level: None
	systolic: None
	temperature_method: None
	temperature_unit: Celsius
	temperature_value: None
	user_type: patient
	vitModule: None
	waist_length: None
	waist_unit: in
	weight_unit: lbs
	weight_value: None
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - Current tracker state [{'slot_waist_unit_0': 1.0, 'entity_user_type': 1.0, 'prev_action_slot_reset': 1.0, 'entity_given_name': 1.0, 'entity_given_lastname': 1.0, 'intent_navigate.call': 1.0, 'slot_weight_unit_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_temperature_unit_0': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'prev_action_listen': 1.0, 'entity_given_name': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'entity_given_name': 1.0, 'prev_action_call_user': 1.0}, {'slot_waist_unit_0': 1.0, 'entity_user_type': 1.0, 'prev_action_slot_reset': 1.0, 'entity_given_name': 1.0, 'entity_given_lastname': 1.0, 'intent_navigate.call': 1.0, 'slot_weight_unit_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_temperature_unit_0': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'prev_action_listen': 1.0, 'entity_given_name': 1.0}]
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2018-10-04 12:24:03 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_2_KerasPolicy
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Predicted next action 'action_call_user' with prob 1.00.
2018-10-04 12:24:03 DEBUG    rasa_core.actions.action  - Calling action endpoint to run action 'action_call_user'.
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Action 'action_call_user' ended with events '[]'
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Bot utterance 'BotUttered(text: Calling patient None., data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - Current tracker state [{'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'prev_action_listen': 1.0, 'entity_given_name': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'entity_given_name': 1.0, 'prev_action_call_user': 1.0}, {'slot_waist_unit_0': 1.0, 'entity_user_type': 1.0, 'prev_action_slot_reset': 1.0, 'entity_given_name': 1.0, 'entity_given_lastname': 1.0, 'intent_navigate.call': 1.0, 'slot_weight_unit_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_temperature_unit_0': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'prev_action_listen': 1.0, 'entity_given_name': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'entity_given_name': 1.0, 'prev_action_call_user': 1.0}]
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
Calling patient None.
2018-10-04 12:24:03 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_2_KerasPolicy
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Predicted next action 'action_slot_reset' with prob 1.00.
2018-10-04 12:24:03 DEBUG    rasa_core.actions.action  - Calling action endpoint to run action 'action_slot_reset'.
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Action 'action_slot_reset' ended with events '['AllSlotsReset()']'
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - Current tracker state [{'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'entity_given_name': 1.0, 'prev_action_call_user': 1.0}, {'slot_waist_unit_0': 1.0, 'entity_user_type': 1.0, 'prev_action_slot_reset': 1.0, 'entity_given_name': 1.0, 'entity_given_lastname': 1.0, 'intent_navigate.call': 1.0, 'slot_weight_unit_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_temperature_unit_0': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'prev_action_listen': 1.0, 'entity_given_name': 1.0}, {'entity_user_type': 1.0, 'slot_user_type_0': 1.0, 'intent_navigate.call': 1.0, 'slot_given_name_0': 1.0, 'slot_command_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_waist_unit_0': 1.0, 'slot_temperature_unit_0': 1.0, 'slot_given_lastname_0': 1.0, 'entity_given_lastname': 1.0, 'slot_weight_unit_0': 1.0, 'entity_given_name': 1.0, 'prev_action_call_user': 1.0}, {'slot_waist_unit_0': 1.0, 'entity_user_type': 1.0, 'prev_action_slot_reset': 1.0, 'entity_given_name': 1.0, 'entity_given_lastname': 1.0, 'intent_navigate.call': 1.0, 'slot_weight_unit_0': 1.0, 'entity_command': 1.0, 'slot_height_unit_0': 1.0, 'slot_temperature_unit_0': 1.0}]
2018-10-04 12:24:03 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2018-10-04 12:24:03 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_2_KerasPolicy
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Predicted next action 'action_listen' with prob 1.00.
2018-10-04 12:24:03 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2018-10-04 12:24:03] "POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1" 200 189 0.162248
1 Like

Well where are you setting these slot values? Everything seems to be commented out?

tracker.slots['patient_name'] = tracker.get_slot("given_name")
tracker.slots['patient_lastname'] = tracker.get_slot("given_lastname")

Here slots are set. Also I’ve commented the other way to set slots but none is working.

The return function is the best way to do it. However, this means the slots will only get set after the action is executed, meaning the template won’t have access to these slots yet. So you should either utter the template in your stories, or create a new custom action to execute after the one that sets your slots

Hey, I am using rasa_core =0.11.5 and I tried to set slots in my action file using tracker.slots[ 'currency_code'] = API['response']['body'] but I am unable to set the slots. can you tell me which version of rasa_core you are using and do you know how to resolve this?

Translation: you can only set one slot per action function call. Correct?

No you can set multiple slots in an action, just return a list of slotset events

1 Like

Hey @akelad, if I set multiple slots in custom action, do I absolutely need to put all of them in my story ?

One of them is influencing my story, but the other one is just set to None and does not influence my story. Should I still put it in the story ?

Yes you should put them in the story

I have another issue that is " How slot is going to store multiple values" like User Query:" I want book banana fig and berry". so here i want to store 2 values(banana fig, berry). but my slot is only stores last value.

Hi @rishi454,

assuming that you have defined banana fig and berry as entities and extracting them as such, how about this nice composite entity module:

which allows you to define exactly that - as one entitiy thus stores your two values?

Is that what you were looking for?

Regards

yes, banana fig and berry an entity values. so how can I store into slots?

you can make your slots unfeaturized, and then setting them won’t affect your story.

Hi Julian

Can you please share if there is a roadmap for incorporating/adopting this feature into rasa?

Requesting since we were especially looking for the points 2 and 3 which Ben BeWe11 mentions in his blog relating to extractors like duckling

Thanks Cyril

Hi @cyrilthank,

I am on vacation until tomorrow and I am going to answer this and your other question asap after returning!

Regards Julian

sure @JulianGerhard your patiently well thought out replies are worth the wait :slight_smile:

Thank you

cyril

Hi Cyril,

after considering what you wrote I’d appreciate if you could describe a bit more detailed what you want to achieve. The composite entities are designed to model dependencies between entities (e.g. them to be linked together). @BeWe11 opened an Issue on that which might be interesting for you, in addition, @amn41 opened a draft PR with an alternative approach.

So to answer your question temporary: Yes, there is a roadmap but it seems to be on hold for the moment so I think it would be a good idea to describe your problem such that maybe we could help another way.

Regards Julian

1 Like

Thanks @JulianGerhard for your patient replies

I am wondering if this is best done this through our partnership relationship with rasa

Please advise how best we may leverage the current existing partnership relationship with rasa

Appreciate it if you could point to a contact in case that may help

Thanks

Hi @cyrilthank,

since I am not a Rasa employee I am afraid that I can’t answer this properly. However, writing @Juste could be a possible approach.

I think that linked entities / BERT pruning strategies are very interesting for the whole community so my preferred way would be that you give me an example of what you want to achieve exactly and then we try to figure it out!

Regards Julian

@Juste can you please advise how our organization may leverage the existing rasa partnership we have to work on this

requesting since there may be more involved in this like NDA etc…

Thanks

Cyril