Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
89 changes: 89 additions & 0 deletions examples/Python/WeatherAgent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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
- Required environment variables:
- `AZURE_APPCONFIGURATION_ENDPOINT`: Endpoint URL of your Azure App Configuration instance

## Setup

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

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. Configure your Azure App Configuration store with the following key-value pairs:

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

**YAML specification for _WeatherAgent:Spec_:**
```yaml
kind: Prompt
name: WeatherAgent
description: Weather Agent
instructions: You are a helpful assistant.
model:
id: gpt-4.1
connection:
kind: remote
```
1. Set the required environment variables:

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

Start the console application:

```bash
python app.py
```
35 changes: 35 additions & 0 deletions examples/Python/WeatherAgent/app.py
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
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["WeatherAgent:Spec"]

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

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())
Binary file added examples/Python/WeatherAgent/requirements.txt
Binary file not shown.
Loading