GroupChat - AG2

GroupChat

``autogen.GroupChatdataclass[

GroupChat(agents, messages=list(), max_round=10, admin_name='Admin', func_call_filter=True, speaker_selection_method='auto', max_retries_for_selecting_speaker=2, allow_repeat_speaker=None, allowed_or_disallowed_speaker_transitions=None, speaker_transitions_type=None, enable_clear_history=False, send_introductions=False, select_speaker_message_template='You are in a role play game. The following roles are available:\n                {roles}.\n                Read the following conversation.\n                Then select the next role from {agentlist} to play. Only return the role.', select_speaker_prompt_template=SELECT_SPEAKER_PROMPT_TEMPLATE, select_speaker_auto_multiple_template='You provided more than one name in your text, please return just the name of the next speaker. To determine the speaker use these prioritised rules:\n    1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n    2. If it refers to the "next" speaker name, choose that name\n    3. Otherwise, choose the first provided speaker's name in the context\n    The names are case-sensitive and should not be abbreviated or changed.\n    Respond with ONLY the name of the speaker and DO NOT provide a reason.', select_speaker_auto_none_template='You didn\'t choose a speaker. As a reminder, to determine the speaker use these prioritised rules:\n    1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n    2. If it refers to the "next" speaker name, choose that name\n    3. Otherwise, choose the first provided speaker's name in the context\n    The names are case-sensitive and should not be abbreviated or changed.\n    The only names that are accepted are {agentlist}.\n    Respond with ONLY the name of the speaker and DO NOT provide a reason.', select_speaker_transform_messages=None, select_speaker_auto_verbose=False, select_speaker_auto_model_client_cls=None, select_speaker_auto_llm_config=None, role_for_select_speaker_messages='system', eligibility_policies=list())

A group chat class that contains the following data fields:

def custom_speaker_selection_func(
    last_speaker: Agent, groupchat: GroupChat
) -> Union[Agent, str, None]:
    ```
- max_retries_for_selecting_speaker: the maximum number of times the speaker selection requery process will run. If, during speaker selection, multiple agent names or no agent names are returned by the LLM as the next agent, it will be queried again up to the maximum number of times until a single agent is returned or it exhausts the maximum attempts. Applies only to "auto" speaker selection method. Default is 2.
- select_speaker_transform_messages: (optional) the message transformations to apply to the nested select speaker agent-to-agent chat messages. Takes a TransformMessages object, defaults to None and is only utilised when the speaker selection method is "auto".
- select_speaker_auto_verbose: whether to output the select speaker responses and selections. If set to True, the outputs from the two agents in the nested select speaker chat will be output, along with whether the responses were successful, or not, in selecting an agent. Applies only to "auto" speaker selection method.
- 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.
- send_introductions: send a round of introductions at the start of the group chat, so agents know who they can speak to (default: False)
- select_speaker_auto_model_client_cls: Custom model client class for the internal speaker select agent used during 'auto' speaker selection (optional)
- select_speaker_auto_llm_config: LLM config for the internal speaker select agent used during 'auto' speaker selection (optional)
- role_for_select_speaker_messages: sets the role name for speaker selection when in 'auto' mode, typically 'user' or 'system'. (default: 'system')
- eligibility_policies: list of :class:`AgentEligibilityPolicy` to filter candidate agents before speaker selection. All policies must return `True` for an agent to be considered eligible (AND semantics). Default is `[]` (no filtering).

### ``agents`instance-attribute`[

agents


### ``messages`class-attribute``instance-attribute`[

messages = field(default_factory=list)


### ``max_round`class-attribute``instance-attribute`[

max_round = 10


### ``admin_name`class-attribute``instance-attribute`[

admin_name = 'Admin'


### ``func_call_filter`class-attribute``instance-attribute`[

func_call_filter = True


### ``speaker_selection_method`class-attribute``instance-attribute`[

speaker_selection_method = 'auto'


### ``max_retries_for_selecting_speaker`class-attribute``instance-attribute`[

max_retries_for_selecting_speaker = 2


### ``allow_repeat_speaker`class-attribute``instance-attribute`[

allow_repeat_speaker = None


### ``allowed_or_disallowed_speaker_transitions`class-attribute``instance-attribute`[

allowed_or_disallowed_speaker_transitions = None


### ``speaker_transitions_type`class-attribute``instance-attribute`[

speaker_transitions_type = None


### ``enable_clear_history`class-attribute``instance-attribute`[

enable_clear_history = False


### ``send_introductions`class-attribute``instance-attribute`[

send_introductions = False


### ``select_speaker_message_template`class-attribute``instance-attribute`[

select_speaker_message_template = 'You are in a role play game. The following roles are available:\n {roles}.\n Read the following conversation.\n Then select the next role from {agentlist} to play. Only return the role.'


### ``select_speaker_prompt_template`class-attribute``instance-attribute`[

select_speaker_prompt_template = SELECT_SPEAKER_PROMPT_TEMPLATE


### ``select_speaker_auto_multiple_template`class-attribute``instance-attribute`[

select_speaker_auto_multiple_template = 'You provided more than one name in your text, please return just the name of the next speaker. To determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.'


### ``select_speaker_auto_none_template`class-attribute``instance-attribute`[

select_speaker_auto_none_template = 'You didn't choose a speaker. As a reminder, to determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n The only names that are accepted are {agentlist}.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.'


### ``select_speaker_transform_messages`class-attribute``instance-attribute`[

select_speaker_transform_messages = None


### ``select_speaker_auto_verbose`class-attribute``instance-attribute`[

select_speaker_auto_verbose = False


### ``select_speaker_auto_model_client_cls`class-attribute``instance-attribute`[

select_speaker_auto_model_client_cls = None


### ``select_speaker_auto_llm_config`class-attribute``instance-attribute`[

select_speaker_auto_llm_config = None


### ``role_for_select_speaker_messages`class-attribute``instance-attribute`[

role_for_select_speaker_messages = 'system'


### ``eligibility_policies`class-attribute``instance-attribute`[

eligibility_policies = field(default_factory=list)


### ``DEFAULT_INTRO_MSG`class-attribute``instance-attribute`[

DEFAULT_INTRO_MSG = 'Hello everyone. We have assembled a great team today to answer questions and solve tasks. In attendance are:'


### ``allowed_speaker_transitions_dict`class-attribute``instance-attribute`[

allowed_speaker_transitions_dict = field(init=False)


### ``agent_names`property`[

agent_names


Return the names of the agents in the group chat.

### ``reset [

reset()


Reset the group chat.

### ``append [

append(message, speaker)


Append a message to the group chat.

### ``agent_by_name [

agent_by_name(name, recursive=False, raise_on_name_conflict=False)


Returns the agent with a given name.

### ``nested_agents [

nested_agents()


Returns all agents in the group chat manager.

### ``next_agent [

next_agent(agent, agents=None)


Return the next agent in the list.

### ``select_speaker_msg [

select_speaker_msg(agents=None)


Return the system message for selecting the next speaker.

### ``select_speaker_prompt [

select_speaker_prompt(agents=None)


Return the floating system prompt selecting the next speaker.

### ``introductions_msg [

introductions_msg(agents=None)


Return the system message for selecting the next speaker.

### ``manual_select_speaker [

manual_select_speaker(agents=None)


Manually select the next speaker.

### ``random_select_speaker [

random_select_speaker(agents=None)


Randomly select the next speaker.

### ``select_speaker [

select_speaker(last_speaker, selector)


Select the next speaker (with requery).

### ``a_select_speaker`async`[

a_select_speaker(last_speaker, selector)


Select the next speaker (with requery), asynchronously.

### ``a_auto_select_speaker`async`[

a_auto_select_speaker(last_speaker, selector, messages, agents)


(Asynchronous) Selects next speaker for the "auto" speaker selection method. Utilises its own two-agent chat to determine the next speaker and supports requerying.