-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1950057
Add AI Agent sample console app
b1204f1
Add README.md
164d85f
Address PR comments
72f7442
Improve ReadMe
f8d8936
Address PR comments
17dc90e
Address PR comments
d15b704
Include package version
31cb4d8
Update package version
0d44ce2
Add extra line
c4c90d6
Add extra line
dc02afa
Update app.py
MaryanneNjeri d1c89fb
Address comments
26d5446
Merge branch 'user/maryanne/agent_sample_app' of https://github.com/A…
62423b7
Update examples/Python/ChatAgent/README.md
MaryanneNjeri eec7227
Update examples/Python/ChatAgent/README.md
MaryanneNjeri 8159576
Include agent-framework-core with package version in requirements.txt
bff2000
Merge branch 'user/maryanne/agent_sample_app' of https://github.com/A…
9390fd3
Minor update in ReadMe
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 "<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: | ||
|
|
||
| ```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... | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.