autogen_agentchat.base#

class AndTerminationCondition(*conditions: TerminationCondition)[源代码]#

基础:TerminationCondition, Component[AndTerminationConditionConfig]

component_config_schema#

AndTerminationConditionConfig 的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.base.AndTerminationCondition'#

覆盖组件的提供商字符串。这应用于防止内部模块名称成为模块名称的一部分。

component_type: ClassVar[ComponentType] = 'termination'#

组件的逻辑类型。

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class ChatAgent(*args, **kwargs)[源代码]#

基础类: ABC, TaskRunner, ComponentBase[BaseModel]

聊天代理的协议。

abstract async close() [源代码]#

释放代理持有的任何资源。

component_type: ClassVar[ComponentType] = 'agent'#

组件的逻辑类型。

abstract property description: str#

代理的描述。团队使用此描述来决定使用哪些代理。描述应说明代理的能力以及如何与其互动。

abstract async load_state(state: 映射[str, 任何]) [源代码]#

从保存的状态恢复代理

abstract property name: str#

代理的名称。团队使用此名称来唯一标识代理。它在团队内应该是唯一的。

abstract async on_messages(messages: Sequence[Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], cancellation_token: CancellationToken) 响应[源代码]#

处理传入的消息并返回响应。

abstract on_messages_stream(messages: Sequence[Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], cancellation_token: CancellationToken) AsyncGenerator[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | 响应, ][源代码]#

处理传入的消息并返回一系列内部消息,最终项目是响应。

abstract async on_pause(cancellation_token: CancellationToken) [源代码]#

当代理暂停时调用。该方法被调用时,代理可能正在on_messages()on_messages_stream()中运行。

abstract async on_reset(cancellation_token: CancellationToken) [源代码]#

将代理重置为其初始化状态。

abstract async on_resume(cancellation_token: CancellationToken) [源代码]#

当代理恢复时调用。当此方法被调用时,代理可能在on_messages()on_messages_stream()中运行。

abstract property produced_message_types: Sequence[类型[Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]]#

代理在Response.chat_message字段中生成的消息类型。它们必须是ChatMessage类型。

abstract async save_state() 映射[str, 任何][源代码]#

保存代理状态以便稍后恢复

pydantic model Handoff[源代码]#

基础:BaseModel

交接配置。

显示 JSON 模式
{
   "title": "Handoff",
   "description": "Handoff 配置。",
   "type": "object",
   "properties": {
      "target": {
         "title": "Target",
         "type": "string"
      },
      "description": {
         "default": "",
         "title": "Description",
         "type": "string"
      },
      "name": {
         "default": "",
         "title": "Name",
         "type": "string"
      },
      "message": {
         "default": "",
         "title": "Message",
         "type": "string"
      }
   },
   "required": [
      "target"
   ]
}

Fields:
  • 描述 (字符串)

  • message (str)

  • name (str)

  • target (str)

Validators:
  • set_defaults » all fields

field description: str = ''#

交接的描述,例如应在何种条件下发生以及目标代理的能力。 如果未提供,则根据目标代理的名称生成。

Validated by:
  • set_defaults

field message: str = ''#

发送给目标代理的消息。 如果未提供,则根据目标代理的名称生成。

Validated by:
  • set_defaults

field name: str = ''#

此交接配置的名称。如果未提供,则根据目标代理的名称生成。

Validated by:
  • set_defaults

field target: str [Required]#

要移交的目标代理的名称。

Validated by:
  • set_defaults

validator set_defaults  »  all fields[源代码]#
property handoff_tool: BaseTool[BaseModel, BaseModel]#

从该交接配置创建一个交接工具。

class OrTerminationCondition(*conditions: TerminationCondition)[源代码]#

基类: TerminationCondition, Component[OrTerminationConditionConfig]

component_config_schema#

OrTerminationConditionConfig 的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.base.OrTerminationCondition'#

覆盖组件的提供商字符串。这应用于防止内部模块名称成为模块名称的一部分。

component_type: ClassVar[ComponentType] = 'termination'#

组件的逻辑类型。

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class Response(*, chat_message: Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')], inner_messages: Sequence[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | = None)[源代码]#

基础: object

来自调用 ChatAgent.on_messages() 的响应。

chat_message: Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]#

代理生成的聊天消息作为响应。

inner_messages: Sequence[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | = None#

代理生成的内部分信息,它们可以是AgentEventChatMessage

class TaskResult(messages: Sequence[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], stop_reason: str | = None)[源代码]#

基础: object

运行任务的结果。

messages: Sequence[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]#

由任务生成的消息。

stop_reason: str | = None#

任务停止的原因。

class TaskRunner(*args, **kwargs)[源代码]#

基础类: Protocol

一个任务运行器。

async run(*, task: str | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Sequence[Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | = None, cancellation_token: CancellationToken | = None) TaskResult[源代码]#

运行任务并返回结果。

任务可以是一个字符串、一条消息或一系列消息。

运行器是有状态的,后续调用此方法将从上次调用中断的地方继续。如果未指定任务,运行器将继续处理当前任务。

run_stream(*, task: str | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Sequence[Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | = None, cancellation_token: CancellationToken | = None) AsyncGenerator[Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Annotated[TextMessage | MultiModalMessage | StopMessage | 工具调用摘要信息 | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | TaskResult, ][源代码]#

运行任务并生成一系列消息和最终结果 TaskResult 作为流中的最后一个项目。

任务可以是一个字符串、一条消息或一系列消息。

运行器是有状态的,后续调用此方法将从上次调用中断的地方继续。如果未指定任务,运行器将继续处理当前任务。

class Team(*args, **kwargs)[源代码]#

基础类: ABC, TaskRunner, ComponentBase[BaseModel]

component_type: ClassVar[ComponentType] = 'team'#

组件的逻辑类型。

abstract async load_state(state: 映射[str, 任何]) [源代码]#

加载团队的状态。

abstract async pause() [源代码]#

暂停团队及其所有参与者。这对于暂停autogen_agentchat.base.TaskRunner.run()autogen_agentchat.base.TaskRunner.run_stream()方法的并发执行非常有用,同时保持它们的活跃状态。

abstract async reset() [源代码]#

重置团队及其所有参与者到初始状态。

abstract async resume() [源代码]#

恢复团队及其所有参与者在调用 pause() 后的暂停状态。

abstract async save_state() 映射[str, 任何][源代码]#

保存团队的当前状态。

exception TerminatedException[源代码]#

基础:BaseException

class TerminationCondition[源代码]#

基础:ABC, ComponentBase[BaseModel]

一种有状态的条件,用于确定何时应终止对话。

终止条件是一个可调用对象,它接受自上次调用条件以来的一系列ChatMessage对象,并在应该终止对话时返回一个StopMessage,否则返回None。 一旦达到终止条件,必须在使用前重置。

终止条件可以使用AND和OR运算符进行组合。

示例

import asyncio
from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination


async def main() -> None:
    # Terminate the conversation after 10 turns or if the text "TERMINATE" is mentioned.
    cond1 = MaxMessageTermination(10) | TextMentionTermination("TERMINATE")

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

    # ...

    # Reset the termination condition.
    await cond1.reset()
    await cond2.reset()


asyncio.run(main())
component_type: ClassVar[ComponentType] = 'termination'#

组件的逻辑类型。

abstract async reset() [源代码]#

重置终止条件。

abstract property terminated: bool#

检查是否已达到终止条件