Deactivate a form loop when certain slot (bool) is filled, even if other slots are not filled?

I have a Boolean slot and i want to deactivate the form filling loop depending upon slot value

this is the rule i used, but it didn’t work

 story: Room Booking Unhappy Path
  steps:
  - intent: room_booking
  - action: hotel_booking_form
  - active_loop : hotel_booking_form
  - slot_was_set:
      - room_final: false
  - active_loop: null
  - action: utter_booking_cancelled

the below stroy works, but only if all the slots are filled

- story: Room Booking Happy Path
  steps:
  - intent: room_booking
  - action: hotel_booking_form
  - active_loop : hotel_booking_form
  - slot_was_set:
      - room_final: true
      - requested_slot: null
  - active_loop: null
  - action: utter_booking_done

Hello, the way I did it is by detecting an intent:

- story: User fills form and stops
  steps:
  - intent: room_booking
  - action: hotel_booking_form
  - active_loop: hotel_booking_form
  - intent: stop # or deny
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_booking_cancelled

Or, if you want use a slot, you can do:

- story: User fills form and stops
  steps:
  - intent: room_booking
  - action: hotel_booking_form
  - active_loop: hotel_booking_form
  - slot_was_set:
    - room_final: false
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_booking_cancelled

Or, using a slot, you can stop the form in the required_slots() method, you can return [] if tracket.get_slot('room_final') == False.

Or, using a slot, you can stop the form in the validate_room_final() method, you can return {'required_slot': None} if value == False.

2 Likes

may be the last method doesn’t work . got this error message

Tried to set non existent slot 'required_slot'. Make sure you added all your slots to your domain file

first solution also didn’t work for me, the slot room_final was set to false and TED predicted 'action_deactivate_loop but then it predicted fall_back instead of action utter_booking cancel

2021-08-22 17:20:59 DEBUG    rasa.core.policies.memoization  - Launch DeLorean...
2021-08-22 17:20:59 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'slots': {'room_inter': (1.0, 1.0)}}, {'slots': {'room_final': (1.0, 0.0)}, 'prev_action': {'action_name': 'hotel_booking_form'}}]
2021-08-22 17:20:59 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2021-08-22 17:20:59 DEBUG    rasa.core.policies.ted_policy  - TED predicted 'action_deactivate_loop' based on user intent.
2021-08-22 17:20:59 DEBUG    rasa.core.policies.rule_policy  - Current tracker state:
[state 0] slots: {'room_inter': (1.0, 1.0)}
[state 1] user intent: greet | previous action name: action_listen | slots: {'room_inter': (1.0, 1.0)}
[state 2] user intent: greet | previous action name: utter_greet | slots: {'room_inter': (1.0, 1.0)}
[state 3] user intent: room_booking | previous action name: action_listen | slots: {'room_inter': (1.0, 1.0)}
[state 4] user intent: room_booking | previous action name: hotel_booking_form | slots: {'room_final': (1.0, 0.0)}
2021-08-22 17:20:59 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.
2021-08-22 17:20:59 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_RulePolicy.
2021-08-22 17:20:59 DEBUG    rasa.core.processor  - Predicted next action 'action_default_fallback' with confidence 0.40.
2021-08-22 17:20:59 DEBUG    rasa.core.processor  - Policy prediction ended with events '[]'.
2021-08-22 17:20:59 DEBUG    rasa.core.processor  - Action 'action_default_fallback' ended with events '[BotUttered('I didn't quite understand that. Could you rephrase?', {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, {"utter_action": "utter_default"}, 1629633059.2635887), <rasa.shared.core.events.UserUtteranceReverted object at 0x7f64106a0e10>]'.

Sorry, I meant requested_slot not required_slot :slight_smile:

Dear @ChrisRahme , The first solution also doesn’t work either, I got this conflict error at the end of training InvalidRule: Contradicting rules or stories found :rotating_light:


- the prediction of the action 'action_deactivate_loop' in rule 'booking a room' is contradicting with rule(s) 'handling active loops and forms - hotel_booking_form - action_listen' which predicted action 'action_listen'.
Please update your stories and rules so that they don't contradict each other.

This is the only form related rule I have (i don’t have a story)

- rule: booking a room
  steps:
  - intent: room_booking
  - action: hotel_booking_form
  - active_loop: hotel_booking_form
  - slot_was_set:
    - room_final: false
  - action: action_deactivate_loop
  - active_loop: null
  - action: utter_booking_cancelled

You have a rule called “handling active loops and forms - hotel_booking_form - action_listen”, can you show it to me?

I have 0 stories and 3 rules, other 2 rules are greet and goodbye rules, its independent of the rule related to form booking

training completed successfully when put this steps in story instead of rules, still it isn’t resolve my issue of deactivating the loop on the basis of intent value.

When I use the above mentioned steps in story, TED policy predicts 'action_deactivate_loop, and Rule policy predicts ‘hotel_booking_form’. After reading this I realized TED prediction is not executed when there there is a rule policy prediction

Hi @ChrisRahme , I figured out why my rule were not working properly, I have set an initial value for a slot and the value of this slot changes during form filling depending upon the situations. When I didn’t set the initial value everything works fine, it sounds like a bug to me and if it’s not a bug i think it’s good to mention it on the documentation

detailed explanation: I use two slots to deactivate a form, room_inter(initial_value = True) and room_final room_inter = True ===> the user deactivates the form after filling all details room_inter = False ===> user deactivates the form in between form filling room_inter = None ===> User doesn’t confirm the entered details and deactivate the form after filling all details

I initialized room_inter with value True and use this ‘true’ state for happy path. I resolved my issue by not setting an initial value for room_inter and use the state ‘None’ for Happy path

again i would like to thank @ChrisRahme for his help and support

1 Like

Sorry, I missed you replies.

Glad you solved it! :slight_smile: