My Bot response is not as designed

Dear Team,

Can someone please help me fixing this.

By default, i am giving three choices for the user. Assume, user selected 1st option, and i am asking the user to provide his input. After this i am asking the user again to select the segment. And based on those inputs my python action able to execute and responding with correct answers. And again my bot is asking the user like “Anything Else” with Affirm and Deny.

When user hits deny, then i am seeing correct response.

when user clicks on Yes and bot asking the user with 3 choices again as designed.

But, if the user chooses the same 1st option/choice again, then the bot responding with the previous search response and ignoring the next choices which needs to be asked before it executing.

My Domain :

> slots:
>   userquery:
>     type: text
>     auto_fill: false
>     influence_conversation: false
>   segment:
>     type: text
>     auto_fill: false
>     influence_conversation: false
>   userfeedbacks:
>     type: text
>     auto_fill: false
>     influence_conversation: false

forms:
  document_form:
    required_slots:
      userquery:
        - type: from_entity
          entity: userquery
      segment:
        - type: from_intent
          intent: busegment
          value: Service Capsule
        - type: from_intent
          intent: historicalsegment
          value: Reuse

My Rules with forms:

rules:

  - rule: activate document search form

    steps:
      - intent: lookingfordocuments   # intent that triggers form activation
      - action: document_form      # run the form
      - active_loop: document_form # this form is active

  - rule: submit form
    condition:
    - active_loop: document_form   # this form must be active
    steps:
      - action: document_form      # run the form
      - active_loop: null            # the form is no longer active because it has been filled
      - slot_was_set:
        - requested_slot: null
      - action: action_submit
      - action: utter_anything_else

And my action.py

class ValidateDocumentSearchForm(Action): def name(self) → Text: return “document_form”

def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
    required_slots = ["userquery", "segment"]

    for slot_name in required_slots:
        if tracker.slots.get(slot_name) is None:
            # The slot is not filled yet. Request the user to fill this slot next.
            return [SlotSet("requested_slot", slot_name)]

    # All slots are filled.
    return [SlotSet("requested_slot", None)]

class ActionSubmit(Action):

def name(self) -> Text:
    return "action_submit"

def run(
        self,
        dispatcher,
        tracker: Tracker,
        domain: "DomainDict",
) -> List[Dict[Text, Any]]:

    query = tracker.get_slot("userquery")
    scope = tracker.get_slot("segment")
    
    ####Document Search/Lookup in solr ####
    url = ''
    
    search_response = requests.get(url, verify=False).text
    search_response = json.loads(search_response)
    
    for doc in search_response["response"]["docs"]: 
        print(doc["url"] + '\n' + doc["file"] + '\n' + doc["scope"])
    botsearchresponse = "The document you may be looking for is found under <b>Article</b>." + '\n' + '<a href="' + doc["url"] + '">' +doc["file"] + '</a>'
    dispatcher.utter_message(botsearchresponse)
    return []

Hi @nik202 could you pleasehelp me. I was unable to figure out a fix for this.

Hi @krkc,

Have you tried resetting all the slots before activating the form again? you could do it by creating a custom action and calling AllSlotsReset().

Hi @jupyterjazz Thanks for your response… and appreciate that. Yes you are correct.

Yes, I had fixed it yesterday by writing an action class as below and at the issue id you will see full in detailed.

class ActionResetAllSlots(Action):

def name(self):
    return "action_reset_all_slots"

def run(self, dispatcher, tracker, domain):
    return [AllSlotsReset()]

And i have been added it at the end of my form rule as below…

rules:
  - rule: activate document search form
    steps:
      - intent: lookingfordocuments   # intent that triggers form activation
      - action: document_form      # run the form
      - active_loop: document_form # this form is active

  - rule: submit form
    condition:
    - active_loop: document_form   # this form must be active
    steps:
      - action: document_form      # run the form
      - active_loop: null          # the form is no longer active because it has been filled
      - slot_was_set:
        - requested_slot: null     # All the required slots have been filled
      - action: action_submit
      - action: action_reset_all_slots

Also, registered the action in my domain.yml

Best Regards, Thanks