-
Notifications
You must be signed in to change notification settings - Fork 77
Add AI Agent sample console app #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: | ||
|
|
||
| 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... | ||
| ``` | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about put it under examples/Python/WeatherAgent?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why as AsyncDefaultCredential?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it causes a conflict, since on line 5 we still import
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| agent-framework-azure-ai | ||
| azure-appconfiguration | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line at the end of the file |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.