Braking story loop from custom action in Rasa 3.2

Hello everyone!

I’m working with Rasa version 3.2.1. I’m wondering how can I break the story loop, when user has listed all the sentences of a topic (a string array). Hopefully the following code will clarify my issue.

Stories:

stories:
  
- story: user wants to know bio of a named person
  steps:
  - intent: tell_me_about_person
    entities:
    - PERSON
  - action: action_fetch_person_bio
  - action: utter_select_topic
  - intent: topic_number
    entities:
    - NUMBER
  - action: action_show_topic
  - active_loop: null
  - action: utter_more_bio
  - intent: affirm_more
  - action: action_show_topic
  - active_loop: list_bio_form

- story: user wants to stop listing bio of a named person
  steps:
  - active_loop: null
  - action: utter_more_bio
  - intent: deny_more
  - active_loop: null

Actions.py:

class ActionShowTopic(Action):
    def name(self) -> Text:
        return "action_show_topic"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain) -> List[Dict[Text, Any]]:
        
        try:
            topic_nr_slot = int(tracker.get_slot("topic_nr_slot"))
        except:
            dispatcher.utter_message(text="Please make sure the number is in numerical form.")
            return []

        topic = tracker.get_slot("topic")

        try:
            count = int(tracker.get_slot("count"))
        except:
            return []


        dispatcher.utter_message(text=str(topic[topic_nr_slot][count]))
        
        count = count + 1
        
        if count == len(topic[topic_nr_slot]):
            #
            pass
        else:
            return [SlotSet("count",count)]

What I’m trying to do is to break the story loop when “count == len(topic[topic_nr_slot])”.

Thanks in advance!

I searched the forum more I find some kind of solution to my problem, that I can apply to achieve, what I’m after.

Because in the stories intent “deny_more” will break the story loop, this will break the loop too:

if count == len(topic[topic_nr_slot]):

            data = {

            "intent": {

              "name": "deny_more"

                }

            }

            return [

                ActionExecuted("action_listen"),

                UserUttered(text="/deny_more", parse_data=data),

                ]

        else:

            return [SlotSet("count",count)]

That is: From the actions.py is sent that “deny_more” intent and it will break the story loop.

If there is better solution to this, I would be happy to hear about it.