Skip to main content

agentchat.groupchat

NoEligibleSpeakerException

class NoEligibleSpeakerException(Exception)

Exception raised for early termination of a GroupChat.

GroupChat

@dataclass
class GroupChat()

(In preview) A group chat class that contains the following data fields:

  • agents: a list of participating agents.

  • messages: a list of messages in the group chat.

  • max_round: the maximum number of rounds.

  • admin_name: the name of the admin agent if there is one. Default is "Admin". KeyBoardInterrupt will make the admin agent take over.

  • func_call_filter: whether to enforce function call filter. Default is True. When set to True and when a message is a function call suggestion, the next speaker will be chosen from an agent which contains the corresponding function name in its function_map.

  • speaker_selection_method: the method for selecting the next speaker. Default is "auto". Could be any of the following (case insensitive), will raise ValueError if not recognized:

  • "auto": the next speaker is selected automatically by LLM.

  • "manual": the next speaker is selected manually by user input.

  • "random": the next speaker is selected randomly.

  • "round_robin": the next speaker is selected in a round robin fashion, i.e., iterating in the same order as provided in agents.

  • allow_repeat_speaker: whether to allow the same speaker to speak consecutively. Default is True, in which case all speakers are allowed to speak consecutively. If allow_repeat_speaker is a list of Agents, then only those listed agents are allowed to repeat. If set to False, then no speakers are allowed to repeat. allow_repeat_speaker and allowed_or_disallowed_speaker_transitions are mutually exclusive.

  • allowed_or_disallowed_speaker_transitions: dict. The keys are source agents, and the values are agents that the key agent can/can't transit to, depending on speaker_transitions_type. Default is None, which means all agents can transit to all other agents. allow_repeat_speaker and allowed_or_disallowed_speaker_transitions are mutually exclusive.

  • speaker_transitions_type: whether the speaker_transitions_type is a dictionary containing lists of allowed agents or disallowed agents. "allowed" means the allowed_or_disallowed_speaker_transitions is a dictionary containing lists of allowed agents. If set to "disallowed", then the allowed_or_disallowed_speaker_transitions is a dictionary containing lists of disallowed agents. Must be supplied if allowed_or_disallowed_speaker_transitions is not None.

  • enable_clear_history: enable possibility to clear history of messages for agents manually by providing "clear history" phrase in user prompt. This is experimental feature. See description of GroupChatManager.clear_agents_history function for more info.

agent_names

@property
def agent_names() -> List[str]

Return the names of the agents in the group chat.

reset

def reset()

Reset the group chat.

append

def append(message: Dict, speaker: Agent)

Append a message to the group chat. We cast the content to str here so that it can be managed by text-based model.

agent_by_name

def agent_by_name(name: str,
recursive: bool = False,
raise_on_name_conflict: bool = False) -> Optional[Agent]

Returns the agent with a given name. If recursive is True, it will search in nested teams.

nested_agents

def nested_agents() -> List[Agent]

Returns all agents in the group chat manager.

next_agent

def next_agent(agent: Agent, agents: Optional[List[Agent]] = None) -> Agent

Return the next agent in the list.

select_speaker_msg

def select_speaker_msg(agents: Optional[List[Agent]] = None) -> str

Return the system message for selecting the next speaker. This is always the first message in the context.

select_speaker_prompt

def select_speaker_prompt(agents: Optional[List[Agent]] = None) -> str

Return the floating system prompt selecting the next speaker. This is always the last message in the context.

manual_select_speaker

def manual_select_speaker(
agents: Optional[List[Agent]] = None) -> Union[Agent, None]

Manually select the next speaker.

random_select_speaker

def random_select_speaker(
agents: Optional[List[Agent]] = None) -> Union[Agent, None]

Randomly select the next speaker.

select_speaker

def select_speaker(last_speaker: Agent, selector: ConversableAgent) -> Agent

Select the next speaker.

a_select_speaker

async def a_select_speaker(last_speaker: Agent,
selector: ConversableAgent) -> Agent

Select the next speaker.

GroupChatManager

class GroupChatManager(ConversableAgent)

(In preview) A chat manager agent that can manage a group chat of multiple agents.

groupchat

@property
def groupchat() -> GroupChat

Returns the group chat managed by the group chat manager.

chat_messages_for_summary

def chat_messages_for_summary(agent: Agent) -> List[Dict]

The list of messages in the group chat as a conversation to summarize. The agent is ignored.

run_chat

def run_chat(messages: Optional[List[Dict]] = None,
sender: Optional[Agent] = None,
config: Optional[GroupChat] = None) -> Tuple[bool, Optional[str]]

Run a group chat.

a_run_chat

async def a_run_chat(messages: Optional[List[Dict]] = None,
sender: Optional[Agent] = None,
config: Optional[GroupChat] = None)

Run a group chat asynchronously.

clear_agents_history

def clear_agents_history(reply: str, groupchat: GroupChat) -> str

Clears history of messages for all agents or selected one. Can preserve selected number of last messages. That function is called when user manually provide "clear history" phrase in his reply. When "clear history" is provided, the history of messages for all agents is cleared. When "clear history <agent_name>" is provided, the history of messages for selected agent is cleared. When "clear history <nr_of_messages_to_preserve>" is provided, the history of messages for all agents is cleared except last <nr_of_messages_to_preserve> messages. When "clear history <agent_name> <nr_of_messages_to_preserve>" is provided, the history of messages for selected agent is cleared except last <nr_of_messages_to_preserve> messages. Phrase "clear history" and optional arguments are cut out from the reply before it passed to the chat.

Arguments:

  • reply str - Admin reply to analyse.
  • groupchat GroupChat - GroupChat object.