diff --git a/dotnet/demos/MinimalConsole/MinimalConsole.csproj b/dotnet/demos/MinimalConsole/MinimalConsole.csproj
index 62e6ae5b56..7020df82e5 100644
--- a/dotnet/demos/MinimalConsole/MinimalConsole.csproj
+++ b/dotnet/demos/MinimalConsole/MinimalConsole.csproj
@@ -13,6 +13,7 @@
+
diff --git a/dotnet/demos/MinimalConsole/Program.cs b/dotnet/demos/MinimalConsole/Program.cs
index 8935856ffb..a4c21ec673 100644
--- a/dotnet/demos/MinimalConsole/Program.cs
+++ b/dotnet/demos/MinimalConsole/Program.cs
@@ -6,22 +6,18 @@ using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Agents;
+using OpenAI;
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
-{
- return $"The weather in {location} is cloudy with a high of 15°C.";
-}
+ => $"The weather in {location} is cloudy with a high of 15°C.";
-IChatClient chatClient = new AzureOpenAIClient(
+AIAgent agent = new AzureOpenAIClient(
new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
- .AsIChatClient();
-
-AIAgent agent = new ChatClientAgent(
- chatClient,
- instructions: "You are a helpful assistant, you can help the user with weather information.",
- tools: [AIFunctionFactory.Create(GetWeather)]);
+ .CreateAIAgent(
+ instructions: "You are a helpful assistant, you can help the user with weather information.",
+ tools: [AIFunctionFactory.Create(GetWeather)]);
Console.WriteLine(await agent.RunAsync("What's the weather in Amsterdam?"));
diff --git a/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureAIAgentsPersistent.cs b/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureAIAgentsPersistent.cs
index 9e3dccc7eb..cf3d2bcae4 100644
--- a/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureAIAgentsPersistent.cs
+++ b/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureAIAgentsPersistent.cs
@@ -43,11 +43,13 @@ public sealed class AIAgent_With_AzureAIAgentsPersistent(ITestOutputHelper outpu
// Local function to run agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- Console.WriteLine(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- Console.WriteLine(response);
+ """);
}
// Cleanup
@@ -77,11 +79,13 @@ public sealed class AIAgent_With_AzureAIAgentsPersistent(ITestOutputHelper outpu
// Local function to run agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- Console.WriteLine(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- Console.WriteLine(response);
+ """);
}
// Cleanup
diff --git a/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureOpenAIChatCompletion.cs b/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureOpenAIChatCompletion.cs
index 86b33c35f9..e2216359ad 100644
--- a/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureOpenAIChatCompletion.cs
+++ b/dotnet/samples/GettingStarted/Providers/AIAgent_With_AzureOpenAIChatCompletion.cs
@@ -39,11 +39,13 @@ public sealed class AIAgent_With_AzureOpenAIChatCompletion(ITestOutputHelper out
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- this.WriteUserMessage(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- this.WriteResponseOutput(response);
+ """);
}
}
}
diff --git a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIAssistant.cs b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIAssistant.cs
index 13fc621133..3dc69536f7 100644
--- a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIAssistant.cs
+++ b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIAssistant.cs
@@ -43,11 +43,13 @@ public sealed class AIAgent_With_OpenAIAssistant(ITestOutputHelper output) : Age
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- this.WriteUserMessage(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- this.WriteResponseOutput(response);
+ """);
}
// Cleanup
diff --git a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIClient.cs b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIClient.cs
index 2c85b93bf7..86fd251701 100644
--- a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIClient.cs
+++ b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIClient.cs
@@ -33,11 +33,13 @@ public sealed class AIAgent_With_OpenAIClient(ITestOutputHelper output) : AgentS
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- Console.WriteLine(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- Console.WriteLine(response.Messages.Last().Text);
+ """);
}
}
@@ -59,12 +61,17 @@ public sealed class AIAgent_With_OpenAIClient(ITestOutputHelper output) : AgentS
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- Console.WriteLine(input);
+ Console.WriteLine($"User: {input}");
var response = await agent.RunAsync(input, thread);
var chatCompletion = response.AsChatCompletion();
- Console.WriteLine(chatCompletion.Content.Last().Text);
+ Console.WriteLine(
+ $"""
+ Assistant:
+ {chatCompletion.Content.Last().Text}
+
+ """);
}
}
@@ -86,13 +93,18 @@ public sealed class AIAgent_With_OpenAIClient(ITestOutputHelper output) : AgentS
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- Console.WriteLine(input);
+ Console.WriteLine($"User: {input}");
// Use the OpenAI.Chat message types directly
var chatMessage = new UserChatMessage(input);
var chatCompletion = await agent.RunAsync(chatMessage, thread);
- Console.WriteLine(chatCompletion.Content.Last().Text);
+ Console.WriteLine(
+ $"""
+ Assistant:
+ {chatCompletion.Content.Last().Text}
+
+ """);
}
}
}
diff --git a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIResponseClient.cs b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIResponseClient.cs
index 314a49c768..f9d8ac3307 100644
--- a/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIResponseClient.cs
+++ b/dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIResponseClient.cs
@@ -37,11 +37,13 @@ public sealed class AIAgent_With_OpenAIResponseClient(ITestOutputHelper output)
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- this.WriteUserMessage(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- this.WriteResponseOutput(response);
+ """);
}
}
@@ -77,11 +79,13 @@ public sealed class AIAgent_With_OpenAIResponseClient(ITestOutputHelper output)
// Local function to invoke agent and display the conversation messages for the thread.
async Task RunAgentAsync(string input)
{
- this.WriteUserMessage(input);
+ Console.WriteLine(
+ $"""
+ User: {input}
+ Assistant:
+ {await agent.RunAsync(input, thread)}
- var response = await agent.RunAsync(input, thread);
-
- this.WriteResponseOutput(response);
+ """);
}
}
}
diff --git a/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs b/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs
index f0b498c992..b593c24f6a 100644
--- a/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs
+++ b/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs
@@ -16,6 +16,9 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
private const string ParrotName = "Parrot";
private const string ParrotInstructions = "Repeat the user message in the voice of a pirate and then end with a parrot sound.";
+ private const string JokerName = "Joker";
+ private const string JokerInstructions = "You are good at telling jokes.";
+
///
/// Demonstrate the most basic Agent case, where we do not have a server-side agent
/// but just an in-memory agent, backed by an inference service,
@@ -33,7 +36,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
IChatClient chatClient = base.GetChatClient(provider);
// Define the agent
- AIAgent agent = new ChatClientAgent(chatClient, name: ParrotName, instructions: ParrotInstructions);
+ AIAgent agent = new ChatClientAgent(chatClient, ParrotInstructions);
// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Fortune favors the bold."));
@@ -95,8 +98,8 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
// Define the options for the chat client agent.
var agentOptions = new ChatClientAgentOptions
{
- Name = ParrotName,
- Instructions = ParrotInstructions,
+ Name = JokerName,
+ Instructions = JokerInstructions,
// Get chat options based on the store type, if needed.
ChatOptions = base.GetChatOptions(provider),
@@ -145,7 +148,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
public async Task RunStreamingWithThread(ChatClientProviders provider)
{
// Define the options for the chat client agent.
- var agentOptions = new ChatClientAgentOptions(name: ParrotName, instructions: ParrotInstructions)
+ var agentOptions = new ChatClientAgentOptions(name: JokerName, instructions: JokerInstructions)
{
// Get chat options based on the store type, if needed.
ChatOptions = base.GetChatOptions(provider),
diff --git a/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs b/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs
index 45c9f57342..7c233a8cc3 100644
--- a/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs
+++ b/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs
@@ -9,6 +9,9 @@ namespace Steps;
public sealed class Step04_ChatClientAgent_DependencyInjection(ITestOutputHelper output) : AgentSample(output)
{
+ private const string JokerName = "Joker";
+ private const string JokerInstructions = "You are good at telling jokes.";
+
[Theory]
[InlineData(ChatClientProviders.AzureAIAgentsPersistent)]
[InlineData(ChatClientProviders.AzureOpenAI)]
@@ -20,9 +23,7 @@ public sealed class Step04_ChatClientAgent_DependencyInjection(ITestOutputHelper
// Adding multiple chat clients to the service collection.
var services = new ServiceCollection();
- var agentOptions = new ChatClientAgentOptions(
- name: "Parrot",
- instructions: "Repeat the user message in the voice of a pirate and then end with a parrot sound.");
+ var agentOptions = new ChatClientAgentOptions(JokerInstructions, JokerName);
services.AddLogging();