Best way to handle Ramifications with slot filling

Imagine we want to ask for the slots:

  • time
  • number

Afterwards, if the number is > 10 we will ask for:

  • person

if number <= 10, we will ask for:

  • job

What is the best way to handle Ramifications with slot filling?

You probably want to look into using a FormAction, and using the required_slots method. From the FormAction tutorial

def required_slots(tracker):
    # type: () -> List[Text]
    """A list of required slots that the form has to fill"""

    if tracker.get_slot('cuisine') == 'greek':
        return ["cuisine", "num_people", "outdoor_seating",
             	"preferences", "feedback"]
        return ["cuisine", "num_people",
             	"preferences", "feedback"] 

This will allow the bot to conditionally ask for other slots based on the values of previous ones. (In your case, the number slot.)

Something like this, perhaps.

def required_slots(tracker):

    if int(tracker.get_slot('number')) <= 10:
        return ["time", "number", "person",...]
        return ["time", "number", "job",...] 
1 Like

Thank you! I’ll try that. Does this mean “required_slots” is called everytime a slot is captured?

Good question! The short answer is yes.

If we take a bit of a dive into the FormAction source code, we come across a function called request_next_slot, which is the method that handles the capturing of each slot.

    def request_next_slot(
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: Dict[Text, Any],
    ) -> Optional[List[EventType]]:
        """Request the next slot and utter template if needed,
            else return None"""

        for slot in self.required_slots(tracker):
            if self._should_request_slot(tracker, slot):
                logger.debug(f"Request next slot '{slot}'")
                dispatcher.utter_message(template=f"utter_ask_{slot}", **tracker.slots)
                return [SlotSet(REQUESTED_SLOT, slot)]

Note the following line:

 for slot in self.required_slots(tracker):

Which means that the FormAction loops over the list of required slots every time a new slot is ready to be filled.

HINT: You can override this method in your custom FormAction to modify the way your Form asks for each slot. Maybe add in some buttons, a bit of customized text logic for each slot?


Thank you so much, that’s a big help!