Hi, is there a way that rasa can ask for all unfilled slots together at once. Like for example, let’s say my use case is to collect some data from the user and have built a form for the same. I’m expecting 4 slots to be filled and the user gives 2 in the first utterance. How should I model the bot so that it can ask for all the unfilled slots in one go?
Look at Dynamic Form Behavior. It lets you write Python code to dynamically set the required slots.
You can use the domain
variable to list all the slots you have, then using tracker.get_slot(slot_name)
, if the slot is None
, you append it to the list of required slots.
I forgot the exact syntax to get the slots from the domain, you can do print(domain)
to check its structure (the output will appear in the action server terminal). Let’s say it’s domain['slots']
and your form’s name is my_form
, then your code would look something like that:
from rasa_sdk.forms import FormValidationAction
class ValidateMyForm(FormValidationAction):
def name(self):
return "validate_my_form"
async def required_slots(self, domain_slots, dispatcher, tracker, domain):
required = []
for slot in domain['slots']:
if tracker.get_slot(slot) is None:
required.append(slot)
return required
1 Like