Class BaseAgent
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
AgentIdruntime
IAgentRuntimedescription
stringlogger
ILogger<BaseAgent>
Fields
_logger
protected ILogger<BaseAgent> _logger
Field Value
s_source
The activity source for tracing.
public static readonly ActivitySource s_source
Field Value
Properties
Description
protected string Description { get; }
Property Value
Id
Gets the unique identifier of the agent.
public AgentId Id { get; }
Property Value
Metadata
Gets metadata associated with the agent.
public AgentMetadata Metadata { get; }
Property Value
Runtime
protected IAgentRuntime Runtime { get; }
Property Value
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
objectThe received message. The type should match one of the expected subscription types.
messageContext
MessageContextThe 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
objecttopic
TopicIdmessageId
stringcancellationToken
CancellationToken
Returns
SendMessageAsync(object, AgentId, string?, CancellationToken)
public ValueTask<object?> SendMessageAsync(object message, AgentId recepient, string? messageId = null, CancellationToken cancellationToken = default)
Parameters
message
objectrecepient
AgentIdmessageId
stringcancellationToken
CancellationToken