ChatClientAgent API Reference
AnAIAgent implementation that delegates to an IChatClient for chat completion operations.
ChatClientAgent
Provides an agent that uses anIChatClient to send messages to an AI provider and receive responses.
Constructor
IChatClient
required
The chat client to use when running the agent.
string?
Optional system instructions that guide the agent’s behavior. These are provided to the
IChatClient with each invocation.string?
Optional name for the agent, used for identification and logging.
string?
Optional human-readable description of the agent’s purpose and capabilities.
IList<AITool>?
Optional collection of tools that the agent can invoke during conversations. These augment any tools provided via
ChatOptions.Tools.ILoggerFactory?
Optional logger factory for creating loggers used by the agent and its components.
IServiceProvider?
Optional service provider for resolving dependencies required by AI functions and other agent components.
ChatClientAgentOptions?
Configuration options that control all aspects of the agent’s behavior, including chat settings, chat history providers, context providers, and other advanced configurations.
Properties
IChatClient
The underlying chat client used by the agent. May return the original client or a pipeline of decorating
IChatClient instances.ChatHistoryProvider?
The
ChatHistoryProvider used by this agent for cases where chat history is not stored by the agent service.IReadOnlyList<AIContextProvider>?
The list of
AIContextProvider instances used by this agent for providing additional context during agent runs.string?
The system instructions that guide the agent’s behavior during conversations.
Methods
CreateSessionAsync()
Creates a new conversation session for use with this agent.string
The identifier of an existing conversation to continue. Used for service-backed agents with server-side chat history storage.
CancellationToken
default:"default"
The cancellation token to monitor for cancellation requests.
ValueTask<AgentSession>
A new
AgentSession (specifically ChatClientAgentSession) instance configured for use with this agent.Extension Methods
AsAIAgent()
Extension method to convert anIChatClient into a ChatClientAgent.
Example: Basic Agent Creation
Example: Agent with Tools
Example: Using ChatClientAgentOptions
Example: Streaming with Tools
Example: Session with Server-Side History
IChatClient
TheIChatClient interface from Microsoft.Extensions.AI defines the contract for sending messages to an AI provider.
Overview
IChatClient is the core abstraction for chat completion operations. It’s implemented by provider-specific packages and used by ChatClientAgent.
Methods
GetResponseAsync()
Sends a request to get a response from the chat client.GetStreamingResponseAsync()
Sends a request to get a streaming response from the chat client.Example: Custom IChatClient
ChatClientBuilder
Extension methods for building agents fromChatClientBuilder.
BuildAIAgent()
Builds aChatClientAgent from a ChatClientBuilder pipeline.