AgentGroupChat Class
An agent chat that supports multi-turn interactions.
Note: This class is marked as 'experimental' and may change in the future.
Initialize a new instance of AgentGroupChat.
Constructor
AgentGroupChat(agents: list[Agent] | None = None, termination_strategy: TerminationStrategy | None = None, selection_strategy: SelectionStrategy | None = None, chat_history: ChatHistory | None = None)
Parameters
Name | Description |
---|---|
agents
|
The agents to add to the group chat. Default value: None
|
termination_strategy
|
The termination strategy to use. Default value: None
|
selection_strategy
|
The selection strategy Default value: None
|
chat_history
|
The chat history. Default value: None
|
Methods
add_agent |
Add an agent to the group chat. |
invoke |
Invoke the agent chat asynchronously. Handles both group interactions and single agent interactions based on the provided arguments. |
invoke_single_turn |
Invoke the agent chat for a single turn. |
invoke_stream |
Invoke the agent chat stream asynchronously. Handles both group interactions and single agent interactions based on the provided arguments. |
invoke_stream_single_turn |
Invoke the agent chat for a single turn. |
model_post_init |
We need to both initialize private attributes and call the user-defined model_post_init method. |
reduce_history |
Perform the reduction on the provided history, returning True if reduction occurred. |
add_agent
Add an agent to the group chat.
add_agent(agent: Agent) -> None
Parameters
Name | Description |
---|---|
agent
Required
|
The agent to add. |
invoke
Invoke the agent chat asynchronously.
Handles both group interactions and single agent interactions based on the provided arguments.
async invoke(agent: Agent | None = None, is_joining: bool = True) -> AsyncIterable[ChatMessageContent]
Parameters
Name | Description |
---|---|
agent
|
The agent to invoke. If not provided, the method processes all agents in the chat. Default value: None
|
is_joining
|
Controls whether the agent joins the chat. Defaults to True. Default value: True
|
invoke_single_turn
Invoke the agent chat for a single turn.
async invoke_single_turn(agent: Agent) -> AsyncIterable[ChatMessageContent]
Parameters
Name | Description |
---|---|
agent
Required
|
The agent to invoke. |
invoke_stream
Invoke the agent chat stream asynchronously.
Handles both group interactions and single agent interactions based on the provided arguments.
async invoke_stream(agent: Agent | None = None, is_joining: bool = True) -> AsyncIterable[ChatMessageContent]
Parameters
Name | Description |
---|---|
agent
|
The agent to invoke. If not provided, the method processes all agents in the chat. Default value: None
|
is_joining
|
Controls whether the agent joins the chat. Defaults to True. Default value: True
|
invoke_stream_single_turn
Invoke the agent chat for a single turn.
async invoke_stream_single_turn(agent: Agent) -> AsyncIterable[ChatMessageContent]
Parameters
Name | Description |
---|---|
agent
Required
|
The agent to invoke. |
model_post_init
We need to both initialize private attributes and call the user-defined model_post_init method.
model_post_init(context: Any, /) -> None
Positional-Only Parameters
Name | Description |
---|---|
context
Required
|
|
reduce_history
Perform the reduction on the provided history, returning True if reduction occurred.
async reduce_history() -> bool
Attributes
agent_channels
agent_channels: dict[str, AgentChannel]
agent_ids
agent_ids: set[str]
agents
agents: list[Agent]
broadcast_queue
broadcast_queue: BroadcastQueue
channel_map
channel_map: dict[Agent, str]
history
history: ChatHistory
is_complete
is_complete: bool
is_experimental
is_experimental = True
selection_strategy
selection_strategy: SelectionStrategy
stage_status
stage_status = 'experimental'
termination_strategy
termination_strategy: TerminationStrategy