How do I setup TwoStageFallback

I have tried to follow the guide on Fallback and Human Handoff, but I couldnt manage to setup my TwoStageFallback. Currently when the NLU_threshold is not met, my chatbot just responds with utter_default. But I expect it to ask the user to rephrase their message. My files look like this :

domain.yml
responses:
    utter_out_of_scope:
      - text: Sorry, das ist out of scope
    utter_ask_rephrase:
        - text: Sorry, das habe ich nicht ganz verstanden. Kannst du das nochmal anders formulieren?
    utter_default:
        - text: Es tut mir leid, ich kann dir nicht weiterhelfen
....

config.yml

# The config recipe.
# https://rasa.com/docs/rasa/model-configuration/
recipe: default.v1

# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: de

pipeline:
  - name: SpacyNLP
    model: "de_core_news_lg"
  - name: SpacyTokenizer
  - name: SpacyFeaturizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: "word"
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
  - name: FallbackClassifier
    threshold: 0.45

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
  - name: MemoizationPolicy
  - name: RulePolicy
  - name: UnexpecTEDIntentPolicy
    max_history: 5
    epochs: 30
  - name: TEDPolicy
    max_history: 5
    epochs: 30
    constrain_similarities: true

rules.yml

version: "3.0"

rules:

- rule: Say goodbye anytime the user says goodbye
  steps:
  - intent: goodbye
  - action: utter_goodbye

- rule: Implementation of Two-Stage-Fallback
  steps:
  - intent: nlu_fallback
  - action: action_two_stage_fallback
  - active_loop: action_two_stage_fallback

- rule: out-of-scope
  steps:
  - intent: out_of_scope
  - action: utter_out_of_scope

How do I get the described dialog where the user is asked to rephrase his message twice?

I made this way: I created a slot to increment the number of fallback and action to read slot value

rules.yml

rules:
- rule:  fallback
  steps:
  - intent: nlu_fallback
  - action: custom_default_fallback

domain.yml

intents:
- nlu_fallback
- utter_ask_rephrase
- utter_goodbye

slots:
  number_fallback:
    type: text
    initial_value: '0'
    influence_conversation: false

my action

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.events import UserUtteranceReverted, SlotSet
from rasa_sdk.executor import CollectingDispatcher

class ActionCustomFallback(Action):
    """Executes the fallback action and goes back to the previous state
    of the dialogue"""

    def name(self) -> Text:
        return "custom_default_fallback"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        number_fallback = tracker.get_slot('number_fallback')
        number_fallback = int(number_fallback)

        if number_fallback > 1:
            dispatcher.utter_message(response="utter_goodbye")
            return [SlotSet('number_fallback', '0')]

        dispatcher.utter_message(response="utter_ask_rephrase")
        return [SlotSet('number_fallback', str(number_fallback+1))]
1 Like

is there really no other way to do it ? Does this just mean that the docs is outdated?

The other way is using rules how you made I tried to use rules method in the past (rasa 2.2.0) but the method not working very well because the some issue. Rasa team has fixed but i never tried more

Looking the Doc, i think your code is right. Maybe you can create the custom action for action_default_fallback

Reference: Fallback and Human Handoff