Bases: BaseModel
Represents a speaker selection result that will be returned to GroupChat._prepare_and_select_agents to determine the next speaker.
This class can return an Agent, a None to end the conversation, or a string for a speaker selection method.
terminate class-attribute
instance-attribute
agent_name class-attribute
instance-attribute
speaker_selection_method class-attribute
instance-attribute
speaker_selection_method = None
get_speaker_selection_result
get_speaker_selection_result(groupchat)
Get the speaker selection result. If None, the conversation will end.
Source code in autogen/agentchat/group/speaker_selection_result.py
| def get_speaker_selection_result(self, groupchat: "GroupChat") -> Optional[Union[Agent, str]]:
"""Get the speaker selection result. If None, the conversation will end."""
if self.agent_name is not None:
# Find the agent by name in the groupchat
for agent in groupchat.agents:
if agent.name == self.agent_name:
return agent
raise ValueError(f"Agent '{self.agent_name}' not found in groupchat.")
elif self.speaker_selection_method is not None:
return self.speaker_selection_method
elif self.terminate is not None and self.terminate:
return None
else:
raise ValueError(
"Unable to establish speaker selection result. No terminate, agent, or speaker selection method provided."
)
|