From a8fadbc49c0515939e22a33c9bec6e78226f174d Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:49:47 +0100 Subject: [PATCH] Add a minimum console demo app (#198) * Add a minimum console demo app * Remove hardcoded values from sample. * Make console project .net 9.0 only. * Move minimum console demo to demo folder. * Fix framework issue with demo project. * Undo unintended commit. * Address PR comments * Fix build issue. * Address PR Comments * Rename Agent to AIAgent in new console app. --- dotnet/agent-framework-dotnet.slnx | 5 ++++ dotnet/demos/.editorconfig | 8 ++++++ .../MinimalConsole/MinimalConsole.csproj | 19 +++++++++++++ dotnet/demos/MinimalConsole/Program.cs | 27 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 dotnet/demos/.editorconfig create mode 100644 dotnet/demos/MinimalConsole/MinimalConsole.csproj create mode 100644 dotnet/demos/MinimalConsole/Program.cs diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index ad74b1f003..0490ce2aa6 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -24,6 +24,11 @@ + + + + + diff --git a/dotnet/demos/.editorconfig b/dotnet/demos/.editorconfig new file mode 100644 index 0000000000..0e87de9ec1 --- /dev/null +++ b/dotnet/demos/.editorconfig @@ -0,0 +1,8 @@ +# Suppressing errors for Sample projects under dotnet/samples folder +[*.cs] +dotnet_diagnostic.CA2007.severity = none # Do not directly await a Task +dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member +dotnet_diagnostic.IDE1006.severity = warning # Naming rule violations +dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave +dotnet_diagnostic.CA1716.severity = none # Add summary to documentation comment. +dotnet_diagnostic.CA2000.severity = none # Call System.IDisposable.Dispose on object before all references to it are out of scope diff --git a/dotnet/demos/MinimalConsole/MinimalConsole.csproj b/dotnet/demos/MinimalConsole/MinimalConsole.csproj new file mode 100644 index 0000000000..62e6ae5b56 --- /dev/null +++ b/dotnet/demos/MinimalConsole/MinimalConsole.csproj @@ -0,0 +1,19 @@ + + + + Exe + $(ProjectsTargetFrameworks) + $(ProjectsDebugTargetFrameworks) + + + + + + + + + + + + + diff --git a/dotnet/demos/MinimalConsole/Program.cs b/dotnet/demos/MinimalConsole/Program.cs new file mode 100644 index 0000000000..8935856ffb --- /dev/null +++ b/dotnet/demos/MinimalConsole/Program.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.ComponentModel; +using Azure.AI.OpenAI; +using Azure.Identity; +using Microsoft.Extensions.AI; +using Microsoft.Extensions.AI.Agents; + +[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."; +} + +IChatClient chatClient = 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)]); + +Console.WriteLine(await agent.RunAsync("What's the weather in Amsterdam?"));