Table of Contents

Class AgentProxy

Namespace
Microsoft.AutoGen.Contracts
Assembly
Microsoft.AutoGen.Contracts.dll

A helper class that allows you to use an AgentId in place of its associated IAgent.

public class AgentProxy
Inheritance
AgentProxy
Inherited Members

Constructors

AgentProxy(AgentId, IAgentRuntime)

A helper class that allows you to use an AgentId in place of its associated IAgent.

public AgentProxy(AgentId agentId, IAgentRuntime runtime)

Parameters

agentId AgentId
runtime IAgentRuntime

Fields

Id

The target agent for this proxy.

public AgentId Id

Field Value

AgentId

Properties

Metadata

Gets the metadata of the agent.

public AgentMetadata Metadata { get; }

Property Value

AgentMetadata

An instance of AgentMetadata containing details about the agent.

Methods

LoadStateAsync(JsonElement)

Loads the state of the agent from a previously saved state.

public ValueTask LoadStateAsync(JsonElement state)

Parameters

state JsonElement

A dictionary representing the state of the agent. Must be JSON serializable.

Returns

ValueTask

A task representing the asynchronous operation.

SaveStateAsync()

Saves the state of the agent. The result must be JSON serializable.

public ValueTask<JsonElement> SaveStateAsync()

Returns

ValueTask<JsonElement>

A task representing the asynchronous operation, returning a dictionary containing the saved state.

SendMessageAsync(object, AgentId, string?, CancellationToken)

Sends a message to the agent and processes the response.

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

Parameters

message object

The message to send to the agent.

sender AgentId

The agent that is sending the message.

messageId string

The message ID. If null, a new message ID will be generated. This message ID must be unique and is recommended to be a UUID.

cancellationToken CancellationToken

A token used to cancel an in-progress operation. Defaults to null.

Returns

ValueTask<object>

A task representing the asynchronous operation, returning the response from the agent.