Table of Contents

Interface IAgent

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

Represents an agent within the runtime that can process messages, maintain state, and be closed when no longer needed.

public interface IAgent : ISaveState
Inherited Members

Properties

Id

Gets the unique identifier of the agent.

AgentId Id { get; }

Property Value

AgentId

Metadata

Gets metadata associated with the agent.

AgentMetadata Metadata { get; }

Property Value

AgentMetadata

Methods

OnMessageAsync(object, MessageContext)

Handles an incoming message for the agent. This should only be called by the runtime, not by other agents.

ValueTask<object?> OnMessageAsync(object message, MessageContext messageContext)

Parameters

message object

The received message. The type should match one of the expected subscription types.

messageContext MessageContext

The context of the message, providing additional metadata.

Returns

ValueTask<object>

A task representing the asynchronous operation, returning a response to the message. The response can be null if no reply is necessary.

Exceptions

OperationCanceledException

Thrown if the message was cancelled.

CantHandleException

Thrown if the agent cannot handle the message.