Skip to content

Commit 2ab859d

Browse files
authored
.NET: [BREAKING] Renamed CreateAIAgent/GetAIAgent to AsAIAgent (#3222)
* Renamed chat client extension method * Additional renaming * Updated documentation * Fixed tests * Small fix * Small fix
1 parent e192af9 commit 2ab859d

File tree

99 files changed

+307
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+307
-307
lines changed

dotnet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT
2121

2222
var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
2323
.GetOpenAIResponseClient(deploymentName)
24-
.CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully.");
24+
.AsAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully.");
2525

2626
Console.WriteLine(await agent.RunAsync("Write a haiku about Microsoft Agent Framework."));
2727
```

dotnet/samples/A2AClientServer/A2AClient/HostClientAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal async Task InitializeAgentAsync(string modelId, string apiKey, string[]
2929
// Create the agent that uses the remote agents as tools
3030
this.Agent = new OpenAIClient(new ApiKeyCredential(apiKey))
3131
.GetChatClient(modelId)
32-
.CreateAIAgent(instructions: "You specialize in handling queries for users and using your tools to provide answers.", name: "HostClient", tools: tools);
32+
.AsAIAgent(instructions: "You specialize in handling queries for users and using your tools to provide answers.", name: "HostClient", tools: tools);
3333
}
3434
catch (Exception ex)
3535
{

dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal static class HostAgentFactory
3535
{
3636
AIAgent agent = new OpenAIClient(apiKey)
3737
.GetChatClient(model)
38-
.CreateAIAgent(instructions, name, tools: tools);
38+
.AsAIAgent(instructions, name, tools: tools);
3939

4040
AgentCard agentCard = agentType.ToUpperInvariant() switch
4141
{

dotnet/samples/AGUIClientServer/AGUIClient/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static async Task HandleCommandsAsync(CancellationToken cancellationToke
8383
serverUrl,
8484
jsonSerializerOptions: AGUIClientSerializerContext.Default.Options);
8585

86-
AIAgent agent = chatClient.CreateAIAgent(
86+
AIAgent agent = chatClient.AsAIAgent(
8787
name: "agui-client",
8888
description: "AG-UI Client Agent",
8989
tools: [changeBackground, readClientClimateSensors]);

dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static ChatClientAgent CreateAgenticChat()
3333
{
3434
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
3535

36-
return chatClient.AsIChatClient().CreateAIAgent(
36+
return chatClient.AsIChatClient().AsAIAgent(
3737
name: "AgenticChat",
3838
description: "A simple chat agent using Azure OpenAI");
3939
}
@@ -42,7 +42,7 @@ public static ChatClientAgent CreateBackendToolRendering()
4242
{
4343
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
4444

45-
return chatClient.AsIChatClient().CreateAIAgent(
45+
return chatClient.AsIChatClient().AsAIAgent(
4646
name: "BackendToolRenderer",
4747
description: "An agent that can render backend tools using Azure OpenAI",
4848
tools: [AIFunctionFactory.Create(
@@ -56,7 +56,7 @@ public static ChatClientAgent CreateHumanInTheLoop()
5656
{
5757
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
5858

59-
return chatClient.AsIChatClient().CreateAIAgent(
59+
return chatClient.AsIChatClient().AsAIAgent(
6060
name: "HumanInTheLoopAgent",
6161
description: "An agent that involves human feedback in its decision-making process using Azure OpenAI");
6262
}
@@ -65,15 +65,15 @@ public static ChatClientAgent CreateToolBasedGenerativeUI()
6565
{
6666
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
6767

68-
return chatClient.AsIChatClient().CreateAIAgent(
68+
return chatClient.AsIChatClient().AsAIAgent(
6969
name: "ToolBasedGenerativeUIAgent",
7070
description: "An agent that uses tools to generate user interfaces using Azure OpenAI");
7171
}
7272

7373
public static AIAgent CreateAgenticUI(JsonSerializerOptions options)
7474
{
7575
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
76-
var baseAgent = chatClient.AsIChatClient().CreateAIAgent(new ChatClientAgentOptions
76+
var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions
7777
{
7878
Name = "AgenticUIAgent",
7979
Description = "An agent that generates agentic user interfaces using Azure OpenAI",
@@ -116,7 +116,7 @@ public static AIAgent CreateSharedState(JsonSerializerOptions options)
116116
{
117117
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
118118

119-
var baseAgent = chatClient.AsIChatClient().CreateAIAgent(
119+
var baseAgent = chatClient.AsIChatClient().AsAIAgent(
120120
name: "SharedStateAgent",
121121
description: "An agent that demonstrates shared state patterns using Azure OpenAI");
122122

@@ -127,7 +127,7 @@ public static AIAgent CreatePredictiveStateUpdates(JsonSerializerOptions options
127127
{
128128
ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!);
129129

130-
var baseAgent = chatClient.AsIChatClient().CreateAIAgent(new ChatClientAgentOptions
130+
var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions
131131
{
132132
Name = "PredictiveStateUpdatesAgent",
133133
Description = "An agent that demonstrates predictive state updates using Azure OpenAI",

dotnet/samples/AGUIClientServer/AGUIServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
new Uri(endpoint),
2424
new DefaultAzureCredential())
2525
.GetChatClient(deploymentName)
26-
.CreateAIAgent(
26+
.AsAIAgent(
2727
name: "AGUIAssistant",
2828
tools: [
2929
AIFunctionFactory.Create(

dotnet/samples/AGUIClientServer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ The `AGUIServer` uses the `MapAGUI` extension method to expose an agent through
119119
```csharp
120120
AIAgent agent = new OpenAIClient(apiKey)
121121
.GetChatClient(model)
122-
.CreateAIAgent(
122+
.AsAIAgent(
123123
instructions: "You are a helpful assistant.",
124124
name: "AGUIAssistant");
125125

@@ -144,7 +144,7 @@ var chatClient = new AGUIChatClient(
144144
modelId: "agui-client",
145145
jsonSerializerOptions: null);
146146

147-
AIAgent agent = chatClient.CreateAIAgent(
147+
AIAgent agent = chatClient.AsAIAgent(
148148
instructions: null,
149149
name: "agui-client",
150150
description: "AG-UI Client Agent",

dotnet/samples/AGUIWebChat/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(
7474
ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName);
7575

7676
// Create AI agent
77-
ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent(
77+
ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent(
7878
name: "ChatAssistant",
7979
instructions: "You are a helpful assistant.");
8080

@@ -162,7 +162,7 @@ dotnet run
162162
Edit the instructions in `Server/Program.cs`:
163163

164164
```csharp
165-
ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent(
165+
ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent(
166166
name: "ChatAssistant",
167167
instructions: "You are a helpful coding assistant specializing in C# and .NET.");
168168
```

dotnet/samples/AGUIWebChat/Server/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName);
2727

28-
ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent(
28+
ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent(
2929
name: "ChatAssistant",
3030
instructions: "You are a helpful assistant.");
3131

dotnet/samples/AzureFunctions/01_SingleAgent/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
const string JokerName = "Joker";
2626
const string JokerInstructions = "You are good at telling jokes.";
2727

28-
AIAgent agent = client.GetChatClient(deploymentName).CreateAIAgent(JokerInstructions, JokerName);
28+
AIAgent agent = client.GetChatClient(deploymentName).AsAIAgent(JokerInstructions, JokerName);
2929

3030
// Configure the function app to host the AI agent.
3131
// This will automatically generate HTTP API endpoints for the agent.

0 commit comments

Comments
 (0)