autogen_agentchat.teams#

class autogen_agentchat.teams.MaxMessageTermination(max_messages: int)[source]#

Bases: TerminationCondition

Terminate the conversation after a maximum number of messages have been exchanged.

Parameters:

max_messages – The maximum number of messages allowed in the conversation.

async reset() None[source]#

Reset the termination condition.

property terminated: bool#

Check if the termination condition has been reached

class autogen_agentchat.teams.RoundRobinGroupChat(participants: List[BaseChatAgent])[source]#

Bases: BaseGroupChat

A team that runs a group chat with participants taking turns in a round-robin fashion to publish a message to all.

If a single participant is in the team, the participant will be the only speaker.

Parameters:
  • participants (List[BaseChatAgent]) – The participants in the group chat.

  • tools (List[Tool], optional) – The tools to use in the group chat. Defaults to None.

Raises:

ValueError – If no participants are provided or if participant names are not unique.

Examples:

A team with one participant with tools:

from autogen_agentchat.agents import ToolUseAssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat, StopMessageTermination

assistant = ToolUseAssistantAgent("Assistant", model_client=..., registered_tools=...)
team = RoundRobinGroupChat([assistant])
await team.run("What's the weather in New York?", termination_condition=StopMessageTermination())

A team with multiple participants:

from autogen_agentchat.agents import CodingAssistantAgent, CodeExecutorAgent
from autogen_agentchat.teams import RoundRobinGroupChat, StopMessageTermination

coding_assistant = CodingAssistantAgent("Coding_Assistant", model_client=...)
executor_agent = CodeExecutorAgent("Code_Executor", code_executor=...)
team = RoundRobinGroupChat([coding_assistant, executor_agent])
await team.run("Write a program that prints 'Hello, world!'", termination_condition=StopMessageTermination())
class autogen_agentchat.teams.SelectorGroupChat(participants: List[BaseChatAgent], model_client: ChatCompletionClient, *, selector_prompt: str = 'You are in a role play game. The following roles are available:\n{roles}.\nRead the following conversation. Then select the next role from {participants} to play. Only return the role.\n\n{history}\n\nRead the above conversation. Then select the next role from {participants} to play. Only return the role.\n', allow_repeated_speaker: bool = False)[source]#

Bases: BaseGroupChat

A group chat team that have participants takes turn to publish a message to all, using a ChatCompletion model to select the next speaker after each message.

Parameters:
  • participants (List[BaseChatAgent]) – The participants in the group chat, must have unique names and at least two participants.

  • model_client (ChatCompletionClient) – The ChatCompletion model client used to select the next speaker.

  • selector_prompt (str, optional) – The prompt template to use for selecting the next speaker. Must contain ‘{roles}’, ‘{participants}’, and ‘{history}’ to be filled in.

  • allow_repeated_speaker (bool, optional) – Whether to allow the same speaker to be selected consecutively. Defaults to False.

Raises:

ValueError – If the number of participants is less than two or if the selector prompt is invalid.

Examples:

A team with multiple participants:

from autogen_agentchat.agents import ToolUseAssistantAgent
from autogen_agentchat.teams import SelectorGroupChat, StopMessageTermination

travel_advisor = ToolUseAssistantAgent("Travel_Advisor", model_client=..., registered_tools=...)
hotel_agent = ToolUseAssistantAgent("Hotel_Agent", model_client=..., registered_tools=...)
flight_agent = ToolUseAssistantAgent("Flight_Agent", model_client=..., registered_tools=...)
team = SelectorGroupChat([travel_advisor, hotel_agent, flight_agent], model_client=...)
await team.run("Book a 3-day trip to new york.", termination_condition=StopMessageTermination())
class autogen_agentchat.teams.StopMessageTermination[source]#

Bases: TerminationCondition

Terminate the conversation if a StopMessage is received.

async reset() None[source]#

Reset the termination condition.

property terminated: bool#

Check if the termination condition has been reached

class autogen_agentchat.teams.TerminationCondition[source]#

Bases: ABC

A stateful condition that determines when a conversation should be terminated.

A termination condition is a callable that takes a sequence of ChatMessage objects since the last time the condition was called, and returns a StopMessage if the conversation should be terminated, or None otherwise. Once a termination condition has been reached, it must be reset before it can be used again.

Termination conditions can be combined using the AND and OR operators.

Example

from autogen_agentchat.teams import MaxTurnsTermination, TextMentionTermination

# Terminate the conversation after 10 turns or if the text "TERMINATE" is mentioned.
cond1 = MaxTurnsTermination(10) | TextMentionTermination("TERMINATE")

# Terminate the conversation after 10 turns and if the text "TERMINATE" is mentioned.
cond2 = MaxTurnsTermination(10) & TextMentionTermination("TERMINATE")

...

# Reset the termination condition.
await cond1.reset()
await cond2.reset()
abstract async reset() None[source]#

Reset the termination condition.

abstract property terminated: bool#

Check if the termination condition has been reached

class autogen_agentchat.teams.TextMentionTermination(text: str)[source]#

Bases: TerminationCondition

Terminate the conversation if a specific text is mentioned.

Parameters:

text – The text to look for in the messages.

async reset() None[source]#

Reset the termination condition.

property terminated: bool#

Check if the termination condition has been reached