Skip to content

Commit 24807be

Browse files
authored
Added warnings for some GroupChat misconfigurations and selection errors (#603)
* Added warnings for some GroupChat misconfigurations and selection errors * Fixed formatting
1 parent b1e69bf commit 24807be

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

autogen/agentchat/groupchat.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def reset(self):
3838
self.messages.clear()
3939

4040
def agent_by_name(self, name: str) -> Agent:
41-
"""Find the next speaker based on the message."""
41+
"""Returns the agent with a given name."""
4242
return self.agents[self.agent_names.index(name)]
4343

4444
def next_agent(self, agent: Agent, agents: List[Agent]) -> Agent:
@@ -103,10 +103,20 @@ def select_speaker(self, last_speaker: Agent, selector: ConversableAgent):
103103
try:
104104
return self.agent_by_name(name)
105105
except ValueError:
106+
logger.warning(
107+
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}"
108+
)
106109
return self.next_agent(last_speaker, agents)
107110

108111
def _participant_roles(self):
109-
return "\n".join([f"{agent.name}: {agent.system_message}" for agent in self.agents])
112+
roles = []
113+
for agent in self.agents:
114+
if agent.system_message.strip() == "":
115+
logger.warning(
116+
f"The agent '{agent.name}' has an empty system_message, and may not work well with GroupChat."
117+
)
118+
roles.append(f"{agent.name}: {agent.system_message}")
119+
return "\n".join(roles)
110120

111121

112122
class GroupChatManager(ConversableAgent):

0 commit comments

Comments
 (0)