Table of Contents

Class BaseAgent

Namespace
Microsoft.AutoGen.Core
Assembly
Microsoft.AutoGen.Core.dll

Represents the base class for an agent in the AutoGen system.

public abstract class BaseAgent : IHostableAgent, IAgent, ISaveState
Inheritance
BaseAgent
Implements
Inherited Members

Constructors

BaseAgent(AgentId, IAgentRuntime, string, ILogger<BaseAgent>?)

protected BaseAgent(AgentId id, IAgentRuntime runtime, string description, ILogger<BaseAgent>? logger = null)

Parameters

id AgentId
runtime IAgentRuntime
description string
logger ILogger<BaseAgent>

Fields

_logger

protected ILogger<BaseAgent> _logger

Field Value

ILogger<BaseAgent>

s_source

The activity source for tracing.

public static readonly ActivitySource s_source

Field Value

ActivitySource

Properties

Description

protected string Description { get; }

Property Value

string

Id

Gets the unique identifier of the agent.

public AgentId Id { get; }

Property Value

AgentId

Metadata

Gets metadata associated with the agent.

public AgentMetadata Metadata { get; }

Property Value

AgentMetadata

Runtime

protected IAgentRuntime Runtime { get; }

Property Value

IAgentRuntime

Methods

CloseAsync()

Called when the runtime is closing.

public virtual ValueTask CloseAsync()

Returns

ValueTask

A task representing the asynchronous operation.

OnMessageAsync(object, MessageContext)

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

public 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.

PublishMessageAsync(object, TopicId, string?, CancellationToken)

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

Parameters

message object
topic TopicId
messageId string
cancellationToken CancellationToken

Returns

ValueTask

SendMessageAsync(object, AgentId, string?, CancellationToken)

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

Parameters

message object
recepient AgentId
messageId string
cancellationToken CancellationToken

Returns

ValueTask<object>