# When FollowupAction is specified, should all predicted event that has not been executed be reverted?

**URL:** <https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542>\
**Category:** Rasa Open Source\
**Created:** [December 14, 2018, 12:46am UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542 "2018-12-14T00:46:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [December 14, 2018, 12:46am UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/1 "2018-12-14T00:46:46Z")

</div>

In FormAction validation, I didn’t want to simply raise `ActionExecutionRejection` because you have to have good stories and intent data to bring user back to FormAction in case of entity extraction failure. So I added code like this in FormAction.validate

```auto
if not entities:
    failed_count = int(tracker.slots.get('failed_counter') or 0)
   if failed_count > 1:
       return [Restarted(), FollowupAction(name='show_menu')]

   dispatcher.utter_message(f"Sorry, I didn't get that. Let's try again. ")
   return [SlotSet('failed_counter', failed_count + 1)]

```

This allow user to make mistake but still ask same question without writing stories etc. Then after 2 failure, I wanted to show initial menu cause Bot just gave up and wanted user’s attention to what bot can do. This almost works perfectly except that `Restarted(), FollowupAction(name='show_menu')` happnes AFTER another form\_action is predicted. So at the end, user would see Bot message with template from `utter_ask_{my_slot}` Then immediately after that, it sees `show_menu` Action. I was wondering, if `FollowupAction` is detected, should tracker will revert any predicted yet not executed (emitted) event?

The below log shows when `if failed_count > 1`. I’ve annoted my opinion with line starts with `**`

```auto
[BOT] What is the race distance?
[USER INPUT] meh

2018-12-13 16:31:06 DEBUG rasa_core.tracker_store - Recreating tracker for id 'default'
2018-12-13 16:31:06 DEBUG rasa_core.processor - Received user message 'meh' with intent '{'name': None, 'confidence': 0.0}' and entities '[]'
2018-12-13 16:31:06 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 79 events

2018-12-13 16:31:06 DEBUG rasa_core.policies.memoization - Current tracker state [None, {}, {'prev_action_listen': 1.0, 'select_main_menu_item': 1.0, 'main_menu_0': 1.0, 'main_menu': 1.0}]
2018-12-13 16:31:06 DEBUG rasa_core.policies.memoization - There is a memorised next action '24'
2018-12-13 16:31:06 DEBUG rasa_core.policies.form_policy - There is an active form 'target_pace_form'
2018-12-13 16:31:07 DEBUG rasa_core.policies.fallback - NLU confidence 0.0 is lower than NLU threshold 0.2. Predicting fallback action: action_default_fallback
2018-12-13 16:31:07 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_FormPolicy
2018-12-13 16:31:07 DEBUG rasa_core.processor - Predicted next action 'target_pace_form' with prob 1.00.
2018-12-13 16:31:07 DEBUG rasa_core.actions.action - Calling action endpoint to run action 'target_pace_form'.

** SETTING FollowupAction BECAUSE I WNAT TO GET OUT OF FORM
2018-12-13 16:31:07 DEBUG rasa_core.processor - Action 'target_pace_form' ended with events '['AllSlotsReset()', 'Restarted()', 'FollowupAction(action: utter_show_menu)', 'SlotSet(key: requested_slot, value: distance_to_run)']'
** OH NO, I DON'T WANT THIS EVENT TO BE EMIITED ANYMORE....
2018-12-13 16:31:07 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: What is the race distance?, data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'

** GOOD! FollowupAction IS WORKING!
2018-12-13 16:31:07 DEBUG rasa_core.processor - Predicted next action 'utter_show_menu' with prob 1.00.
2018-12-13 16:31:07 DEBUG rasa_core.processor - Action 'utter_show_menu' ended with events '[]'

```

---

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [December 17, 2018, 5:58pm UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/2 "2018-12-17T17:58:20Z")

</div>

Maybe above post is not clear enough so I like to re-state the what I expected and actual and hoping to hear the solution.

I have code like this from FormAction

```auto
if last_message == '/reset':
    dispatcher.utter_message("Alright, let's start all over.")
    from rasa_core_sdk.events import SlotSet, Form
    return [Form(None), SlotSet(REQUESTED_SLOT, None), FollowupAction(name='show_menu')]
    # return [Restarted(), FollowupAction(name='show_menu')] <== also tried this

```

What I expected to see is after user enter ‘/reset’

“Alright, let’s start all over.” then take action “show\_menu” however, between “Alright, let’s start all over.” and action show\_menu, rasa\_core inject IMO residual predicted action from FormAction.

Actual Bot Utterances:

```auto
Alright, let's start all over. <== this was dispatched from FormAction
What is the race distance? <== this is form FormAction `utter_ask_{slot_name}` which I think is residual
Select one of the options below. <== this is from Action show_menu

```

Expected Bot Utterances:

```auto
Alright, let's start all over. <== this was dispatched from FormAction
Select one of the options below. <== this is from Action show_menu

```

Here is what Log shows after user enter ‘/reset’…

```auto
2018-12-17 10:00:09 DEBUG rasa_core.processor - Received user message '/reset' with intent '{'name': 'reset', 'confidence': 1.0}' and entities '[]'

2018-12-17 10:01:23 DEBUG rasa_core.policies.form_policy - There is an active form 'target_pace_form'

2018-12-17 10:01:23 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_1_FormPolicy

2018-12-17 10:01:23 DEBUG rasa_core.processor - Predicted next action 'target_pace_form' with prob 1.00.

2018-12-17 10:01:23 DEBUG rasa_core.actions.action - Calling action endpoint to run action 'target_pace_form'.

2018-12-17 10:01:23 DEBUG rasa_core.processor - Action 'target_pace_form' ended with events '['Form(None)', 'SlotSet(key: requested_slot, value: None)', 'FollowupAction(action: show_menu)', 'SlotSet(key: requested_slot, value: distance_to_run)']'

2018-12-17 10:01:23 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: Alright, let's start all over., data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'

2018-12-17 10:01:23 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: What is the race distance?, data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'
2018-12-17 10:01:23 DEBUG rasa_core.processor - Predicted next action 'show_menu' with prob 1.00.
2018-12-17 10:01:23 DEBUG rasa_core.processor - Action 'show_menu' ended with events '[]'

```

Is this expected? or should predicted FormAction be reverted?

Thank you

---

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [December 18, 2018, 5:14pm UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/3 "2018-12-18T17:14:38Z")

</div>

Identified the cause and reported here: [Option to not to add Next Slot Events if event includes `Restarted` or maybe Form Deactivation · Issue #32 · RasaHQ/rasa\_core\_sdk · GitHub](https://github.com/RasaHQ/rasa_core_sdk/issues/32)

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [December 18, 2018, 5:29pm UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/4 "2018-12-18T17:29:43Z")

</div>

It looks like it behaves as expected. You see `utter_ask_{next_slot}` before followup action because it is emitted by `request_next_slot` method. I would suggest to override this method and add counter logic there instead of `validate`

---

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [December 18, 2018, 6:39pm UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/5 "2018-12-18T18:39:45Z")

</div>

I had the logic in `run` as this function gather this session’s `events` and I needed that info. I did end up adding the logic in `request_next_slot` but I had to find a way to gather this session’s `events` which is the info `run` method already have. So I set the class attributes when I want to get out of Form completely I set that attribute/flag then return None from `request_next_slot` if the flag is set to `true`. Thank you for your advice.

---

<div class="post-metadata">

**Author:** ![azizullah2017](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/azizullah2017/32/241_2.png) [@azizullah2017](https://forum.rasa.com/u/azizullah2017)\
**Post date:** [May 16, 2019, 7:32am UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/6 "2019-05-16T07:32:48Z")

</div>

request\_next\_slot @Ghostvv how can I override the this methond. If my slot name is “ask\_name”.

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [May 16, 2019, 8:02am UTC](https://forum.rasa.com/t/when-followupaction-is-specified-should-all-predicted-event-that-has-not-been-executed-be-reverted/3542/7 "2019-05-16T08:02:15Z")

</div>

just create a method in your custom form with the same name modified from original [rasa-sdk/forms.py at 0c55c8b55903b424a410d1421e581d4f9071f5a3 · RasaHQ/rasa-sdk · GitHub](https://github.com/RasaHQ/rasa-sdk/blob/0c55c8b55903b424a410d1421e581d4f9071f5a3/rasa_sdk/forms.py#L371) to do your logic
