Switch between two intents with two forms without losing entities

I am having a problem for more than a month now in switching between two intents.

I have this case: carSearch intent with carSearch_form and bookAppointment intent with bookAppointment_form

I want to allow user to switch between the two intents in the middle of one of them.

for example: the user is in bookAppointment intent when the next slot and the requested slot is phone_number … he can write i want to buy a car which trigger the carSearch intent and open the carSearch_form

I wrote two stories but each has it’s own problem

the first: the problem here is if the user didn’t provide any entities in the sentence the core gives a circuit breaker and failed to do anything i want to buy a Toyota works fine while I want to buy a car fails

## book appointment to car search switching
* bookAppointment
  - bookAppointment_form
    - form{"name": "bookAppointment_form"}
* carSearch
  - carSearch_form
    - form{"name": "carSearch_form"}
    - form{"name": null}
    - form{"name": null}
  - action_carSearch

the second: works fine in both sentences but forget any entities captured in the sentence like i want to buy a corolla the corolla is extracted from the nlu but never saved in the slots

## book appointment to car search switching
* bookAppointment
  - bookAppointment_form
    - form{"name": "bookAppointment_form"}
* carSearch
  - action_deactivate_form
  - carSearch_form
    - form{"name": "carSearch_form"}
    - form{"name": null}
    - form{"name": null}
  - action_carSearch

I am using rasa-core==0.13.2 and rasa-core-sdk==0.12.1

any suggestions here?

1 Like

@Juste can you help me here?

can you share you action form.

it’s a normal form calls as the example in validation …something like

class CarSearchForm(FormAction):
        def name(self):
            return "carSearch_form"
        @staticmethod
        def required_slots(tracker: Tracker) -> List[Text]:
            return ['make', 'model', .......]

class BookAppointmentForm(FormAction):
    def name(self):
        return "bookAppointment_form"
    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        return ['name', 'phone', .......]

i don’t think the problem is from the forms code …i think it’s in the stories

@akelad help is appreciated

@hossa95 I think there is problem in your action form.

    def slot_mappings(self):
        # type: () -> Dict[Text: Union[Dict, List[Dict]]]
        """A dictionary to map required slots to
            - an extracted entity
            - intent: value pairs
            - a whole message
            or a list of them, where a first match will be picked"""

        return {"cuisine": self.from_entity(entity="cuisine",
                                            not_intent="chitchat"),
                "num_people": [self.from_entity(entity="num_people",
                                                intent=["inform",
                                                        "request_restaurant"]),
                               self.from_entity(entity="number")],
                "outdoor_seating": [self.from_entity(entity="seating"),
                                    self.from_intent(intent='affirm',
                                                     value=True),
                                    self.from_intent(intent='deny',
                                                     value=False)],
                "preferences": [self.from_intent(intent='deny',
                                                 value="no additional "
                                                       "preferences"),
                                self.from_text(not_intent="affirm")],
                "feedback": [self.from_entity(entity="feedback"),
                             self.from_text()]}

Recheck your slot maping. what how you find the slot.

There might help you. Referenced: 1-

2-

the problem was in stories … here is how i wrote them

## book appointment to car search switching
* bookAppointment
  - bookAppointment_form
  - form{"name": "bookAppointment_form"}
* carSearch
  - form{"name": null}
  - slot{"requested_slot": null}
  - carSearch_form
  - form{"name": "carSearch_form"}
  - form{"name": null}
  - slot{"requested_slot": null}
  - action_carSearch

and from the form code i handled the case of no entities by SlotSet(slots, None)

1 Like