Manage unknow intent in the stories

Let say I need that after 3 times in a row that the intent is unknow, I want to take some custom action. Can I manage this on the stories? There is a label for an unknow intent so I can do something like?

  • unknow_intent
    • action_default_fallback
  • unknow_intent
    • action_default_fallback
  • unknow_intent
    • my_custom_action

This is how I achieve it. (well after the second try but you can change the script for third attempt) I use two slots, unsure_count and unsure_time.

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
from rasa_core_sdk.events import UserUtteranceReverted
import requests
import os
import time


class ActionUnsure(Action):
    def name(self):
        return "action_unsure"

    def run(self, dispatcher, tracker, domain):
        unsure_count = 0
        unsure_time = int(time.time())
        if tracker.get_slot("unsure_count"):
            unsure_count = int(tracker.get_slot("unsure_count"))
        if tracker.get_slot("unsure_time"):
            unsure_time = int(tracker.get_slot("unsure_time"))

        if (int(time.time()) - unsure_time) > 30:
            unsure_count = 0
            unsure_time = int(time.time())
        
        if unsure_count == 0:
            dispatcher.utter_template("utter_not_sure", tracker)
        elif unsure_count == 1:
            dispatcher.utter_template("utter_still_not_sure", tracker)
            # do some action like email a human or utter something           
            return[SlotSet("unsure_count", None), SlotSet("unsure_time", None), UserUtteranceReverted() ]

        unsure_count = unsure_count+1
        return [SlotSet("unsure_count", str(unsure_count)), SlotSet("unsure_time", str(unsure_time))]

My policies …

policies:
  - name: KerasPolicy
    epochs: 200
    max_history: 3
  - name: MemoizationPolicy
    max_history: 3
  - name: "FallbackPolicy"
    nlu_threshold: 0.2
    core_threshold: 0.1
    fallback_action_name: "action_unsure"
  - name: "FormPolicy"
1 Like

great, thank you!