Language

ChatClientExtensions.AsAIAgent Method

Definition

Overloads

AsAIAgent(IChatClient, ChatClientAgentOptions, ILoggerFactory, IServiceProvider)

Creates a new ChatClientAgent instance.

public static Microsoft.Agents.AI.ChatClientAgent AsAIAgent(this Microsoft.Extensions.AI.IChatClient chatClient, Microsoft.Agents.AI.ChatClientAgentOptions? options, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory = default, IServiceProvider? services = default);
static member AsAIAgent : Microsoft.Extensions.AI.IChatClient * Microsoft.Agents.AI.ChatClientAgentOptions * Microsoft.Extensions.Logging.ILoggerFactory * IServiceProvider -> Microsoft.Agents.AI.ChatClientAgent
<Extension()>
Public Function AsAIAgent (chatClient As IChatClient, options As ChatClientAgentOptions, Optional loggerFactory As ILoggerFactory = Nothing, Optional services As IServiceProvider = Nothing) As ChatClientAgent

Parameters

chatClient
IChatClient

The chat client to use when running the agent.

options
ChatClientAgentOptions

Configuration options that control all aspects of the agent's behavior, including chat settings, chat history provider factories, context provider factories, and other advanced configurations.

loggerFactory
ILoggerFactory

Optional logger factory for creating loggers used by the agent and its components.

services
IServiceProvider

Optional service provider for resolving dependencies required by AI functions and other agent components. This is particularly important when using custom tools that require dependency injection. This is only relevant when the IChatClient doesn't already contain a FunctionInvokingChatClient and the ChatClientAgent needs to insert one.

Returns

A new ChatClientAgent instance.

Applies to

AsAIAgent(IChatClient, String, String, String, IList<AITool>, ILoggerFactory, IServiceProvider)

Creates a new ChatClientAgent instance.

public static Microsoft.Agents.AI.ChatClientAgent AsAIAgent(this Microsoft.Extensions.AI.IChatClient chatClient, string? instructions = default, string? name = default, string? description = default, System.Collections.Generic.IList<Microsoft.Extensions.AI.AITool>? tools = default, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory = default, IServiceProvider? services = default);
static member AsAIAgent : Microsoft.Extensions.AI.IChatClient * string * string * string * System.Collections.Generic.IList<Microsoft.Extensions.AI.AITool> * Microsoft.Extensions.Logging.ILoggerFactory * IServiceProvider -> Microsoft.Agents.AI.ChatClientAgent
<Extension()>
Public Function AsAIAgent (chatClient As IChatClient, Optional instructions As String = Nothing, Optional name As String = Nothing, Optional description As String = Nothing, Optional tools As IList(Of AITool) = Nothing, Optional loggerFactory As ILoggerFactory = Nothing, Optional services As IServiceProvider = Nothing) As ChatClientAgent

Parameters

chatClient
IChatClient

The chat client to use when running the agent.

instructions
String

Optional system instructions that guide the agent's behavior. These instructions are provided to the IChatClient with each invocation to establish the agent's role and behavior.

name
String

Optional name for the agent. This name is used for identification and logging purposes.

description
String

Optional human-readable description of the agent's purpose and capabilities. This description can be useful for documentation and agent discovery scenarios.

tools
IList<AITool>

Optional collection of tools that the agent can invoke during conversations. These tools augment any tools that may be provided to the agent via Tools when the agent is run. By default, all provided tools are invoked without user approval. The AI selects which functions to call and chooses the arguments — these arguments should be treated as untrusted input. Developers should require explicit approval for tools that have side effects, access sensitive data, or perform irreversible operations.

loggerFactory
ILoggerFactory

Optional logger factory for creating loggers used by the agent and its components.

services
IServiceProvider

Optional service provider for resolving dependencies required by AI functions and other agent components. This is particularly important when using custom tools that require dependency injection. This is only relevant when the IChatClient doesn't already contain a FunctionInvokingChatClient and the ChatClientAgent needs to insert one.

Returns

A new ChatClientAgent instance.

Applies to