From 24807be4c8d823d72b8e8c19660e92ef6882c3e4 Mon Sep 17 00:00:00 2001 From: afourney Date: Fri, 10 Nov 2023 16:54:25 -0800 Subject: [PATCH] Added warnings for some GroupChat misconfigurations and selection errors (#603) * Added warnings for some GroupChat misconfigurations and selection errors * Fixed formatting --- autogen/agentchat/groupchat.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index fd481632ed7..604eb5c209d 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -38,7 +38,7 @@ def reset(self): self.messages.clear() def agent_by_name(self, name: str) -> Agent: - """Find the next speaker based on the message.""" + """Returns the agent with a given name.""" return self.agents[self.agent_names.index(name)] def next_agent(self, agent: Agent, agents: List[Agent]) -> Agent: @@ -103,10 +103,20 @@ def select_speaker(self, last_speaker: Agent, selector: ConversableAgent): try: return self.agent_by_name(name) except ValueError: + logger.warning( + f"GroupChat select_speaker failed to resolve the next speaker's name. Speaker selection will default to the next speaker in the list. This is because the speaker selection OAI call returned:\n{name}" + ) return self.next_agent(last_speaker, agents) def _participant_roles(self): - return "\n".join([f"{agent.name}: {agent.system_message}" for agent in self.agents]) + roles = [] + for agent in self.agents: + if agent.system_message.strip() == "": + logger.warning( + f"The agent '{agent.name}' has an empty system_message, and may not work well with GroupChat." + ) + roles.append(f"{agent.name}: {agent.system_message}") + return "\n".join(roles) class GroupChatManager(ConversableAgent):