Share via


AIAgent Class

Definition

Provides the base abstraction for all AI agents, defining the core interface for agent interactions and conversation management.

public abstract class AIAgent
type AIAgent = class
Public MustInherit Class AIAgent
Inheritance
AIAgent
Derived

Remarks

AIAgent serves as the foundational class for implementing AI agents that can participate in conversations and process user requests. An agent instance may participate in multiple concurrent conversations, and each conversation may involve multiple agents working together.

Constructors

AIAgent()

Properties

Description

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

DisplayName

Gets a display-friendly name for the agent.

Id

Gets the unique identifier for this agent instance.

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.

NotifyThreadOfNewMessagesAsync(AgentThread, IEnumerable<ChatMessage>, CancellationToken)

Notifies the specified thread about new messages that have been added to the conversation.

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.

RunAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken)

Runs the agent with a single chat message.

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.

RunStreamingAsync(AgentThread, AgentRunOptions, CancellationToken)

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

RunStreamingAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken)

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

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.

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