Ask questions to user in random order and end conversation when a threshold is reached

Hi. I am developing a bot where user answers 1.with buttons (MCQ, yes/no questions) 2.free text.

There are 4 different categories and I have to find which category the user falls into depending on their answers.

I have written 40 total questions but I don’t want to ask the user these 40 questions every time.

I would like to know how to write story/rules in such a way that these questions are uttered to the user in a random order every time, and how to stop the questions when a certain threshold (threshold here is the least correct answers from user set by me for individual category) is reached.

Thanks

Welcome to the forum :slight_smile:

I would go with forms for that.

To ask the questions in a random order, you could do it inside the required_slots method of a Form Validation Action:

from rasa_sdk.forms import FormValidationAction
import random

class ValidateRestaurantForm(FormValidationAction):
    def name(self):
        return "validate_restaurant_form"

    async def required_slots(self, slots, dispatcher, tracker, domain):
        random.shuffle(slots)
        return slots

This will take the slots you defined for the form in the domain and shuffle them every time.

40 questions are a lot though. Maybe it would be better storing them in a database and querying it ever time.

Hello, I have the same issue, would you share your code with me ?

Hi @istabrak , random.shuffle(slots) works properly to shuffle the slots. But the downside I faced is, slot validation stops once the slots are shuffled and user input is directly stored as slot value bypassing conditions of FormValidation.