Skip to content

Commit 2499d15

Browse files
MaryanneNjeriMaryanne Gichohijimmyca15
authored
Add AI Agent sample console app (#1115)
* Add AI Agent sample console app * Add README.md * Address PR comments * Improve ReadMe * Address PR comments * Address PR comments * Include package version * Update package version * Add extra line * Add extra line * Update app.py * Address comments * Update examples/Python/ChatAgent/README.md Co-authored-by: Jimmy Campbell <jimmyca@microsoft.com> * Update examples/Python/ChatAgent/README.md Co-authored-by: Jimmy Campbell <jimmyca@microsoft.com> * Include agent-framework-core with package version in requirements.txt * Minor update in ReadMe --------- Co-authored-by: Maryanne Gichohi <mgichohi@microsoft.com> Co-authored-by: Jimmy Campbell <jimmyca@microsoft.com>
1 parent 0de207d commit 2499d15

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Azure App Configuration - AI Agent chat application
2+
3+
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.
4+
5+
## Features
6+
7+
- Integrates with Azure AI Agent Framework to create a conversational AI agent
8+
- Loads agent YAML specifications from Azure App Configuration.
9+
10+
## Prerequisites
11+
12+
- Python 3.10 or later
13+
- An Azure subscription with:
14+
- An Azure App Configuration store
15+
- An Azure AI project with a deployed gpt-4.1 model and Grounding with Bing Search configured as a connected resource.
16+
- User has **App Configuration Reader** role assigned for the Azure App Configuration resource.
17+
- User has **Azure AI User** role assigned for the Azure AI project.
18+
19+
## Setup
20+
21+
1. Clone the repository and navigate to the `examples\Python\ChatAgent` directory:
22+
```bash
23+
git clone https://github.com/Azure/AppConfiguration.git
24+
cd examples\Python\ChatAgent
25+
```
26+
27+
1. Next, create a new Python virtual environment where you can safely install the packages:
28+
29+
On macOS or Linux run the following command:
30+
```bash
31+
python -m venv .venv
32+
source .venv/bin/activate
33+
```
34+
35+
On Windows run:
36+
```cmd
37+
python -m venv .venv
38+
.venv\scripts\activate
39+
```
40+
41+
1. Install the required packages:
42+
43+
```bash
44+
pip install -r requirements.txt
45+
```
46+
47+
1. Add the following key-values to your Azure App Configuration store.
48+
49+
| Key | Value |
50+
|-----|-------|
51+
| ChatAgent:Spec | _See YAML below_ |
52+
| CharAgent:ProjectEndpoint | _Your Azure AI project endpoint_ |
53+
54+
**YAML specification for _ChatAgent:Spec_**
55+
```yaml
56+
kind: Prompt
57+
name: ChatAgent
58+
description: Agent example with web search
59+
instructions: You are a helpful assistant with access to web search.
60+
model:
61+
id: gpt-4.1
62+
connection:
63+
kind: remote
64+
tools:
65+
- kind: web_search
66+
name: WebSearchTool
67+
description: Search the web for live information.
68+
```
69+
70+
1. Set the required environment variable:
71+
72+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
73+
74+
```cmd
75+
setx AZURE_APPCONFIGURATION_ENDPOINT "<endpoint-of-your-app-configuration-store>"
76+
```
77+
78+
If you use PowerShell, run the following command:
79+
```powershell
80+
$Env:AZURE_APPCONFIGURATION_ENDPOINT="<endpoint-of-your-app-configuration-store>"
81+
```
82+
83+
If you use macOS or Linux run the following command:
84+
```bash
85+
export AZURE_APPCONFIGURATION_ENDPOINT='<endpoint-of-your-app-configuration-store>'
86+
```
87+
88+
## Run the Application
89+
90+
1. Start the console application:
91+
92+
```cmd
93+
python app.py
94+
```
95+
96+
2. Type the message "What is the weather in Seattle today?" when prompted with "How can I help?" and then press the Enter key
97+
98+
```Output
99+
How can I help? (type 'quit' to exit)
100+
User: What is the weather today in Seattle ?
101+
Agent response: Today in Seattle, expect steady rain throughout the day with patchy fog, and a high temperature around 57°F (14°C).
102+
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).
103+
Press enter to continue...
104+
```
105+

examples/Python/ChatAgent/app.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import asyncio
2+
import os
3+
from agent_framework.declarative import AgentFactory
4+
from azure.identity import DefaultAzureCredential
5+
from azure.appconfiguration.provider import load
6+
7+
async def main():
8+
endpoint = os.environ["AZURE_APPCONFIGURATION_ENDPOINT"]
9+
credential = DefaultAzureCredential()
10+
11+
config = load(endpoint=endpoint, credential=credential)
12+
13+
agent_spec = config["ChatAgent:Spec"]
14+
15+
agent = AgentFactory(client_kwargs={"credential": credential, "project_endpoint": config["ChatAgent:ProjectEndpoint"]}).create_agent_from_yaml(agent_spec)
16+
17+
while True:
18+
print("How can I help? (type 'quit' to exit)")
19+
20+
user_input = input("User: ")
21+
22+
if user_input.lower() in ['quit', 'exit', 'bye']:
23+
break
24+
25+
response = await agent.run(user_input)
26+
print("Agent response: ", response.text)
27+
input("Press enter to continue...")
28+
29+
print("Exiting... Goodbye...")
30+
31+
if __name__ == "__main__":
32+
asyncio.run(main())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
agent-framework-azure-ai==1.0.0b251211
2+
agent-framework-declarative==1.0.0b251211
3+
agent-framework-core==1.0.0b251211
4+
azure-appconfiguration-provider==2.3.1
5+
azure-identity==1.26.0b1

0 commit comments

Comments
 (0)