AnthropicClientExtensions.AsAIAgent Method

Definition

Overloads

AsAIAgent(IAnthropicClient, ChatClientAgentOptions, Func<IChatClient,IChatClient>, ILoggerFactory, IServiceProvider)

Creates an AI agent from an Anthropic.IAnthropicClient using the Anthropic Chat Completion API.

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

Parameters

client
Anthropic.IAnthropicClient

An Anthropic Anthropic.IAnthropicClient to use with the agent..

options
ChatClientAgentOptions

Full set of options to configure the agent.

clientFactory
Func<IChatClient,IChatClient>

Provides a way to customize the creation of the underlying IChatClient used by the agent.

loggerFactory
ILoggerFactory

Optional logger factory for enabling logging within the agent.

services
IServiceProvider

An optional IServiceProvider to use for resolving services required by the AIFunction instances being invoked.

Returns

An ChatClientAgent instance backed by the Anthropic Chat Completion service.

Exceptions

Thrown when client or options is null.

Applies to

AsAIAgent(IAnthropicClient, String, String, String, String, IList<AITool>, Nullable<Int32>, Func<IChatClient,IChatClient>, ILoggerFactory, IServiceProvider)

Creates a new AI agent using the specified model and options.

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

Parameters

client
Anthropic.IAnthropicClient

An Anthropic Anthropic.IAnthropicClient to use with the agent..

model
String

The model to use for chat completions.

instructions
String

The instructions for the AI agent.

name
String

The name of the AI agent.

description
String

The description of the AI agent.

tools
IList<AITool>

The tools available to the AI agent.

defaultMaxTokens
Nullable<Int32>

The default maximum tokens for chat completions. Defaults to DefaultMaxTokens if not provided.

clientFactory
Func<IChatClient,IChatClient>

Provides a way to customize the creation of the underlying IChatClient used by the agent.

loggerFactory
ILoggerFactory

Optional logger factory for enabling logging within the agent.

services
IServiceProvider

An optional IServiceProvider to use for resolving services required by the AIFunction instances being invoked.

Returns

The created ChatClientAgent AI agent.

Applies to