autogen_agentchat.base#

class autogen_agentchat.base.ChatAgent(*args, **kwargs)[source]#

Bases: TaskRunner, Protocol

Protocol for a chat agent.

property description: str#

The description of the agent. This is used by team to make decisions about which agents to use. The description should describe the agent’s capabilities and how to interact with it.

property name: str#

The name of the agent. This is used by team to uniquely identify the agent. It should be unique within the team.

async on_messages(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | HandoffMessage], cancellation_token: CancellationToken) TextMessage | MultiModalMessage | StopMessage | HandoffMessage[source]#

Handle incoming messages and return a response message.

async run(task: str, *, cancellation_token: CancellationToken | None = None, termination_condition: TerminationCondition | None = None) TaskResult[source]#

Run the agent with the given task and return the result.

class autogen_agentchat.base.TaskResult(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | HandoffMessage])[source]#

Bases: object

Result of running a task.

messages: Sequence[TextMessage | MultiModalMessage | StopMessage | HandoffMessage]#

Messages produced by the task.

class autogen_agentchat.base.TaskRunner(*args, **kwargs)[source]#

Bases: Protocol

A task runner.

async run(task: str, *, cancellation_token: CancellationToken | None = None, termination_condition: TerminationCondition | None = None) TaskResult[source]#

Run the task.

class autogen_agentchat.base.Team(*args, **kwargs)[source]#

Bases: TaskRunner, Protocol

async run(task: str, *, cancellation_token: CancellationToken | None = None, termination_condition: TerminationCondition | None = None) TaskResult[source]#

Run the team on a given task until the termination condition is met.

exception autogen_agentchat.base.TerminatedException[source]#

Bases: BaseException

class autogen_agentchat.base.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