Share via


DelegatingAIAgent Class

Definition

Provides an abstract base class for AI agents that delegate operations to an inner agent instance while allowing for extensibility and customization.

public class DelegatingAIAgent : Microsoft.Agents.AI.AIAgent
type DelegatingAIAgent = class
    inherit AIAgent
Public Class DelegatingAIAgent
Inherits AIAgent
Inheritance
DelegatingAIAgent
Derived

Remarks

DelegatingAIAgent implements the decorator pattern for AIAgents, enabling the creation of agent pipelines where each layer can add functionality while delegating core operations to an underlying agent. This pattern is fundamental to building composable agent architectures.

The default implementation provides transparent pass-through behavior, forwarding all operations to the inner agent. Derived classes can override specific methods to add custom behavior while maintaining compatibility with the agent interface.

Constructors

DelegatingAIAgent(AIAgent)

Initializes a new instance of the DelegatingAIAgent class with the specified inner agent.

Properties

Description

Gets a description of the agent's purpose, capabilities, or behavior.

DisplayName

Gets a display-friendly name for the agent.

(Inherited from AIAgent)
Id

Gets the unique identifier for this agent instance.

InnerAgent

Gets the inner agent instance that receives delegated operations.

Name

Gets the human-readable name of the agent.

Methods

DeserializeThread(JsonElement, JsonSerializerOptions)

Deserializes an agent thread from its JSON serialized representation.

GetNewThread()

Creates a new conversation thread that is compatible with this agent.

GetService(Type, Object)

Asks the AIAgent for an object of the specified type serviceType.

GetService<TService>(Object)

Asks the AIAgent for an object of type TService.

(Inherited from AIAgent)
RunAsync(AgentThread, AgentRunOptions, CancellationToken)

Run the agent with no message assuming that all required instructions are already provided to the agent or on the thread.

(Inherited from AIAgent)
RunAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent with a single chat message.

(Inherited from AIAgent)
RunAsync(IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent with a collection of chat messages, providing the core invocation logic that all other overloads delegate to.

RunAsync(String, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent with a text message from the user.

(Inherited from AIAgent)
RunStreamingAsync(AgentThread, AgentRunOptions, CancellationToken)

Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions.

(Inherited from AIAgent)
RunStreamingAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent in streaming mode with a single chat message.

(Inherited from AIAgent)
RunStreamingAsync(IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent in streaming mode with a collection of chat messages, providing the core streaming invocation logic.

RunStreamingAsync(String, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent in streaming mode with a text message from the user.

(Inherited from AIAgent)

Extension Methods

AsAIFunction(AIAgent, AIFunctionFactoryOptions, AgentThread)

Creates an AIFunction that runs the provided AIAgent.

AsBuilder(AIAgent)

Creates a new AIAgentBuilder using the specified agent as the foundation for the builder pipeline.

MapA2A(AIAgent, AgentCard, TaskManager, ILoggerFactory)

Attaches A2A (Agent-to-Agent) messaging capabilities via Message processing to the specified AIAgent.

MapA2A(AIAgent, TaskManager, ILoggerFactory)

Attaches A2A (Agent-to-Agent) messaging capabilities via Message processing to the specified AIAgent.

RunAsync(AIAgent, IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken)

Runs the AI agent with a collection of OpenAI chat messages and returns the response as a native OpenAI OpenAI.Chat.ChatCompletion.

RunStreamingAsync(AIAgent, IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken)

Runs the AI agent with a single OpenAI chat message and returns the response as collection of native OpenAI OpenAI.Chat.StreamingChatCompletionUpdate.

Applies to