ChatClientAgent Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides an AIAgent that delegates to an IChatClient implementation.
public sealed class ChatClientAgent : Microsoft.Agents.AI.AIAgent
type ChatClientAgent = class
inherit AIAgent
Public NotInheritable Class ChatClientAgent
Inherits AIAgent
- Inheritance
Constructors
| Name | Description |
|---|---|
| ChatClientAgent(IChatClient, ChatClientAgentOptions, ILoggerFactory, IServiceProvider) |
Initializes a new instance of the ChatClientAgent class. |
| ChatClientAgent(IChatClient, String, String, String, IList<AITool>, ILoggerFactory, IServiceProvider) |
Initializes a new instance of the ChatClientAgent class. |
Properties
| Name | Description |
|---|---|
| AIContextProviders |
Gets the list of AIContextProvider instances used by this agent, to support cases where additional context is needed for each agent run. |
| ChatClient |
Gets the underlying chat client used by the agent to invoke chat completions. |
| ChatHistoryProvider |
Gets the ChatHistoryProvider used by this agent, to support cases where the chat history is not stored by the agent service. |
| Description |
Gets a description of the agent's purpose, capabilities, or behavior. |
| Id |
Gets the unique identifier for this agent instance. (Inherited from AIAgent) |
| IdCore |
Gets a custom identifier for the agent, which can be overridden by derived classes. (Inherited from AIAgent) |
| Instructions |
Gets the system instructions that guide the agent's behavior during conversations. |
| Name |
Gets the human-readable name of the agent. |
Methods
| Name | Description |
|---|---|
| CreateSessionAsync(CancellationToken) |
Creates a new conversation session that is compatible with this agent. (Inherited from AIAgent) |
| CreateSessionAsync(String, CancellationToken) |
Creates a new agent session instance using an existing conversation identifier to continue that conversation. |
| CreateSessionCoreAsync(CancellationToken) |
Core implementation of session creation logic. (Inherited from AIAgent) |
| DeserializeSessionAsync(JsonElement, JsonSerializerOptions, CancellationToken) |
Deserializes an agent session from its JSON serialized representation. (Inherited from AIAgent) |
| DeserializeSessionCoreAsync(JsonElement, JsonSerializerOptions, CancellationToken) |
Core implementation of session deserialization logic. (Inherited from AIAgent) |
| GetService(Type, Object) |
Asks the AIAgent for an object of the specified type |
| GetService<TService>(Object) |
Asks the AIAgent for an object of type |
| RunAsync(AgentSession, AgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session. (Inherited from AIAgent) |
| RunAsync(AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session. |
| RunAsync(ChatMessage, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a single chat message. (Inherited from AIAgent) |
| RunAsync(ChatMessage, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a single chat message. |
| RunAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages, providing the core invocation logic that all other overloads delegate to. (Inherited from AIAgent) |
| RunAsync(IEnumerable<ChatMessage>, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages. |
| RunAsync(String, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user. (Inherited from AIAgent) |
| RunAsync(String, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user. |
| RunAsync<T>(AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session, and requesting a response of the specified type |
| RunAsync<T>(AgentSession, JsonSerializerOptions, ChatClientAgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session, and requesting a response of the specified type |
| RunAsync<T>(ChatMessage, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a single chat message, requesting a response of the specified type |
| RunAsync<T>(ChatMessage, AgentSession, JsonSerializerOptions, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a single chat message, requesting a response of the specified type |
| RunAsync<T>(IEnumerable<ChatMessage>, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages, requesting a response of the specified type |
| RunAsync<T>(IEnumerable<ChatMessage>, AgentSession, JsonSerializerOptions, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages, requesting a response of the specified type |
| RunAsync<T>(String, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user, requesting a response of the specified type |
| RunAsync<T>(String, AgentSession, JsonSerializerOptions, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user, requesting a response of the specified type |
| RunCoreAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Core implementation of the agent invocation logic with a collection of chat messages. (Inherited from AIAgent) |
| RunCoreStreamingAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Core implementation of the agent streaming invocation logic with a collection of chat messages. (Inherited from AIAgent) |
| RunStreamingAsync(AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions. (Inherited from AIAgent) |
| RunStreamingAsync(AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions. |
| RunStreamingAsync(ChatMessage, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a single chat message. (Inherited from AIAgent) |
| RunStreamingAsync(ChatMessage, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a single chat message. |
| RunStreamingAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a collection of chat messages, providing the core streaming invocation logic. (Inherited from AIAgent) |
| RunStreamingAsync(IEnumerable<ChatMessage>, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a collection of chat messages. |
| RunStreamingAsync(String, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a text message from the user. (Inherited from AIAgent) |
| RunStreamingAsync(String, AgentSession, ChatClientAgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a text message from the user. |
| SerializeSessionAsync(AgentSession, JsonSerializerOptions, CancellationToken) |
Serializes an agent session to its JSON representation. (Inherited from AIAgent) |
| SerializeSessionCoreAsync(AgentSession, JsonSerializerOptions, CancellationToken) |
Core implementation of session serialization logic. (Inherited from AIAgent) |
Extension Methods
| Name | Description |
|---|---|
| AsAIFunction(AIAgent, AIFunctionFactoryOptions, AgentSession) |
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. |
| AsDurableAgentProxy(AIAgent, IServiceProvider) |
Converts an AIAgent to a durable agent proxy. |
| BindAsExecutor(AIAgent, AIAgentHostOptions) |
Configure an AIAgent as an executor for use in a workflow. |
| BindAsExecutor(AIAgent, Boolean) |
Configure an AIAgent as an executor for use in a workflow. |
| MapA2A(AIAgent, AgentCard, ITaskManager, ILoggerFactory, AgentSessionStore, AgentRunMode, JsonSerializerOptions) |
Attaches A2A (Agent2Agent) messaging capabilities via Message processing to the specified AIAgent. |
| MapA2A(AIAgent, ITaskManager, ILoggerFactory, AgentSessionStore, AgentRunMode, JsonSerializerOptions) |
Attaches A2A (Agent2Agent) messaging capabilities via Message processing to the specified AIAgent. |
| RunAsync(AIAgent, IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the AI agent with a collection of OpenAI chat messages and returns the response as a native OpenAI OpenAI.Chat.ChatCompletion. |
| RunAsync(AIAgent, IEnumerable<ResponseItem>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the AI agent with a collection of OpenAI response items and returns the response as a native OpenAI OpenAI.Responses.ResponseResult. |
| RunStreamingAsync(AIAgent, IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the AI agent with a single OpenAI chat message and returns the response as collection of native OpenAI OpenAI.Chat.StreamingChatCompletionUpdate. |
| RunStreamingAsync(AIAgent, IEnumerable<ResponseItem>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the AI agent in streaming mode with a collection of OpenAI response items and returns the response as a collection of native OpenAI OpenAI.Responses.StreamingResponseUpdate. |