Setting multiple slots in custom action

I’m having trouble setting slots in customactions

In some custom actions I would like to set multiple slots depending on the value of other slots. For example I have a time slot which is filled through duckling and I would like to fill two separate hour and date slots.

Looking at the medicare locator, slots are set using the SlotSet function return [SlotSet("facility_address", address)] when returning the customaction.

How would I go for updating multiple slots?

an array of SlotSet causes this error: action_server_1 | ValueError: dictionary update sequence element #0 has length 4; 2 is required

an object like this return {"time": time,"time_confirmed": True} works.

Is this the correct way to update multiple slots or can I use SlotSet in the body of the function and then return []? Why should SlotSet be the output of the customaction?

thanks

Hi @laujen, returning a list of SlotSet events should work alright in Rasa 2.x as the docs say (I checked using 2.1.x a while ago). Which version of Rasa are you using? Could you also share (at least the relevant parts of) the action code that doesn’t work and maybe also some other parts of your config/domain/data if you want me to try to reproduce the error that you’re getting?

Hey @SamSthanks for the reply. This is the code I am using. I think it is related to using FormValidationAction

class ValidateChooseFieldAppointmentForm(FormValidationAction):

  def name(self) -> Text:
    return "validate_choose_field_appointment_form"
  
  def validate_field_to_modify(
        self,
        value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
      ) -> Dict[Text, Any]:
         
      return {'appointment_type': None, 'time': tracker.get_slot('time'), 'modifying': True}

At first I assumed it is related to the typing (-> Dict[Text, Any]) but even if I set it as -> List[Dict[Text,Any]] the error is still coming up.

I assumed FormValidationActions should only be used to set the slot values but maybe I’m wrong

Alright, I see what’s the problem.

So, there are differences based on whether your custom action extends Action or FormValidationAction. In the latter case, you should follow this example in the docs and indeed return a dictionary like you do, not a list of SlotSet events :slight_smile:

Note: no need to use type List for the return type. Dict[Text, Any] covers cases where the dictionary has multiple entries.