How to delete or undo the last chat or slot event from tracker

I am using Rasa SDK and created manual agent. So using handle_message I predict the response and if response intent is out_of_scope or low confidence then I ignore the Rasa response and predict the response using other AI models.

Now the response that I ignored can open the slot, so my flow is disturbed, As i ignored this low confidence response, but next queries can act according to the opened slot.

So from tracker, I manually set the value to None

agent = rasaBots[botRequest.clientId]
tracker = agent.tracker_store.retrieve(botRequest.senderId)
requestedSlot = tracker.slots['requested_slot']
requestedSlot.value = None

and tried even

requestedSlot.reset()

but this is not working, on next call still the slot is open

You can reset the slot by sending a SlotSet('slot_name', None) event from the SDK. You might also be interested in UserUtteranceReverted events. Generally, this guide for fallbacks and human handoffs should be useful.

@j.mosig thanks, I tried SlotSet SlotSet is not working

tracker = agent.tracker_store.retrieve(botRequest.senderId)
requestedSlot = tracker.slots['requested_slot']
if requestedSlot and requestedSlot.value:
    tracker._set_slot(requestedSlot.value, None)

By this mean i thought it will close the slot, but for next query still the slot is open

I mean a custom action who’s run method returns

return [SlotSet("name_of_your_slot", None)]

This should work for any regular slot. It looks, though, as if you want to set the special requested_slot slot, which is used internally by Rasa forms. To reset this, it is better to use the action_deactivate_loop, as described here.