# Custom two\_stage fallback

**URL:** <https://forum.rasa.com/t/custom-two-stage-fallback/50982>\
**Category:** Rasa Open Source\
**Created:** [January 30, 2022, 9:19am UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982 "2022-01-30T09:19:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZahraDehghani99](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zahradehghani99/32/17977_2.png) [@ZahraDehghani99](https://forum.rasa.com/u/ZahraDehghani99)\
**Post date:** [January 30, 2022, 9:19am UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/1 "2022-01-30T09:19:45Z")

</div>

Hi, I want to use the `Two_Stage Fallback` option in rasa, but I want to customize it in such a way that it doesn’t activate `action_default_ask_affirmation`. I want to have a similar process in my chatbot dialogue:

```auto
user: What is your name? (nlu_fallback)
chatbot: Please rephrase your message. (action_ask_rephrase)
user: What is your name? (nlu_fallback)
chatbot: I am passing you to a human. (action_default_fallback)

```

But in the rasa two\_stage fallback, in the beginning, the user is asked for affirmation. I want to deactivate ‘action\_default\_ask\_affirmation’ part. Is there any way to do this?

I appreciate any help.

---

<div class="post-metadata">

**Author:** ![SamS](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sams/32/3497_2.png) [@SamS](https://forum.rasa.com/u/SamS)\
**Post date:** [January 31, 2022, 10:35am UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/2 "2022-01-31T10:35:08Z")

</div>

Hey @ZahraDehghani99, I recommend overwriting the [default `action_two_stage_fallback` action](https://rasa.com/docs/rasa/default-actions#action_two_stage_fallback) with a [custom action](https://rasa.com/docs/action-server/sdk-actions) where you’ll re-use much of the [code present in the default implementation](https://github.com/RasaHQ/rasa/blob/6359be5509c7d87cd29c2ab5149bc45e843fea85/tests/core/actions/test_two_stage_fallback.py) but will adjust the logic to your needs. Let me know how it goes. As the [docs page for default actions](https://rasa.com/docs/rasa/default-actions) says: “You may want to customize these to personalize your assistant.” and it’s nothing to be afraid of 🙂

---

<div class="post-metadata">

**Author:** ![ZahraDehghani99](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zahradehghani99/32/17977_2.png) [@ZahraDehghani99](https://forum.rasa.com/u/ZahraDehghani99)\
**Post date:** [February 2, 2022, 1:25pm UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/3 "2022-02-02T13:25:54Z")

</div>

Hi @[SamS](http://forum.rasa.com/u/sams) thank you for your reply. where can I find the default implementation of `action_two_stage_fallback`?

I tried to overwrite `TwoStageFallbackAction` from rasa/core/actions/two\_stage\_fallback.py with a custom action, But it doesn’t have `run` method inside it.

I’m a bit confused. Can you please give me a more hint about what should I write in the run method of my custom action? 🙏

Should I change `TwoStageFallbackPolicy` from rasa/core/policies/two\_stage\_fallback.py?

Thank you so much.

---

<div class="post-metadata">

**Author:** ![ZahraDehghani99](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zahradehghani99/32/17977_2.png) [@ZahraDehghani99](https://forum.rasa.com/u/ZahraDehghani99)\
**Post date:** [February 4, 2022, 4:19pm UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/4 "2022-02-04T16:19:23Z")

</div>

I wrote a custom action for `action_two_stage_fallback` as follows and it worked as I expected.

```auto
class ActionTwoStageFallback(Action):
    def name(self) -> Text:
        return "action_two_stage_fallback"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: DomainDict):  

        last_action = get_last_utter_action(tracker) 
        last_intent = tracker.latest_message.get("intent", {}).get("name")

        if last_intent == "nlu_fallback":
            # first time this action executed. Ask for rephrase message
            if last_action!="action_two_stage_fallback":
                dispatcher.utter_message(text="Please rephrase your message.")

                return []

            # second time this action executed. Connect to human operator    
            else:   
                dispatcher.utter_message(text="I am passing you to a human")
                # pause the tracker so that the bot stops responding to user input
                return[UserUtteranceReverted(), ConversationPaused()]

```

I found implementation for `get_last_utter_action` in this [link](http://forum.rasa.com/t/getting-last-executed-action-not-action-listen/9580/2).

---

<div class="post-metadata">

**Author:** ![SamS](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sams/32/3497_2.png) [@SamS](https://forum.rasa.com/u/SamS)\
**Post date:** [February 8, 2022, 1:32pm UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/5 "2022-02-08T13:32:04Z")

</div>

@ZahraDehghani99 sorry for not responding earlier; I’m glad you figured it out!

The default `TwoStageFallbackAction` doesn’t have a `run` method but its `do` method has a similar role. In any case, the `run` method, in a cleanly written custom action, shouldn’t do much 🙂 Its role is mainly to be an interface to the outside world – to receive important arguments (the tracker, the dispatcher, etc.) and to delegate work to other helper methods of the custom action, which contain the actual logic. So, in general, to “translate” a default action from `rasa/core/actions` to a custom action, it should be enough to add a very minimalistic `run` method. Anyway, it’s great that you managed to solve it and I’m sure things will be easier for you from now on, as you seem to be comfortable with custom actions!

---

<div class="post-metadata">

**Author:** ![ZahraDehghani99](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zahradehghani99/32/17977_2.png) [@ZahraDehghani99](https://forum.rasa.com/u/ZahraDehghani99)\
**Post date:** [February 11, 2022, 6:35pm UTC](https://forum.rasa.com/t/custom-two-stage-fallback/50982/6 "2022-02-11T18:35:15Z")

</div>

@SamS Thank you so much 🙂
