Execute only action_default_ask_rephrase in Two Stage Fallback Plicy

I am using Two-Stage-Fallback policy. However, my requirement is to just ask the user to ‘Rephrase’ rather than asking the user to confirm the intent ie I want to just execute action_default_ask_rephrase. I do not want to execute : action_default_ask_affirmation

User: I need to install software

Bot: I did not understand. Could you rephrase

User: I need to install rasa on my server

Bot: (If intent recognition happens / policies predict the action) Do xyz… (If not) Sorry I will route your query

Any help is much appreciated.

I think a simple Custom Fallback is more suitable to your requirements. Inside the custom action, you can get the older events with reversed(tracker.events[:-1]) and check if there was a previous fallback. If there was not, just utter_message asking to rephrase and return UserUtteranceReverted. If there was, you can route right there or return a FollowupAction.

Hi, I am trying what you just suggested. How can we check for a previous fallback with reversed(tracker.events[:-1]) ? When I check for that value I just see <list_reverseiterator object at 0x7fcffe4b2a90>

Sorry if I am missing something

No problem. Try to call a method from your custom fallback to check if the user is in a second fallback (consecutive or not). In your method, place something like:

for event in reversed(tracker.events[:-1]):
    
    if event.get('event') == 'action' and event.get('name') == 'action_custom_fallback':                  
        return True

return False
2 Likes

Hi, this is great. For my requirement, I need ask the user to rephrase if the user enters the fallback action in second conversation. For instance: This is the expected flow: User: I need to install software

Bot: I did not understand. Could you rephrase

User: I need to install rasa on my server

Bot: (If intent recognition happens / policies predict the action) Do xyz… (If not) Sorry I will route your query

User: I need to book a flight

Bot: Please rephrase

User: I need a flight to London

Bot: (If intent recognition happens / policies predict the action) Do xyz… (If not) Sorry I will route your query

But because the tracker.events has fallback policy previously, second time when ‘I need to book a flight’ instead of asking to rephrase the bot is directly routing it right there.

I did try to clear the list of tracker.events after every fallback policy. That does not work. Any help on this can be tackled?

Well, you can limit the routing behavior to consecutive fallbacks only. That is, “Sorry I will route your query” will only happen when the previous action was also a fallback, otherwise ask to rephrase.

When speaking we say previous, but the tracker has a lot of info between what the user sees, like action_listen. Take a look on how your conversation history is being saved, and try to identify what it looks like when you have two consecutive fallbacks. Then you will change the code I sent to catch this condition to route the query.

1 Like