Rasa story not followed correctly when forms are used

Hi I am using Rasa 2.x

this is my story:

- story: apply leave + affirm
  steps:
    - intent: apply_leave
    - action: action_apply_leave_slots_check
    - action: apply_leave_form
    - active_loop: apply_leave_form
    - slot_was_set:
      - requested_slot: fromDate
    - slot_was_set:
      - requested_slot: toDate
    - slot_was_set:
      - requested_slot: lvType
    - action: action_deactivate_loop
    - active_loop: null
    - slot_was_set:
      - requested_slot: null  
    - action: action_display_leave_details
    - intent: affirm
    - action: action_apply_leave  
    - action: restart_conversation  

Now after form is deactivated and all required slots are filled it does not execute action_display_leave_details instead it sometimes display restart_conversation or action listen.

What to do ?

I’d suggest writing a more simple story/rule first

Hi @ChrisRahme thanksfor your reply.

the motive of this story is that user asks to apply for leave, the bot will take required info for leave and then display leave info entered by user.

How can I break this down? this is already very simple story. Thanks

Did you pass the utterance or display leave details in your action_display_leave_details?

I’d suggest please first check till here that you able to get the result or not and then provide the button payload for the affirm or deny and then for the new fresh process for the leave.

hi @nik202 Yes I have an utterence so that I know that

  • action: action_display_leave_details is triggered.

I am able to get results till form is deactivated not after that. Am I doing anything wrong??

@NIkhilBhaskar Did you checked with rasa interactive what is happening? OR can you share some debugs or any error if you getting? It’s hard for me to comment.

You should start by reading the forms page. You shouldn’t be using requested_slot in this manner in a story - control the flow with the form required_slots and form validation.

Your story should look more like this:

- story: apply leave + affirm
  steps:
    - intent: apply_leave
    - action: apply_leave_form
    - active_loop: apply_leave_form
    - active_loop: null
    - action: action_apply_leave  
    - action: restart_conversation  # why do this?  you should reset slots in action_apply_leave

you can ignore restart_conversation action

But there is a serious problem in rasa 2.x that it does not follow the actions after a form is deactivated

The prediction is not coming as per the story written

The debug output will give you the details on how the dialog prediction is being made. It’s most likely an issue with your stories. Can you share your bot repo?

I can’t share the repo it’s a private repo, I have worked a way around thanks foryour help

@NIkhilBhaskar I hope you don’t mind to share the solution with us. Good Luck with your project.

Hi @NIkhilBhaskar ! Could you please share with us the solution that you had done to solve your problem? It’d be of huge help. Thank you.

Yeah Sure @muzzammil

this is my current story

- story: apply leave form, for all stories dummySlot is to get everything working it's value doesn't matter
  steps:
    - intent: apply_leave
    - action: action_apply_leave_slots_check
    - action: apply_leave_form
    - active_loop: apply_leave_form
    - slot_was_set:
      - requested_slot: fromDate
    - slot_was_set:
      - requested_slot: toDate
    - slot_was_set:
      - requested_slot: whichHalf
    - slot_was_set:
      - requested_slot: leave_reason
    - slot_was_set:
      - requested_slot: dummySlot
    - action: action_deactivate_loop
    - active_loop: null
    - slot_was_set:
      - requested_slot: null  
      

- story: apply leave action
  steps:
    - intent: trigger_apply_leave_action
    - action: action_apply_leave   

i have changed some slot names but all in all it is same story(changing slot names is nothing to do with actual solution)

The work around I found was, after you have asked all the questions from user and gathered the required information in slots, you request for a dummy slot as given in story and in action_ask_dummySlot you do this

return [
                ActionExecuted('action_listen'),
                UserUttered(
                    text = 'yessss',
                    parse_data = {
                        'id': 123456789,
                        'name': 'affirm',
                        'confidence': 1
                    },
                    timestamp = int(time.time()),
                    input_channel = tracker.get_latest_input_channel()
                 ),
        ]

and in validate portion you simply return as you always do

then all my data goes to my frontend code via webhooks and when user clicks on apply leave button then /trigger_apply_leave_action is triggered with 100% confidence and then action_apply_leave executes.

I apologize for this rusty answer I don’t remember it all together how I did it as it has been 2 years and now I am different tech stack but whatever I could understand from the code i have explained it here

Hope It helps!!

1 Like

This is great! Thank you so much @NIkhilBhaskar