Reruns after user input

I have an app where several agents discuss a topic. Iโ€™m trying to have a user that should be able to make inputs in the ongoing discussion but the app reruns whenever an input is made.
Iโ€™ve read about forms, session_state, experimental_fragments in the documentation but Iโ€™m stuck.

I would really appreciate if someone have any tips or tricks.

        simulator.inject(moderator_name, specified_topic)
        st.write(f"({moderator_name}): {specified_topic}")

        while n < max_iters - 1:
            role, message = simulator.step()

            # If the role is 'User', get input from the user
            if role == user:
                message = get_user_input()
                user.send() # Store the user's message

            # Display the message from the current speaker
            st.write(f"({role}): {message}")
            n += 1

            # After the user's turn, everyone else reacts
            if role == user:
                for agent in agents:
                    agent.receive(user, message)  # Agents receive the user's input
                role, message = simulator.step()  # Get a response from another agent
                st.write(f"({role}): {message}")  # Display the response
        n += 1