autogen_agentchat.条件#

该模块提供了多种终止条件,用于控制多代理团队的行为。

class ExternalTermination[源代码]#

基类:TerminationCondition, Component[ExternalTerminationConfig]

通过调用set()方法外部控制的终止条件。

示例:

from autogen_agentchat.conditions import ExternalTermination

termination = ExternalTermination()

# Run the team in an asyncio task.
...

# Set the termination condition externally
termination.set()
classmethod _from_config(config: ExternalTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() ExternalTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

ExternalTerminationConfig的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.ExternalTermination'#

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

async reset() [源代码]#

重置终止条件。

set() [源代码]#

将终止条件设置为terminated。

property terminated: bool#

检查是否已达到终止条件

class FunctionCallTermination(function_name: str)[源代码]#

基础类: TerminationCondition, Component[FunctionCallTerminationConfig]

如果接收到具有特定名称的FunctionExecutionResult,则终止对话。

Parameters:

function_name (str) – 在消息中查找的函数名称。

Raises:

TerminatedException – 如果终止条件已经达到。

classmethod _from_config(config: FunctionCallTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() FunctionCallTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

FunctionCallTerminationConfig的别名

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class HandoffTermination(target: str)[源代码]#

基础类:TerminationCondition, Component[HandoffTerminationConfig]

如果接收到包含给定目标的HandoffMessage,则终止对话。

Parameters:

target (str) – 交办消息的目标。

classmethod _from_config(config: HandoffTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() HandoffTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

HandoffTerminationConfig的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.HandoffTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class MaxMessageTermination(max_messages: int, include_agent_event: bool = False)[源代码]#

基础:TerminationCondition, Component[MaxMessageTerminationConfig]

在交换了一定数量的消息后终止对话。

Parameters:
  • max_messages – 对话中允许的最大消息数。

  • include_agent_event – 如果为True,则在消息计数中包括AgentEvent。否则,仅包括ChatMessage。默认为False。

classmethod _from_config(config: MaxMessageTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() MaxMessageTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

别名 MaxMessageTerminationConfig

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.MaxMessageTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class SourceMatchTermination(sources: 列表[str])[源代码]#

基类:TerminationCondition, Component[SourceMatchTerminationConfig]

在特定来源响应后终止对话。

Parameters:

sources (List[str]) – 用于终止对话的源名称列表。

Raises:

TerminatedException – 如果终止条件已经达到。

classmethod _from_config(config: SourceMatchTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() SourceMatchTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

SourceMatchTerminationConfig的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.SourceMatchTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class StopMessageTermination[源代码]#

基类:TerminationCondition, Component[StopMessageTerminationConfig]

如果接收到StopMessage,则终止对话。

classmethod _from_config(config: StopMessageTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() StopMessageTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

StopMessageTerminationConfig 的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.StopMessageTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class TextMentionTermination(text: str, sources: Sequence[str] | = None)[源代码]#

基类:TerminationCondition, Component[TextMentionTerminationConfig]

如果提到特定文本,则终止对话。

Parameters:
  • text – 在消息中查找的文本。

  • sources – 仅检查指定代理的消息,以查找要查找的文本。

classmethod _from_config(config: TextMentionTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() TextMentionTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

TextMentionTerminationConfig的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.TextMentionTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class TextMessageTermination(source: str | = None)[源代码]#

基础:TerminationCondition, Component[TextMessageTerminationConfig]

如果接收到TextMessage,则终止对话。

此终止条件检查消息序列中的TextMessage实例。当找到TextMessage时,如果满足以下任一条件,则终止对话: - 未指定消息来源(在任何TextMessage上终止) - 消息来源与指定的来源匹配

Parameters:

source (str | None, optional) – 要匹配传入消息的源名称。如果为 None,则匹配任何源。 默认为 None。

classmethod _from_config(config: TextMessageTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() TextMessageTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

别名 TextMessageTerminationConfig

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.TextMessageTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class TimeoutTermination(timeout_seconds: float)[源代码]#

基础: TerminationCondition, Component[TimeoutTerminationConfig]

在指定时间过后终止对话。

Parameters:

timeout_seconds – 在终止对话之前的最大持续时间(以秒为单位)。

classmethod _from_config(config: TimeoutTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() TimeoutTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

TimeoutTerminationConfig 的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.TimeoutTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件

class TokenUsageTermination(max_total_token: int | = None, max_prompt_token: int | = None, max_completion_token: int | = None)[源代码]#

基础类: TerminationCondition, Component[TokenUsageTerminationConfig]

如果达到令牌使用限制,则终止对话。

Parameters:
  • max_total_token – 对话中允许的最大总标记数。

  • max_prompt_token – 对话中允许的最大提示词数量。

  • max_completion_token – 对话中允许的最大完成令牌数。

Raises:

ValueError – 如果没有提供 max_total_token、max_prompt_token 或 max_completion_token 中的任何一个。

classmethod _from_config(config: TokenUsageTerminationConfig) 自我[源代码]#

从配置对象创建组件的新实例。

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() TokenUsageTerminationConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

TokenUsageTerminationConfig的别名

component_provider_override: ClassVar[str | ] = 'autogen_agentchat.conditions.TokenUsageTermination'#

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

async reset() [源代码]#

重置终止条件。

property terminated: bool#

检查是否已达到终止条件