diff --git a/examples/Python/ChatAgent/README.md b/examples/Python/ChatAgent/README.md new file mode 100644 index 00000000..7a96dd5d --- /dev/null +++ b/examples/Python/ChatAgent/README.md @@ -0,0 +1,105 @@ +# 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.10 or later +- An Azure subscription with: + - An Azure App Configuration store + - An Azure AI project with a deployed gpt-4.1 model and Grounding with Bing Search configured as a connected resource. +- 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\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: + ```cmd + 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 Azure AI 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 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 "" + ``` + + If you use PowerShell, run the following command: + ```powershell + $Env:AZURE_APPCONFIGURATION_ENDPOINT="" + ``` + + If you use macOS or Linux run the following command: + ```bash + export AZURE_APPCONFIGURATION_ENDPOINT='' + ``` + +## Run the Application + +1. Start the console application: + + ```cmd + 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... + ``` + diff --git a/examples/Python/ChatAgent/app.py b/examples/Python/ChatAgent/app.py new file mode 100644 index 00000000..3768e174 --- /dev/null +++ b/examples/Python/ChatAgent/app.py @@ -0,0 +1,32 @@ +import asyncio +import os +from agent_framework.declarative import AgentFactory +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) + + agent_spec = config["ChatAgent:Spec"] + + agent = AgentFactory(client_kwargs={"credential": credential, "project_endpoint": config["ChatAgent:ProjectEndpoint"]}).create_agent_from_yaml(agent_spec) + + 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()) diff --git a/examples/Python/ChatAgent/requirements.txt b/examples/Python/ChatAgent/requirements.txt new file mode 100644 index 00000000..85f9ad8b --- /dev/null +++ b/examples/Python/ChatAgent/requirements.txt @@ -0,0 +1,5 @@ +agent-framework-azure-ai==1.0.0b251211 +agent-framework-declarative==1.0.0b251211 +agent-framework-core==1.0.0b251211 +azure-appconfiguration-provider==2.3.1 +azure-identity==1.26.0b1