目录

类 InProcessRuntime

命名空间
Microsoft.AutoGen.Core
程序集
Microsoft.AutoGen.Core.dll
public sealed class InProcessRuntime : IAgentRuntime, ISaveState, IHostedService
继承
InProcessRuntime
实现
继承的成员
扩展方法

构造函数

InProcessRuntime()

public InProcessRuntime()

属性

DeliverToSelf

public bool DeliverToSelf { get; set; }

属性值

bool

方法

AddSubscriptionAsync(ISubscriptionDefinition)

添加一个新的订阅,以便运行时在处理已发布的消息时进行处理。

public ValueTask AddSubscriptionAsync(ISubscriptionDefinition subscription)

参数

subscription ISubscriptionDefinition

要添加的订阅。

返回值

ValueTask

表示异步操作的任务。

GetAgentAsync(AgentId, bool)

通过其唯一标识符检索代理。

public ValueTask<AgentId> GetAgentAsync(AgentId agentId, bool lazy = true)

参数

agentId AgentId

代理的唯一标识符。

lazy bool

如果 true,则延迟获取代理。

返回值

ValueTask<AgentId>

表示异步操作的任务,返回代理的 ID。

GetAgentAsync(AgentType, string, bool)

通过其类型检索代理。

public ValueTask<AgentId> GetAgentAsync(AgentType agentType, string key = "default", bool lazy = true)

参数

agentType AgentType

代理的类型。

key string

一个可选的键,用于指定代理的变体。默认为“default”。

lazy bool

如果 true,则延迟获取代理。

返回值

ValueTask<AgentId>

表示异步操作的任务,返回代理的 ID。

GetAgentAsync(string, string, bool)

通过其字符串表示形式检索代理。

public ValueTask<AgentId> GetAgentAsync(string agent, string key = "default", bool lazy = true)

参数

agent string

代理的字符串表示形式。

key string

一个可选的键,用于指定代理的变体。默认为“default”。

lazy bool

如果 true,则延迟获取代理。

返回值

ValueTask<AgentId>

表示异步操作的任务,返回代理的 ID。

GetAgentMetadataAsync(AgentId)

检索代理的元数据。

public ValueTask<AgentMetadata> GetAgentMetadataAsync(AgentId agentId)

参数

agentId AgentId

代理的 ID。

返回值

ValueTask<AgentMetadata>

表示异步操作的任务,返回代理的元数据。

LoadAgentStateAsync(AgentId, JsonElement)

将保存的状态加载到代理中。

public ValueTask LoadAgentStateAsync(AgentId agentId, JsonElement state)

参数

agentId AgentId

正在恢复状态的代理的 ID。

state JsonElement

要恢复的状态字典。

返回值

ValueTask

表示异步操作的任务。

LoadStateAsync(JsonElement)

将先前保存的状态加载到对象中。

public ValueTask LoadStateAsync(JsonElement state)

参数

state JsonElement

表示已保存状态的字典。状态的结构是实现定义的,但必须是 JSON 可序列化的。

返回值

ValueTask

表示异步操作的任务。

ProcessNextMessageAsync(CancellationToken)

public ValueTask ProcessNextMessageAsync(CancellationToken cancellation = default)

参数

cancellation CancellationToken

返回值

ValueTask

PublishMessageAsync(object, TopicId, AgentId?, string?, CancellationToken)

将消息发布到所有订阅了给定主题的代理。不期望从发布中获得任何响应。

public ValueTask PublishMessageAsync(object message, TopicId topic, AgentId? sender = null, string? messageId = null, CancellationToken cancellation = default)

参数

message object

要发布的消息。

topic TopicId

要将消息发布到的主题。

sender AgentId?

发送消息的代理。默认为 null

messageId string

一个唯一的消息 ID。如果为 null,则将生成一个新的 ID。

cancellation CancellationToken

返回值

ValueTask

表示异步操作的任务。

异常

UndeliverableException

如果消息无法传递,则抛出此异常。

RegisterAgentFactoryAsync(AgentType, Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>>)

向运行时注册代理工厂,将其与特定的代理类型关联。该类型必须是唯一的。

public ValueTask<AgentType> RegisterAgentFactoryAsync(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>> factoryFunc)

参数

type AgentType

要与工厂关联的代理类型。

factoryFunc Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>>

一个异步创建代理实例的函数。

返回值

ValueTask<AgentType>

表示异步操作的任务,返回注册的 AgentType

RegisterAgentFactoryAsync<TAgent>(AgentType, Func<AgentId, IAgentRuntime, ValueTask<TAgent>>)

public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent

参数

type AgentType
factoryFunc Func<AgentId, IAgentRuntime, ValueTask<TAgent>>

返回值

ValueTask<AgentType>

类型参数

TAgent

RemoveSubscriptionAsync(string)

从运行时中删除订阅。

public ValueTask RemoveSubscriptionAsync(string subscriptionId)

参数

subscriptionId string

要删除的订阅的唯一标识符。

返回值

ValueTask

表示异步操作的任务。

异常

KeyNotFoundException

如果订阅不存在,则抛出此异常。

RunUntilIdleAsync()

public Task RunUntilIdleAsync()

返回值

Task

SaveAgentStateAsync(AgentId)

保存代理的状态。结果必须是 JSON 可序列化的。

public ValueTask<JsonElement> SaveAgentStateAsync(AgentId agentId)

参数

agentId AgentId

正在保存状态的代理的 ID。

返回值

ValueTask<JsonElement>

表示异步操作的任务,返回已保存状态的字典。

SaveStateAsync()

保存对象的当前状态。

public ValueTask<JsonElement> SaveStateAsync()

返回值

ValueTask<JsonElement>

表示异步操作的任务,返回包含已保存状态的字典。状态的结构是实现定义的,但必须是 JSON 可序列化的。

SendMessageAsync(object, AgentId, AgentId?, string?, CancellationToken)

向代理发送消息并获取响应。此方法应用于直接与代理通信。

public ValueTask<object?> SendMessageAsync(object message, AgentId recepient, AgentId? sender = null, string? messageId = null, CancellationToken cancellationToken = default)

参数

message object

要发送的消息。

recepient AgentId

要将消息发送到的代理。

sender AgentId?

发送消息的代理。如果从外部源发送,则应为 null

messageId string

消息的唯一标识符。如果为 null,则将生成一个新的 ID。

cancellationToken CancellationToken

如果需要,用于取消操作的令牌。

返回值

ValueTask<object>

表示异步操作的任务,返回来自代理的响应。

异常

CantHandleException

如果接收者无法处理消息,则抛出此异常。

UndeliverableException

如果消息无法传递,则抛出此异常。

StartAsync(CancellationToken)

public ValueTask StartAsync(CancellationToken token = default)

参数

token CancellationToken

返回值

ValueTask

StopAsync(CancellationToken)

public ValueTask StopAsync(CancellationToken token = default)

参数

token CancellationToken

返回值

ValueTask

TryGetAgentProxyAsync(AgentId)

尝试检索指定代理的 AgentProxy

public ValueTask<AgentProxy> TryGetAgentProxyAsync(AgentId agentId)

参数

agentId AgentId

代理的 ID。

返回值

ValueTask<AgentProxy>

表示异步操作的任务,如果成功,则返回 AgentProxy