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
103 changes: 103 additions & 0 deletions examples/Python/ChatAgent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 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

- Python 3.8 or later
- An Azure subscription with access to:
- Azure App Configuration service
- Microsoft Foundry project

## Setup

1. Clone the repository and navigate to the `examples\Python\ChatAgent` directory:
```bash
git clone https://github.com/Azure/AppConfiguration.git
cd examples\Python\ChatAgent
```

1. Next, create a new Python virtual environment where you can safely install the packages:

On macOS or Linux run the following command:
```bash
python -m venv .venv
source .venv/bin/activate
```

On Windows run:
```bash
python -m venv .venv
.venv\scripts\activate
```

1. Install the required packages:

```bash
pip install -r requirements.txt
```

1. Add the following key-values to your Azure App Configuration store.

| Key | Value |
|-----|-------|
| ChatAgent:Spec | _See YAML below_ |
| CharAgent:ProjectEndpoint | _Your Foundry project endpoint_ |

**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-4.1
connection:
kind: remote
tools:
- kind: web_search
name: WebSearchTool
description: Search the web for live information.
```

1. Set the required environment variables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Set the required environment variables:
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:

```bash
python app.py
```

2. 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 today in Seattle ?
Agent response: Today in Seattle, expect steady rain throughout the day with patchy fog, and a high temperature around 57°F (14°C).
Winds are from the south-southwest at 14 to 17 mph, with gusts as high as 29 mph. Flood and wind advisories are in effect due to ongoing heavy rain and saturated conditions. Rain is likely to continue into the night, with a low near 49°F. Please stay aware of weather alerts if you are traveling or in low-lying areas [National Weather Service Seattle](https://forecast.weather.gov/zipcity.php?inputstring=Seattle%2CWA) [The Weather Channel Seattle Forecast](https://weather.com/weather/today/l/Seattle+Washington?canonicalCityId=1138ce33fd1be51ab7db675c0da0a27c).
Press enter to continue...
```

35 changes: 35 additions & 0 deletions examples/Python/ChatAgent/app.py
Copy link
Member

@zhenlan zhenlan Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about put it under examples/Python/WeatherAgent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is better, this has been updated, thanks

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import asyncio
import os
from agent_framework.declarative import AgentFactory
from azure.identity.aio import DefaultAzureCredential as AsyncDefaultCredential
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why as AsyncDefaultCredential?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it causes a conflict, since on line 5 we still import DefaultAzureCredential in agent framework when constructing the AzureAIClient it expects async credentials to use for authentication (https://github.com/eavanvalkenburg/agent-framework/blob/0d9ae1920dea956856055770f71192ed6317f72d/python/packages/azure-ai/agent_framework_azure_ai/_client.py#L89) or if credential is not provided project_client should be provided

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the agent framework doesn't support the sync version of the DefaultAzureCredential? Does our provider support the async version?

from azure.identity import DefaultAzureCredential
from azure.appconfiguration.provider import load

async def main():
endpoint = os.environ["AZURE_APPCONFIGURATION_ENDPOINT"]
credential = DefaultAzureCredential()

config = load(endpoint=endpoint, credential=credential)

yaml_str = config["ChatAgent:Spec"]

async with (
AsyncDefaultCredential() as credential,
AgentFactory(client_kwargs={"async_credential": credential, "project_endpoint": config["ChatAgent:ProjectEndpoint"]}).create_agent_from_yaml(yaml_str) as agent,
):
while True:
print("How can I help? (type 'quit' to exit)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a weather agent, the question should be related to weather.

Copy link
Contributor Author

@MaryanneNjeri MaryanneNjeri Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the initial prompt ? Instead of "How can I help ?", maybe we can include some sample output in the read me something like this

How can I help? (type 'quit' to exit)
User: What is the weather in Seattle ?
Agent response:  I don’t have access to real-time data, but you can quickly check the current weather in Seattle
using a reliable source like [Weather.com](https://weather.com/weather/today/l/Seattle+WA) or your preferred weather app.

As a general overview, Seattle’s weather in early June is usually mild, with temperatures ranging from the mid-50s 
to upper 60s °F (about 13–20°C). Expect partly cloudy skies with occasional showers. 
If you need a weather forecast for a specific day or a longer period, let me know!
Press enter to continue...
How can I help? (type 'quit' to exit)
User: quit
Exiting... Goodbye...

Though because this agent has no tool configured its not able to give us real time weather data. Maybe we should update the agent yaml spec to include a tool like Bing search or openapi that gives the agent access to real time data? In this sample app we don't change any agent configuration and having a tool as part of the agent yaml spec can let users know that their tool configuration could also be part of the agent yaml spec.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your proposal is reasonable, so we don't tie us to a "weather" scenario. Then we don't have to call it a WeatherAgent, but simply a ChatAgent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and in the sample output, we can ask questions about real time data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the example question you have in mind?


user_input = input("User: ")

if user_input.lower() in ['quit', 'exit', 'bye']:
break

response = await agent.run(user_input)
print("Agent response: ", response.text)
input("Press enter to continue...")

print("Exiting... Goodbye...")

if __name__ == "__main__":
asyncio.run(main())
4 changes: 4 additions & 0 deletions examples/Python/ChatAgent/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
agent-framework-azure-ai
azure-appconfiguration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add SDK directly or the provider is enough?

azure-appconfiguration-provider
azure-identity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line at the end of the file

Loading