Handling unhappy form paths: getting slot value outside the form

I want to handle the following scenario:

User: Show me flowers                      # Triggers flowers_form that has a color slot
Bot:  Do you have any color preference?    # Ask for color slot. Bot expects user to answer with a color
User: What colors can I choose from?       # User deviates
Bot:  You can choose among red and blue.   # Bot handles deviation
      Which one do you prefer?                            
User: Red                                         
Bot:  Here you have red flowers.           # Go back to flowers_form

I manage to go out of the flowers_form and back again. The problem is filling in the color slot in a smooth way. How can I do this?

I found a solution. I use a custom validation action (like in the financial demo) to interrupt the flowers_form when the user deviates. Then I execute a secondary form (color_form) to get the value of the color slot. And I use a combination of a rule and a story to handle the flow between the flowers_form and the color_form.

- rule: handling deviation
  condition:
  - active_loop: flowers_form
  - slot_was_set:
    - requested_slot: color
  steps:
  - intent: what_available_colors
  - action: color_form


- story: handling deviation
  steps:
  - intent: show_me_flowers
  - action: flowers_form
  - active_loop: flowers_form
  - slot_was_set:
    - requested_slot: color
  - intent: what_available_colors
  - action: color_form
  - active_loop: color_form
  - active_loop: null  
  - slot_was_set:
    - requested_slot: null  
  - action: flowers_form
  - active_loop: flowers_form
  - active_loop: null  
  - slot_was_set:
    - requested_slot: null  
  - action: show_flowers

The problem was that I was only issuing an ActionExecutionRejected event in order to interrupt the flowers_form. In that case, the color_form is triggered and rasa tries to extract the color slot from the triggering intent (i.e., from what_available_colors). Extraction fails and the execution of color_form is rejected. If I also issue a LoopInterrupted event (in addition to ActionExecutionRejected), then rasa does not try to extract the color slot from the triggering intent and everything works fine.

The documentation of LoopInterrupted says: “Notifies form action whether or not to validate the user input.” I understand this now, in retrospect. But I must admit that I did not understood it the first time I read the documentation. The point is that it is form_1 that triggers the event and is interrupted, while the notification on validating the user input applies to an eventual form_2 that could be executed after interrupting form_1. Maybe the documentation could be made a bit more clear.

Hi Nicolas,

I just read what you experienced and I am wondering why you need both - a rule and a story both handling the deviation. As the whole rule is 100% integrated part of your story, why is it necessary ? Wouldn’t it work without that rule?

BR

Andre