autogen_agentchat.base#
- class AndTerminationCondition(*conditions: TerminationCondition)[source]#
基类:
TerminationCondition
,Component
[AndTerminationConditionConfig
]- component_config_schema#
别名:
AndTerminationConditionConfig
- component_provider_override: ClassVar[str | None] = 'autogen_agentchat.base.AndTerminationCondition'#
覆盖组件的提供程序字符串。这应该用于防止内部模块名称成为模块名称的一部分。
- component_type: ClassVar[ComponentType] = 'termination'#
组件的逻辑类型。
- class ChatAgent(*args, **kwargs)[source]#
基类:
ABC
,TaskRunner
,ComponentBase
[BaseModel
]聊天代理的协议。
- component_type: ClassVar[ComponentType] = 'agent'#
组件的逻辑类型。
- abstract async on_messages(messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken) Response [source]#
处理传入的消息并返回响应。
- abstract on_messages_stream(messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken) AsyncGenerator[BaseAgentEvent | BaseChatMessage | Response, None] [source]#
处理传入的消息并返回内部消息流,最后一个条目是响应。
- abstract async on_pause(cancellation_token: CancellationToken) None [source]#
当代理暂停时调用。 当调用此方法时,代理可能正在
on_messages()
或on_messages_stream()
中运行。
- abstract async on_reset(cancellation_token: CancellationToken) None [source]#
将代理重置为其初始化状态。
- abstract async on_resume(cancellation_token: CancellationToken) None [source]#
当代理恢复时调用。 当调用此方法时,代理可能正在
on_messages()
或on_messages_stream()
中运行。
- abstract property produced_message_types: Sequence[type[BaseChatMessage]]#
代理在
Response.chat_message
字段中生成的消息类型。 它们必须是BaseChatMessage
类型。
- pydantic model Handoff[source]#
基类:
BaseModel
切换配置。
显示 JSON 模式
{ "title": "Handoff", "description": "Handoff configuration.", "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" ] }
- 字段:
description (str)
message (str)
name (str)
target (str)
- 验证器:
set_defaults
»all fields
- class OrTerminationCondition(*conditions: TerminationCondition)[source]#
基类:
TerminationCondition
,Component
[OrTerminationConditionConfig
]- component_config_schema#
是
OrTerminationConditionConfig
的别名
- component_provider_override: ClassVar[str | None] = 'autogen_agentchat.base.OrTerminationCondition'#
覆盖组件的提供程序字符串。这应该用于防止内部模块名称成为模块名称的一部分。
- component_type: ClassVar[ComponentType] = 'termination'#
组件的逻辑类型。
- class Response(*, chat_message: BaseChatMessage, inner_messages: Sequence[BaseAgentEvent | BaseChatMessage] | None = None)[源代码]#
基类:
object
调用
ChatAgent.on_messages()
的响应。- chat_message: BaseChatMessage#
代理作为响应产生的聊天消息。
- inner_messages: Sequence[BaseAgentEvent | BaseChatMessage] | None = None#
代理产生的内部消息,可以是
BaseAgentEvent
或BaseChatMessage
。
- pydantic 模型 TaskResult[源代码]#
基类:
BaseModel
运行任务的结果。
显示 JSON 模式
{ "title": "TaskResult", "description": "Result of running a task.", "type": "object", "properties": { "messages": { "items": { "anyOf": [ { "$ref": "#/$defs/BaseAgentEvent" }, { "$ref": "#/$defs/BaseChatMessage" } ] }, "title": "Messages", "type": "array" }, "stop_reason": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Stop Reason" } }, "$defs": { "BaseAgentEvent": { "description": "Base class for agent events.\n\n.. note::\n\n If you want to create a new message type for signaling observable events\n to user and application, inherit from this class.\n\nAgent events are used to signal actions and thoughts produced by agents\nand teams to user and applications. They are not used for agent-to-agent\ncommunication and are not expected to be processed by other agents.\n\nYou should override the :meth:`to_text` method if you want to provide\na custom rendering of the content.", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" } }, "required": [ "source" ], "title": "BaseAgentEvent", "type": "object" }, "BaseChatMessage": { "description": "Abstract base class for chat messages.\n\n.. note::\n\n If you want to create a new message type that is used for agent-to-agent\n communication, inherit from this class, or simply use\n :class:`StructuredMessage` if your content type is a subclass of\n Pydantic BaseModel.\n\nThis class is used for messages that are sent between agents in a chat\nconversation. Agents are expected to process the content of the\nmessage using models and return a response as another :class:`BaseChatMessage`.", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" } }, "required": [ "source" ], "title": "BaseChatMessage", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "messages" ] }
- 字段:
messages (Sequence[autogen_agentchat.messages.BaseAgentEvent | autogen_agentchat.messages.BaseChatMessage])
stop_reason (str | None)
- field messages: Sequence[BaseAgentEvent | BaseChatMessage] [必需]#
任务产生的消息。
- class TaskRunner(*args, **kwargs)[源代码]#
基类:
Protocol
任务运行器。
- async run(*, task: str | BaseChatMessage | Sequence[BaseChatMessage] | None = None, cancellation_token: CancellationToken | None = None) TaskResult [source]#
运行任务并返回结果。
任务可以是一个字符串、一条消息或一系列消息。
运行器是有状态的,后续对此方法的调用将从上次调用停止的地方继续。 如果未指定任务,则运行器将继续执行当前任务。
- run_stream(*, task: str | BaseChatMessage | Sequence[BaseChatMessage] | None = None, cancellation_token: CancellationToken | None = None) AsyncGenerator[BaseAgentEvent | BaseChatMessage | TaskResult, None] [source]#
运行任务并生成消息流以及最终结果
TaskResult
作为流中的最后一个项目。任务可以是一个字符串、一条消息或一系列消息。
运行器是有状态的,后续对此方法的调用将从上次调用停止的地方继续。 如果未指定任务,则运行器将继续执行当前任务。
- class Team(*args, **kwargs)[source]#
基类:
ABC
,TaskRunner
,ComponentBase
[BaseModel
]- component_type: ClassVar[ComponentType] = 'team'#
组件的逻辑类型。
- abstract async pause() None [source]#
暂停团队及其所有参与者。 这对于并发暂停
autogen_agentchat.base.TaskRunner.run()
或autogen_agentchat.base.TaskRunner.run_stream()
方法非常有用,同时保持它们处于活动状态。
- 异常 TerminatedException[源代码]#
基类:
BaseException
- 类 TerminationCondition[源代码]#
基类:
ABC
,ComponentBase
[BaseModel
]一个有状态的条件,用于确定何时应该终止对话。
终止条件是一个可调用对象,它接受自上次调用该条件以来的一系列 BaseChatMessage 对象,如果应该终止对话,则返回一个 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'#
组件的逻辑类型。