.NET: [BREAKING] Renamed CreateAIAgent/GetAIAgent to AsAIAgent (#3222)

* Renamed chat client extension method

* Additional renaming

* Updated documentation

* Fixed tests

* Small fix

* Small fix
This commit is contained in:
Dmytro Struk
2026-01-15 08:01:15 -08:00
committed by GitHub
Unverified
parent e192af93a7
commit 2ab859dd94
99 changed files with 307 additions and 307 deletions
@@ -27,11 +27,11 @@ public static class A2AAgentCardExtensions
/// <param name="httpClient">The <see cref="HttpClient"/> to use for HTTP requests.</param>
/// <param name="loggerFactory">The logger factory for enabling logging within the agent.</param>
/// <returns>An <see cref="AIAgent"/> instance backed by the A2A agent.</returns>
public static AIAgent GetAIAgent(this AgentCard card, HttpClient? httpClient = null, ILoggerFactory? loggerFactory = null)
public static AIAgent AsAIAgent(this AgentCard card, HttpClient? httpClient = null, ILoggerFactory? loggerFactory = null)
{
// Create the A2A client using the agent URL from the card.
var a2aClient = new A2AClient(new Uri(card.Url), httpClient);
return a2aClient.GetAIAgent(name: card.Name, description: card.Description, loggerFactory: loggerFactory);
return a2aClient.AsAIAgent(name: card.Name, description: card.Description, loggerFactory: loggerFactory);
}
}
@@ -42,6 +42,6 @@ public static class A2ACardResolverExtensions
// Obtain the agent card from the resolver.
var agentCard = await resolver.GetAgentCardAsync(cancellationToken).ConfigureAwait(false);
return agentCard.GetAIAgent(httpClient, loggerFactory);
return agentCard.AsAIAgent(httpClient, loggerFactory);
}
}
@@ -35,6 +35,6 @@ public static class A2AClientExtensions
/// <param name="description">The description of the agent.</param>
/// <param name="loggerFactory">Optional logger factory for enabling logging within the agent.</param>
/// <returns>An <see cref="AIAgent"/> instance backed by the A2A agent.</returns>
public static AIAgent GetAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null) =>
public static AIAgent AsAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null) =>
new A2AAgent(client, id, name, description, loggerFactory);
}
@@ -31,7 +31,7 @@ public static class AnthropicBetaServiceExtensions
/// <param name="loggerFactory">Optional logger factory for enabling logging within the agent.</param>
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>The created <see cref="ChatClientAgent"/> AI agent.</returns>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IBetaService betaService,
string model,
string? instructions = null,
@@ -81,7 +81,7 @@ public static class AnthropicBetaServiceExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the Anthropic Chat Completion service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="betaService"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IBetaService betaService,
ChatClientAgentOptions options,
Func<IChatClient, IChatClient>? clientFactory = null,
@@ -31,7 +31,7 @@ public static class AnthropicClientExtensions
/// <param name="loggerFactory">Optional logger factory for enabling logging within the agent.</param>
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>The created <see cref="ChatClientAgent"/> AI agent.</returns>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IAnthropicClient client,
string model,
string? instructions = null,
@@ -81,7 +81,7 @@ public static class AnthropicClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the Anthropic Chat Completion service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IAnthropicClient client,
ChatClientAgentOptions options,
Func<IChatClient, IChatClient>? clientFactory = null,
@@ -19,7 +19,7 @@ public static class PersistentAgentsClientExtensions
/// <param name="clientFactory">Provides a way to customize the creation of the underlying <see cref="IChatClient"/> used by the agent.</param>
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the persistent agent.</returns>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this PersistentAgentsClient persistentAgentsClient,
Response<PersistentAgent> persistentAgentResponse,
ChatOptions? chatOptions = null,
@@ -31,7 +31,7 @@ public static class PersistentAgentsClientExtensions
throw new ArgumentNullException(nameof(persistentAgentResponse));
}
return GetAIAgent(persistentAgentsClient, persistentAgentResponse.Value, chatOptions, clientFactory, services);
return AsAIAgent(persistentAgentsClient, persistentAgentResponse.Value, chatOptions, clientFactory, services);
}
/// <summary>
@@ -43,7 +43,7 @@ public static class PersistentAgentsClientExtensions
/// <param name="clientFactory">Provides a way to customize the creation of the underlying <see cref="IChatClient"/> used by the agent.</param>
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the persistent agent.</returns>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this PersistentAgentsClient persistentAgentsClient,
PersistentAgent persistentAgentMetadata,
ChatOptions? chatOptions = null,
@@ -112,7 +112,7 @@ public static class PersistentAgentsClientExtensions
}
var persistentAgentResponse = persistentAgentsClient.Administration.GetAgent(agentId, cancellationToken);
return persistentAgentsClient.GetAIAgent(persistentAgentResponse, chatOptions, clientFactory, services);
return persistentAgentsClient.AsAIAgent(persistentAgentResponse, chatOptions, clientFactory, services);
}
/// <summary>
@@ -145,7 +145,7 @@ public static class PersistentAgentsClientExtensions
}
var persistentAgentResponse = await persistentAgentsClient.Administration.GetAgentAsync(agentId, cancellationToken).ConfigureAwait(false);
return persistentAgentsClient.GetAIAgent(persistentAgentResponse, chatOptions, clientFactory, services);
return persistentAgentsClient.AsAIAgent(persistentAgentResponse, chatOptions, clientFactory, services);
}
/// <summary>
@@ -158,7 +158,7 @@ public static class PersistentAgentsClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the persistent agent.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="persistentAgentResponse"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this PersistentAgentsClient persistentAgentsClient,
Response<PersistentAgent> persistentAgentResponse,
ChatClientAgentOptions options,
@@ -170,7 +170,7 @@ public static class PersistentAgentsClientExtensions
throw new ArgumentNullException(nameof(persistentAgentResponse));
}
return GetAIAgent(persistentAgentsClient, persistentAgentResponse.Value, options, clientFactory, services);
return AsAIAgent(persistentAgentsClient, persistentAgentResponse.Value, options, clientFactory, services);
}
/// <summary>
@@ -183,7 +183,7 @@ public static class PersistentAgentsClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the persistent agent.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="persistentAgentMetadata"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this PersistentAgentsClient persistentAgentsClient,
PersistentAgent persistentAgentMetadata,
ChatClientAgentOptions options,
@@ -268,7 +268,7 @@ public static class PersistentAgentsClientExtensions
}
var persistentAgentResponse = persistentAgentsClient.Administration.GetAgent(agentId, cancellationToken);
return persistentAgentsClient.GetAIAgent(persistentAgentResponse, options, clientFactory, services);
return persistentAgentsClient.AsAIAgent(persistentAgentResponse, options, clientFactory, services);
}
/// <summary>
@@ -307,7 +307,7 @@ public static class PersistentAgentsClientExtensions
}
var persistentAgentResponse = await persistentAgentsClient.Administration.GetAgentAsync(agentId, cancellationToken).ConfigureAwait(false);
return persistentAgentsClient.GetAIAgent(persistentAgentResponse, options, clientFactory, services);
return persistentAgentsClient.AsAIAgent(persistentAgentResponse, options, clientFactory, services);
}
/// <summary>
@@ -91,7 +91,7 @@ public static partial class AzureAIProjectChatClientExtensions
AgentRecord agentRecord = GetAgentRecordByName(aiProjectClient, name, cancellationToken);
return GetAIAgent(
return AsAIAgent(
aiProjectClient,
agentRecord,
tools,
@@ -125,7 +125,7 @@ public static partial class AzureAIProjectChatClientExtensions
AgentRecord agentRecord = await GetAgentRecordByNameAsync(aiProjectClient, name, cancellationToken).ConfigureAwait(false);
return GetAIAgent(
return AsAIAgent(
aiProjectClient,
agentRecord,
tools,
@@ -143,7 +143,7 @@ public static partial class AzureAIProjectChatClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations based on the latest version of the Azure AI Agent.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="aiProjectClient"/> or <paramref name="agentRecord"/> is <see langword="null"/>.</exception>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AIProjectClient aiProjectClient,
AgentRecord agentRecord,
IList<AITool>? tools = null,
@@ -174,7 +174,7 @@ public static partial class AzureAIProjectChatClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations based on the provided version of the Azure AI Agent.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="aiProjectClient"/> or <paramref name="agentVersion"/> is <see langword="null"/>.</exception>
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AIProjectClient aiProjectClient,
AgentVersion agentVersion,
IList<AITool>? tools = null,
@@ -36,13 +36,13 @@ This package provides a `ConfigureDurableAgents` extension method on the `Functi
// Invocable via HTTP via http://localhost:7071/api/agents/SpamDetectionAgent/run
AIAgent spamDetector = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
.AsAIAgent(
instructions: "You are a spam detection assistant that identifies spam emails.",
name: "SpamDetectionAgent");
AIAgent emailAssistant = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
.AsAIAgent(
instructions: "You are an email assistant that helps users draft responses to emails with professionalism.",
name: "EmailAssistantAgent");
@@ -156,7 +156,7 @@ These tools are registered with the agent using the `tools` parameter when creat
Tools tools = new();
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
.AsAIAgent(
instructions: "You are a content generation assistant that helps users generate content.",
name: "ContentGenerationAgent",
tools: [
@@ -30,7 +30,7 @@ public static class OpenAIAssistantClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AssistantClient assistantClient,
ClientResult<Assistant> assistantClientResult,
ChatOptions? chatOptions = null,
@@ -42,7 +42,7 @@ public static class OpenAIAssistantClientExtensions
throw new ArgumentNullException(nameof(assistantClientResult));
}
return assistantClient.GetAIAgent(assistantClientResult.Value, chatOptions, clientFactory, services);
return assistantClient.AsAIAgent(assistantClientResult.Value, chatOptions, clientFactory, services);
}
/// <summary>
@@ -55,7 +55,7 @@ public static class OpenAIAssistantClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AssistantClient assistantClient,
Assistant assistantMetadata,
ChatOptions? chatOptions = null,
@@ -123,7 +123,7 @@ public static class OpenAIAssistantClientExtensions
}
var assistant = assistantClient.GetAssistant(agentId, cancellationToken);
return assistantClient.GetAIAgent(assistant, chatOptions, clientFactory, services);
return assistantClient.AsAIAgent(assistant, chatOptions, clientFactory, services);
}
/// <summary>
@@ -156,7 +156,7 @@ public static class OpenAIAssistantClientExtensions
}
var assistantResponse = await assistantClient.GetAssistantAsync(agentId, cancellationToken).ConfigureAwait(false);
return assistantClient.GetAIAgent(assistantResponse, chatOptions, clientFactory, services);
return assistantClient.AsAIAgent(assistantResponse, chatOptions, clientFactory, services);
}
/// <summary>
@@ -170,7 +170,7 @@ public static class OpenAIAssistantClientExtensions
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
/// <exception cref="ArgumentNullException"><paramref name="assistantClientResult"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AssistantClient assistantClient,
ClientResult<Assistant> assistantClientResult,
ChatClientAgentOptions options,
@@ -182,7 +182,7 @@ public static class OpenAIAssistantClientExtensions
throw new ArgumentNullException(nameof(assistantClientResult));
}
return assistantClient.GetAIAgent(assistantClientResult.Value, options, clientFactory, services);
return assistantClient.AsAIAgent(assistantClientResult.Value, options, clientFactory, services);
}
/// <summary>
@@ -196,7 +196,7 @@ public static class OpenAIAssistantClientExtensions
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
/// <exception cref="ArgumentNullException"><paramref name="assistantMetadata"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
public static ChatClientAgent GetAIAgent(
public static ChatClientAgent AsAIAgent(
this AssistantClient assistantClient,
Assistant assistantMetadata,
ChatClientAgentOptions options,
@@ -282,7 +282,7 @@ public static class OpenAIAssistantClientExtensions
}
var assistant = assistantClient.GetAssistant(agentId, cancellationToken);
return assistantClient.GetAIAgent(assistant, options, clientFactory, services);
return assistantClient.AsAIAgent(assistant, options, clientFactory, services);
}
/// <summary>
@@ -322,7 +322,7 @@ public static class OpenAIAssistantClientExtensions
}
var assistantResponse = await assistantClient.GetAssistantAsync(agentId, cancellationToken).ConfigureAwait(false);
return assistantClient.GetAIAgent(assistantResponse, options, clientFactory, services);
return assistantClient.AsAIAgent(assistantResponse, options, clientFactory, services);
}
/// <summary>
@@ -32,7 +32,7 @@ public static class OpenAIChatClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Chat Completion service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this ChatClient client,
string? instructions = null,
string? name = null,
@@ -41,7 +41,7 @@ public static class OpenAIChatClientExtensions
Func<IChatClient, IChatClient>? clientFactory = null,
ILoggerFactory? loggerFactory = null,
IServiceProvider? services = null) =>
client.CreateAIAgent(
client.AsAIAgent(
new ChatClientAgentOptions()
{
Name = name,
@@ -66,7 +66,7 @@ public static class OpenAIChatClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Chat Completion service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this ChatClient client,
ChatClientAgentOptions options,
Func<IChatClient, IChatClient>? clientFactory = null,
@@ -32,7 +32,7 @@ public static class OpenAIResponseClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Response service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this ResponsesClient client,
string? instructions = null,
string? name = null,
@@ -44,7 +44,7 @@ public static class OpenAIResponseClientExtensions
{
Throw.IfNull(client);
return client.CreateAIAgent(
return client.AsAIAgent(
new ChatClientAgentOptions()
{
Name = name,
@@ -70,7 +70,7 @@ public static class OpenAIResponseClientExtensions
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Response service.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this ResponsesClient client,
ChatClientAgentOptions options,
Func<IChatClient, IChatClient>? clientFactory = null,
@@ -186,7 +186,7 @@ AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent("You are a helpful assistant.")
.AsAIAgent("You are a helpful assistant.")
.AsBuilder()
.WithPurview(browserCredential, new PurviewSettings("Agent Framework Test App"))
.Build();
@@ -174,7 +174,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj
AIProjectClient client = this.GetAgentClient();
agent = client.GetAIAgent(agentVersion, tools: null, clientFactory: null, services: null);
agent = client.AsAIAgent(agentVersion, tools: null, clientFactory: null, services: null);
FunctionInvokingChatClient? functionInvokingClient = agent.GetService<FunctionInvokingChatClient>();
if (functionInvokingClient is not null)
@@ -49,7 +49,7 @@ public static class ChatClientBuilderExtensions
IList<AITool>? tools = null,
ILoggerFactory? loggerFactory = null,
IServiceProvider? services = null) =>
Throw.IfNull(builder).Build(services).CreateAIAgent(
Throw.IfNull(builder).Build(services).AsAIAgent(
instructions: instructions,
name: name,
description: description,
@@ -78,7 +78,7 @@ public static class ChatClientBuilderExtensions
ChatClientAgentOptions? options,
ILoggerFactory? loggerFactory = null,
IServiceProvider? services = null) =>
Throw.IfNull(builder).Build(services).CreateAIAgent(
Throw.IfNull(builder).Build(services).AsAIAgent(
options: options,
loggerFactory: loggerFactory,
services: services);
@@ -20,7 +20,7 @@ public static class ChatClientExtensions
/// </summary>
/// <inheritdoc cref="ChatClientAgent(IChatClient, string?, string?, string?, IList{AITool}?, ILoggerFactory?, IServiceProvider?)"/>
/// <returns>A new <see cref="ChatClientAgent"/> instance.</returns>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IChatClient chatClient,
string? instructions = null,
string? name = null,
@@ -42,7 +42,7 @@ public static class ChatClientExtensions
/// </summary>
/// <inheritdoc cref="ChatClientAgent(IChatClient, ChatClientAgentOptions?, ILoggerFactory?, IServiceProvider?)"/>
/// <returns>A new <see cref="ChatClientAgent"/> instance.</returns>
public static ChatClientAgent CreateAIAgent(
public static ChatClientAgent AsAIAgent(
this IChatClient chatClient,
ChatClientAgentOptions? options,
ILoggerFactory? loggerFactory = null,