Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: GroupChatManager.a_run_chat does not handle NoEligibleSpeaker Exception #298

Closed
linmou opened this issue Dec 27, 2024 · 4 comments · May be fixed by #296
Closed

[Bug]: GroupChatManager.a_run_chat does not handle NoEligibleSpeaker Exception #298

linmou opened this issue Dec 27, 2024 · 4 comments · May be fixed by #296
Assignees
Labels
bug Something isn't working

Comments

@linmou
Copy link
Collaborator

linmou commented Dec 27, 2024

Describe the bug

According to the code in GroupChatManager.run_chat when GroupChat.select_speaker raise NoEligibleSpeaker , the groupchat will be terminated. This feature enables coders to define termination conditions in customized speaker_selection_method.

def run_chat(
        self,
        messages: Optional[list[dict]] = None,
        sender: Optional[Agent] = None,
        config: Optional[GroupChat] = None,
    ) -> tuple[bool, Optional[str]]:
        """Run a group chat."""
        
         # other codes before ...
       
        for i in range(groupchat.max_round):
            self._last_speaker = speaker
            groupchat.append(message, speaker)
            # broadcast the message to all agents except the speaker
            for agent in groupchat.agents:
                if agent != speaker:
                    self.send(message, agent, request_reply=False, silent=True)
            if self._is_termination_msg(message) or i == groupchat.max_round - 1:
                # The conversation is over or it's the last round
                break
            try:
                # select the next speaker
                speaker = groupchat.select_speaker(speaker, self)
                if not silent:
                    iostream = IOStream.get_default()
                    iostream.print(colored(f"\nNext speaker: {speaker.name}\n", "green"), flush=True)
                # let the speaker speak
                reply = speaker.generate_reply(sender=self)
            except KeyboardInterrupt:
                # let the admin agent speak if interrupted
                if groupchat.admin_name in groupchat.agent_names:
                    # admin agent is one of the participants
                    speaker = groupchat.agent_by_name(groupchat.admin_name)
                    reply = speaker.generate_reply(sender=self)
                else:
                    # admin agent is not found in the participants
                    raise
            except NoEligibleSpeaker:
                # No eligible speaker, terminate the conversation
                break

        # other codes after ...
        return True, None

However, it seems that GroupChatManager.a_run_chat do not have this feature.
I am not sure whether it is a feature or bug.

async def a_run_chat(
        self,
        messages: Optional[list[dict]] = None,
        sender: Optional[Agent] = None,
        config: Optional[GroupChat] = None,
    ):
        # other codes before ...
        for i in range(groupchat.max_round):
            groupchat.append(message, speaker)

            if self._is_termination_msg(message):
                # The conversation is over
                break

            # broadcast the message to all agents except the speaker
            for agent in groupchat.agents:
                if agent != speaker:
                    await self.a_send(message, agent, request_reply=False, silent=True)
            if i == groupchat.max_round - 1:
                # the last round
                break
            try:
                # select the next speaker
                speaker = await groupchat.a_select_speaker(speaker, self)
                # let the speaker speak
                reply = await speaker.a_generate_reply(sender=self)
            except KeyboardInterrupt:
                # let the admin agent speak if interrupted
                if groupchat.admin_name in groupchat.agent_names:
                    # admin agent is one of the participants
                    speaker = groupchat.agent_by_name(groupchat.admin_name)
                    reply = await speaker.a_generate_reply(sender=self)
                else:
                    # admin agent is not found in the participants
                    raise
           # It does not have the following exception handler
           #  except NoEligibleSpeaker:  
           #     break

            if reply is None:
                break

       # other codes after ...
      

Steps to reproduce

Define a speaker_selection_method returning None under some conditions. ( That should be a proper case when we try to define the termination condition

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

@linmou linmou added the bug Something isn't working label Dec 27, 2024
@marklysze
Copy link
Collaborator

Thanks @linmou, I have addressed this in my Telemetry Phase 1 code, if you need it more urgently then I'll create a new PR. Telemetry Phase 1 #296

@marklysze marklysze mentioned this issue Dec 27, 2024
8 tasks
@linmou
Copy link
Collaborator Author

linmou commented Dec 27, 2024

Thanks @linmou, I have addressed this in my Telemetry Phase 1 code, if you need it more urgently then I'll create a new PR. Telemetry Phase 1 #296

Not so urgent , I can change my code locally.

@marklysze
Copy link
Collaborator

I'm also addressing this in #315, as I think that will merge earlier than #296.

@marklysze
Copy link
Collaborator

#315 has merged, so we're good to go :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants