Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/DotNetCore/ChatAgent/ChatAgent.csproj
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>
62 changes: 62 additions & 0 deletions examples/DotNetCore/ChatAgent/Program.cs
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!");
94 changes: 94 additions & 0 deletions examples/DotNetCore/ChatAgent/README.md
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...
```
Loading