GroupChatManager

GroupChatManager(
    groupchat: autogen.GroupChat,
    name: str | None = 'chat_manager',
    max_consecutive_auto_reply: int | None = 9223372036854775807,
    human_input_mode: Literal['ALWAYS', 'NEVER', 'TERMINATE'] = 'NEVER',
    system_message: str | list | None = 'Group chat manager.',
    silent: bool = False,
    **kwargs
)

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

Parameters:
NameDescription
groupchatType: autogen.GroupChat
namename of the agent.

Type: str | None

Default: ‘chat_manager’
max_consecutive_auto_replythe maximum number of consecutive auto replies.

default to None (no limit provided, class attribute MAX_CONSECUTIVE_AUTO_REPLY will be used as the limit in this case).

When set to 0, no auto reply will be generated.

Type: int | None

Default: 9223372036854775807
human_input_modewhether to ask for human inputs every time a message is received.

Possible values are “ALWAYS”, “TERMINATE”, “NEVER”.

(1) When “ALWAYS”, the agent prompts for human input every time a message is received.

Under this mode, the conversation stops when the human input is “exit”, or when is_termination_msg is True and there is no human input.

(2) When “TERMINATE”, the agent only prompts for human input only when a termination message is received or the number of auto reply reaches the max_consecutive_auto_reply.

(3) When “NEVER”, the agent will never prompt for human input.

Under this mode, the conversation stops when the number of auto reply reaches the max_consecutive_auto_reply or when is_termination_msg is True.

Type: Literal['ALWAYS', 'NEVER', 'TERMINATE']

Default: ‘NEVER’
system_messagesystem message for the ChatCompletion inference.

Type: str | list | None

Default: ‘Group chat manager.‘
silent(Experimental) whether to print the message sent.

If None, will use the value of silent in each function.

Type: bool

Default: False
**kwargs

Instance Attributes

groupchat


Returns the group chat managed by the group chat manager.

last_speaker


Return the agent who sent the last message to group chat manager.

In a group chat, an agent will always send a message to the group chat manager, and the group chat manager will send the message to all other agents in the group chat. So, when an agent receives a message, it will always be from the group chat manager. With this property, the agent receiving the message can know who actually sent the message.

Example:

from autogen import ConversableAgent
from autogen import GroupChat, GroupChatManager


def print_messages(recipient, messages, sender, config):
    # Print the message immediately
    print(f"Sender: \{sender.name} | Recipient: \{recipient.name} | Message: \{messages[-1].get('content')}")
    print(f"Real Sender: \{sender.last_speaker.name}")
    assert sender.last_speaker.name in messages[-1].get("content")
    return False, None  # Required to ensure the agent communication flow continues


agent_a = ConversableAgent("agent A", default_auto_reply="I'm agent A.")
agent_b = ConversableAgent("agent B", default_auto_reply="I'm agent B.")
agent_c = ConversableAgent("agent C", default_auto_reply="I'm agent C.")
for agent in [agent_a, agent_b, agent_c]:
    agent.register_reply([ConversableAgent, None], reply_func=print_messages, config=None)
group_chat = GroupChat(
    [agent_a, agent_b, agent_c],
    messages=[],
    max_round=6,
    speaker_selection_method="random",
    allow_repeat_speaker=True,
)
chat_manager = GroupChatManager(group_chat)
groupchat_result = agent_a.initiate_chat(chat_manager, message="Hi, there, I'm agent A.")

Instance Methods

a_resume

a_resume(
    self,
    messages: list[dict] | str,
    remove_termination_string: str | Callable[[str], str] | None = None,
    silent: bool | None = False
) -> tuple[autogen.ConversableAgent, dict]

Resumes a group chat using the previous messages as a starting point, asynchronously. Requires the agents, group chat, and group chat manager to be established as per the original group chat.

Parameters:
NameDescription
messagesType: list[dict] | str
remove_termination_stringType: str | Callable[[str], str] | None

Default: None
silentType: bool | None

Default: False
Returns:
TypeDescription
tuple[autogen.ConversableAgent, dict]- Tuple[ConversableAgent, Dict]: A tuple containing the last agent who spoke and their message

a_run_chat

a_run_chat(
    self,
    messages: list[dict] | None = None,
    sender: autogen.Agent | None = None,
    config: autogen.GroupChat | None = None
) -> 

Run a group chat asynchronously.

Parameters:
NameDescription
messagesType: list[dict] | None

Default: None
senderType: autogen.Agent | None

Default: None
configType: autogen.GroupChat | None

Default: None

chat_messages_for_summary

chat_messages_for_summary(self, agent: autogen.Agent) -> list[dict]

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

Parameters:
NameDescription
agentType: autogen.Agent

clear_agents_history

clear_agents_history(
    self,
    reply: dict,
    groupchat: autogen.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.

Parameters:
NameDescription
replyreply message dict to analyze.

Type: dict
groupchatGroupChat object.

Type: autogen.GroupChat

messages_from_string

messages_from_string(self, message_string: str) -> list[dict]

Reads the saved state of messages in Json format for resume and returns as a messages list

Parameters:
NameDescription
message_stringType: str
Returns:
TypeDescription
list[dict]- List[Dict]: List of messages

messages_to_string

messages_to_string(self, messages: list[dict]) -> str

Converts the provided messages into a Json string that can be used for resuming the chat. The state is made up of a list of messages

Parameters:
NameDescription
messagesType: list[dict]
Returns:
TypeDescription
str- str: Json representation of the messages which can be persisted for resuming later

resume

resume(
    self,
    messages: list[dict] | str,
    remove_termination_string: str | Callable[[str], str] | None = None,
    silent: bool | None = False
) -> tuple[autogen.ConversableAgent, dict]

Resumes a group chat using the previous messages as a starting point. Requires the agents, group chat, and group chat manager to be established as per the original group chat.

Parameters:
NameDescription
messagesType: list[dict] | str
remove_termination_stringType: str | Callable[[str], str] | None

Default: None
silentType: bool | None

Default: False
Returns:
TypeDescription
tuple[autogen.ConversableAgent, dict]- Tuple[ConversableAgent, Dict]: A tuple containing the last agent who spoke and their message

run_chat

run_chat(
    self,
    messages: list[dict] | None = None,
    sender: autogen.Agent | None = None,
    config: autogen.GroupChat | None = None
) -> tuple[bool, str | None]

Run a group chat.

Parameters:
NameDescription
messagesType: list[dict] | None

Default: None
senderType: autogen.Agent | None

Default: None
configType: autogen.GroupChat | None

Default: None