Skip to content

Commit

Permalink
Added warnings for some GroupChat misconfigurations and selection err…
Browse files Browse the repository at this point in the history
…ors (#603)

* Added warnings for some GroupChat misconfigurations and selection errors

* Fixed formatting
  • Loading branch information
afourney committed Nov 11, 2023
1 parent b1e69bf commit 24807be
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 24807be

Please sign in to comment.