[HELP] TwoStageFallbackPolicy: do not revert slot filling after affirmation

Hi,

rasa-core==0.13.1

I am using the TwoStageFallbackPolicy. Within the action ‘action_default_ask_affirmation’, I have a button for affirmation with the payload containing an intent and entities from a user message that has to be affirmed, e.g., {'title': 'Yes', 'payload': '/inform{"location":"berlin"}'}

Let’s say I have a slot ‘location’ that is filled with the value of the corresponding entity.

However, when a user affirms, ‘action_revert_fallback_events’ reverts not only fallback events but also the filling of the slot “location”. So what I have after affirmation is: intent=inform, entity_location=berlin, slot_location=None.

How can I prevent the slot filling to be reverted after affirmation?

Hi again, It looks like I am the only one with this problem…

Is there any chance to get it solved without modifying the TwoStageFallbackPolicy?

Thanks in advance, Lily

@liliya.avdiyenko Sorry for replying so late, but that’s actually a bug you have discovered! Thanks a lot! I created a bug for that here: TwoStageFallbackPolicy: Set slot for affirmations with entities · Issue #3281 · RasaHQ/rasa · GitHub

Hi @Tobias_Wochinger , Thanks for your reply! I am glad that it will be fixed in one of the next versions and I won’t have to use my custom workaround anymore.

@liliya.avdiyenko What is your workaround? I’m running into the same problem

Hi @rbossie,

I had to add the following modifications to _run_action() method in rasa_core.processor.MessageProcessor

def _run_action(self, action, tracker, dispatcher, policy=None,
                confidence=None):
    # events and return values are used to update
    # the tracker state after an action has been taken
    try:
        events = action.run(dispatcher, tracker, self.domain)
        
        # custom code starts here
        # after ACTION_REVERT_FALLBACK_EVENTS_NAME,
        # fill slots from entities of the last user message
        if action.name() == ACTION_REVERT_FALLBACK_EVENTS_NAME:
            logger.debug('Filling slots after {} if necessary'
                         .format(ACTION_REVERT_FALLBACK_EVENTS_NAME))
            last_user_event = tracker.get_last_event_for(UserUttered)
            for e in self.domain.slots_for_entities(last_user_event.parse_data["entities"]):
                events.append(e)

           # custom code ends here
            except ActionExecutionRejection:
                 .....

So at the end I have a custom Agent (rasa_core.agent.Agent) that uses a custom MessageProcessor where the _run_action() method is overwritten as shown above.

I don’t know if it is the best way to solve the problem. But it works :slight_smile: at least until the official fix will be released.

@rbossie you can have a look at TwoStageFallbackPolicy: Set slot for affirmations with entities · Issue #3281 · RasaHQ/rasa · GitHub where another solution is suggested.

@liliya.avdiyenko I used your workaround, seems to work fine. Thanks!