-
Notifications
You must be signed in to change notification settings - Fork 79
Add .NET sample chat agent app #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+171
−0
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <NoWarn>$(NoWarn);OPENAI001</NoWarn> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.AI.Projects" Version="2.0.0" /> | ||
| <PackageReference Include="Azure.Identity" Version="1.20.0" /> | ||
| <PackageReference Include="Microsoft.Agents.AI" Version="1.0.0" /> | ||
| <PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0" /> | ||
| <PackageReference Include="Microsoft.Agents.AI.Declarative" Version="1.0.0-rc4" /> | ||
| <PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.4.1" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.5.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| using Azure.Core; | ||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Extensions.AI; | ||
| using Azure.AI.Projects; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Configuration.AzureAppConfiguration; | ||
|
|
||
| TokenCredential credential = new AzureCliCredential(); | ||
| IConfigurationRefresher refresher = null; | ||
|
|
||
| // Load configuration from Azure App Configuration | ||
| IConfiguration configuration = new ConfigurationBuilder() | ||
| .AddAzureAppConfiguration(options => | ||
| { | ||
| Uri endpoint = new(Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT") ?? | ||
| throw new InvalidOperationException("The environment variable 'AZURE_APPCONFIGURATION_ENDPOINT' is not set or is empty")); | ||
| options.Connect(endpoint, credential) | ||
| .Select("ChatAgent:*") | ||
| .ConfigureRefresh(refreshOptions => | ||
| { | ||
| refreshOptions.RegisterAll(); | ||
| }); | ||
| refresher = options.GetRefresher(); | ||
| }).Build(); | ||
|
|
||
| var endpoint = configuration["ChatAgent:ProjectEndpoint"]; | ||
| var deploymentName = configuration["ChatAgent:DeploymentName"]; | ||
|
|
||
| IChatClient chatClient = new AIProjectClient( | ||
| new Uri(endpoint), credential) | ||
| .GetProjectOpenAIClient() | ||
| .GetProjectResponsesClient() | ||
| .AsIChatClient(); | ||
|
|
||
| var agentSpec = configuration["ChatAgent:Spec"]; | ||
|
|
||
| var agentFactory = new ChatClientPromptAgentFactory(chatClient); | ||
|
|
||
| AIAgent agent = await agentFactory.CreateFromYamlAsync(agentSpec); | ||
|
|
||
| while (true) | ||
| { | ||
| Console.WriteLine("How can I help? (type 'quit' to exit)"); | ||
|
|
||
| Console.Write("User: "); | ||
|
|
||
| var userInput = Console.ReadLine(); | ||
|
|
||
| if (userInput?.Trim().ToLower() == "quit") | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| var response = await agent.RunAsync(userInput); | ||
|
|
||
| Console.WriteLine($"Agent response: {response}"); | ||
| Console.WriteLine("Press enter to continue..."); | ||
| Console.ReadLine(); | ||
| } | ||
|
|
||
| Console.WriteLine("Goodbye!"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Azure App Configuration - AI Agent chat application | ||
|
|
||
| This sample demonstrates using Azure App Configuration to load agent YAML specifications that define AI agent behavior, prompts, and model configurations for a chat application. | ||
|
|
||
| ## Features | ||
| - Integrates with Azure AI Agent Framework to create a conversational AI agent | ||
| - Loads agent YAML specifications from Azure App Configuration. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - .NET 10 SDK | ||
| - An Azure subscription with: | ||
| - An Azure App Configuration store | ||
| - An Azure AI project with a deployed gpt-5 model. | ||
| - User has **App Configuration Reader** role assigned for the Azure App Configuration resource. | ||
| - User has **Azure AI User** role assigned for the Azure AI project. | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Clone the repository and navigate to the `examples\DotNetCore\ChatAgent` directory: | ||
| ```bash | ||
| git clone https://github.com/Azure/AppConfiguration.git | ||
| cd examples\DotNetCore\ChatAgent | ||
| ``` | ||
|
|
||
| 1. Install the required packages: | ||
|
|
||
| ```bash | ||
| dotnet restore | ||
| ``` | ||
|
|
||
| 1. Add the following key-values to your Azure App Configuration store. | ||
|
|
||
| | Key | Value | | ||
| |-----|-------| | ||
| | ChatAgent:Spec | _See YAML below_ | | ||
| | ChatAgent:ProjectEndpoint | _Your Azure AI project endpoint_ | | ||
| | ChatAgent:DeploymentName| gpt-5 | | ||
|
|
||
| **YAML specification for _ChatAgent:Spec_** | ||
| ```yaml | ||
| kind: Prompt | ||
| name: ChatAgent | ||
| description: Agent example with web search | ||
| instructions: You are a helpful assistant with access to web search. | ||
| model: | ||
| id: gpt-5 | ||
| connection: | ||
| kind: remote | ||
| tools: | ||
| - kind: webSearch | ||
| name: WebSearchTool | ||
| description: Search the web for live information. | ||
| ``` | ||
|
|
||
| 1. Set the required environment variable: | ||
|
|
||
| If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect: | ||
|
|
||
| ```cmd | ||
| setx AZURE_APPCONFIGURATION_ENDPOINT "<endpoint-of-your-app-configuration-store>" | ||
| ``` | ||
|
|
||
| If you use PowerShell, run the following command: | ||
| ```powershell | ||
| $Env:AZURE_APPCONFIGURATION_ENDPOINT="<endpoint-of-your-app-configuration-store>" | ||
| ``` | ||
|
|
||
| If you use macOS or Linux run the following command: | ||
| ```bash | ||
| export AZURE_APPCONFIGURATION_ENDPOINT='<endpoint-of-your-app-configuration-store>' | ||
| ``` | ||
|
|
||
| ## Run the Application | ||
|
|
||
| 1. Start the console application: | ||
|
|
||
| ```cmd | ||
| dotnet run | ||
| ``` | ||
|
|
||
| 1. Type the message "What is the weather in Seattle today?" when prompted with "How can I help?" and then press the Enter key | ||
|
|
||
| ```Output | ||
| How can I help? (type 'quit' to exit) | ||
| User: What is the weather in Seattle today ? | ||
| Agent response: Seattle weather for today (Thursday, April 9, 2026): | ||
|
|
||
| - Current conditions (as of ~10:48 AM PDT): 55°F, sunny. Wind N 6 mph (gusts 7), humidity 55%, pressure 30.05 in. ([wunderground.com](https://www.wunderground.com/weather/us/wa/seattle)) | ||
| - Today’s forecast: Mostly sunny and mild. High around 64–65°F; tonight’s low near 43–44°F. Very low chance of precipitation and light winds. ([wunderground.com](https://www.wunderground.com/weather/us/wa/seattle)) | ||
|
|
||
| Want the hour‑by‑hour forecast or weekend outlook? | ||
| Press enter to continue... | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.