diff --git a/python/samples/getting_started/agents/azure_ai/README.md b/python/samples/getting_started/agents/azure_ai/README.md index f11bcd300e..475dad5a1a 100644 --- a/python/samples/getting_started/agents/azure_ai/README.md +++ b/python/samples/getting_started/agents/azure_ai/README.md @@ -11,6 +11,7 @@ This folder contains examples demonstrating different ways to create and use age | [`azure_ai_with_azure_ai_search.py`](azure_ai_with_azure_ai_search.py) | Shows how to use Azure AI Search with Azure AI agents to search through indexed data and answer user questions with proper citations. Requires an Azure AI Search connection and index configured in your Azure AI project. | | [`azure_ai_with_bing_grounding.py`](azure_ai_with_bing_grounding.py) | Shows how to use Bing Grounding search with Azure AI agents to search the web for current information and provide grounded responses with citations. Requires a Bing connection configured in your Azure AI project. | | [`azure_ai_with_bing_custom_search.py`](azure_ai_with_bing_custom_search.py) | Shows how to use Bing Custom Search with Azure AI agents to search custom search instances and provide responses with relevant results. Requires a Bing Custom Search connection and instance configured in your Azure AI project. | +| [`azure_ai_with_browser_automation.py`](azure_ai_with_browser_automation.py) | Shows how to use Browser Automation with Azure AI agents to perform automated web browsing tasks and provide responses based on web interactions. Requires a Browser Automation connection configured in your Azure AI project. | | [`azure_ai_with_code_interpreter.py`](azure_ai_with_code_interpreter.py) | Shows how to use the `HostedCodeInterpreterTool` with Azure AI agents to write and execute Python code for mathematical problem solving and data analysis. | | [`azure_ai_with_existing_agent.py`](azure_ai_with_existing_agent.py) | Shows how to work with a pre-existing agent by providing the agent name and version to the Azure AI client. Demonstrates agent reuse patterns for production scenarios. | | [`azure_ai_with_existing_conversation.py`](azure_ai_with_existing_conversation.py) | Demonstrates how to use an existing conversation created on the service side with Azure AI agents. Shows two approaches: specifying conversation ID at the client level and using AgentThread with an existing conversation ID. | @@ -20,6 +21,7 @@ This folder contains examples demonstrating different ways to create and use age | [`azure_ai_with_response_format.py`](azure_ai_with_response_format.py) | Shows how to use structured outputs (response format) with Azure AI agents using Pydantic models to enforce specific response schemas. | | [`azure_ai_with_thread.py`](azure_ai_with_thread.py) | Demonstrates thread management with Azure AI agents, including automatic thread creation for stateless conversations and explicit thread management for maintaining conversation context across multiple interactions. | | [`azure_ai_with_image_generation.py`](azure_ai_with_image_generation.py) | Shows how to use the `ImageGenTool` with Azure AI agents to generate images based on text prompts. | +| [`azure_ai_with_microsoft_fabric.py`](azure_ai_with_microsoft_fabric.py) | Shows how to use Microsoft Fabric with Azure AI agents to query Fabric data sources and provide responses based on data analysis. Requires a Microsoft Fabric connection configured in your Azure AI project. | | [`azure_ai_with_web_search.py`](azure_ai_with_web_search.py) | Shows how to use the `HostedWebSearchTool` with Azure AI agents to perform web searches and retrieve up-to-date information from the internet. | ## Environment Variables diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py index 6e01c622c7..7db42e9f21 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py @@ -26,8 +26,8 @@ async def main() -> None: instructions="""You are a helpful agent that can use Bing Custom Search tools to assist users. Use the available Bing Custom Search tools to answer questions and perform tasks.""", tools={ - "type": "bing_custom_search", - "bing_custom_search": { + "type": "bing_custom_search_preview", + "bing_custom_search_preview": { "search_configurations": [ { "project_connection_id": os.environ["BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID"], diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py new file mode 100644 index 0000000000..f614228d39 --- /dev/null +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py @@ -0,0 +1,52 @@ +# Copyright (c) Microsoft. All rights reserved. +import asyncio +import os + +from agent_framework.azure import AzureAIClient +from azure.identity.aio import AzureCliCredential + +""" +Azure AI Agent with Browser Automation Example + +This sample demonstrates usage of AzureAIClient with Browser Automation +to perform automated web browsing tasks and provide responses based on web interactions. + +Prerequisites: +1. Set AZURE_AI_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME environment variables. +2. Ensure you have a Browser Automation connection configured in your Azure AI project + and set BROWSER_AUTOMATION_PROJECT_CONNECTION_ID environment variable. +""" + + +async def main() -> None: + async with ( + AzureCliCredential() as credential, + AzureAIClient(async_credential=credential).create_agent( + name="MyBrowserAutomationAgent", + instructions="""You are an Agent helping with browser automation tasks. + You can answer questions, provide information, and assist with various tasks + related to web browsing using the Browser Automation tool available to you.""", + tools={ + "type": "browser_automation_preview", + "browser_automation_preview": { + "connection": { + "project_connection_id": os.environ["BROWSER_AUTOMATION_PROJECT_CONNECTION_ID"], + } + }, + }, + ) as agent, + ): + query = """Your goal is to report the percent of Microsoft year-to-date stock price change. + To do that, go to the website finance.yahoo.com. + At the top of the page, you will find a search bar. + Enter the value 'MSFT', to get information about the Microsoft stock price. + At the top of the resulting page you will see a default chart of Microsoft stock price. + Click on 'YTD' at the top of that chart, and report the percent value that shows up just below it.""" + + print(f"User: {query}") + result = await agent.run(query) + print(f"Result: {result}\n") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py new file mode 100644 index 0000000000..8b77d9221d --- /dev/null +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py @@ -0,0 +1,46 @@ +# Copyright (c) Microsoft. All rights reserved. +import asyncio +import os + +from agent_framework.azure import AzureAIClient +from azure.identity.aio import AzureCliCredential + +""" +Azure AI Agent with Microsoft Fabric Example + +This sample demonstrates usage of AzureAIClient with Microsoft Fabric +to query Fabric data sources and provide responses based on data analysis. + +Prerequisites: +1. Set AZURE_AI_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME environment variables. +2. Ensure you have a Microsoft Fabric connection configured in your Azure AI project + and set FABRIC_PROJECT_CONNECTION_ID environment variable. +""" + + +async def main() -> None: + async with ( + AzureCliCredential() as credential, + AzureAIClient(async_credential=credential).create_agent( + name="MyFabricAgent", + instructions="You are a helpful assistant.", + tools={ + "type": "fabric_dataagent_preview", + "fabric_dataagent_preview": { + "project_connections": [ + { + "project_connection_id": os.environ["FABRIC_PROJECT_CONNECTION_ID"], + } + ] + }, + }, + ) as agent, + ): + query = "Tell me about sales records" + print(f"User: {query}") + result = await agent.run(query) + print(f"Result: {result}\n") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/python/samples/getting_started/agents/azure_ai_agent/README.md b/python/samples/getting_started/agents/azure_ai_agent/README.md index 375f682474..19165b89ed 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/README.md +++ b/python/samples/getting_started/agents/azure_ai_agent/README.md @@ -7,6 +7,7 @@ This folder contains examples demonstrating different ways to create and use age | File | Description | |------|-------------| | [`azure_ai_basic.py`](azure_ai_basic.py) | The simplest way to create an agent using `ChatAgent` with `AzureAIAgentClient`. It automatically handles all configuration using environment variables. | +| [`azure_ai_with_bing_custom_search.py`](azure_ai_with_bing_custom_search.py) | Shows how to use Bing Custom Search with Azure AI agents to find real-time information from the web using custom search configurations. Demonstrates how to set up and use HostedWebSearchTool with custom search instances. | | [`azure_ai_with_bing_grounding.py`](azure_ai_with_bing_grounding.py) | Shows how to use Bing Grounding search with Azure AI agents to find real-time information from the web. Demonstrates web search capabilities with proper source citations and comprehensive error handling. | | [`azure_ai_with_code_interpreter.py`](azure_ai_with_code_interpreter.py) | Shows how to use the HostedCodeInterpreterTool with Azure AI agents to write and execute Python code. Includes helper methods for accessing code interpreter data from response chunks. | | [`azure_ai_with_existing_agent.py`](azure_ai_with_existing_agent.py) | Shows how to work with a pre-existing agent by providing the agent ID to the Azure AI chat client. This example also demonstrates proper cleanup of manually created agents. | @@ -49,6 +50,18 @@ Before running the examples, you need to set up your environment variables. You - Add a new connection for "Grounding with Bing Search" - Copy the ID +4. For samples using Bing Custom Search (like `azure_ai_with_bing_custom_search.py`), you'll also need: + ``` + BING_CUSTOM_CONNECTION_ID="your-bing-custom-connection-id" + BING_CUSTOM_INSTANCE_NAME="your-bing-custom-instance-name" + ``` + + To get your Bing Custom Search connection details: + - Go to [Azure AI Foundry portal](https://ai.azure.com) + - Navigate to your project's "Connected resources" section + - Add a new connection for "Grounding with Bing Custom Search" + - Copy the connection ID and instance name + ### Option 2: Using environment variables directly Set the environment variables in your shell: @@ -57,6 +70,8 @@ Set the environment variables in your shell: export AZURE_AI_PROJECT_ENDPOINT="your-project-endpoint" export AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name" export BING_CONNECTION_ID="your-bing-connection-id" +export BING_CUSTOM_CONNECTION_ID="your-bing-custom-connection-id" +export BING_CUSTOM_INSTANCE_NAME="your-bing-custom-instance-name" ``` ### Required Variables @@ -67,3 +82,5 @@ export BING_CONNECTION_ID="your-bing-connection-id" ### Optional Variables - `BING_CONNECTION_ID`: Your Bing connection ID (required for `azure_ai_with_bing_grounding.py` and `azure_ai_with_multiple_tools.py`) +- `BING_CUSTOM_CONNECTION_ID`: Your Bing Custom Search connection ID (required for `azure_ai_with_bing_custom_search.py`) +- `BING_CUSTOM_INSTANCE_NAME`: Your Bing Custom Search instance name (required for `azure_ai_with_bing_custom_search.py`) diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py new file mode 100644 index 0000000000..0474d6c5bc --- /dev/null +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py @@ -0,0 +1,63 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio + +from agent_framework import ChatAgent, HostedWebSearchTool +from agent_framework.azure import AzureAIAgentClient +from azure.identity.aio import AzureCliCredential + +""" +The following sample demonstrates how to create an Azure AI agent that +uses Bing Custom Search to find real-time information from the web. + +More information on Bing Custom Search and difference from Bing Grounding can be found here: +https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/bing-custom-search + +Prerequisites: +1. A connected Grounding with Bing Custom Search resource in your Azure AI project +2. Set BING_CUSTOM_CONNECTION_ID environment variable + Example: BING_CUSTOM_CONNECTION_ID="your-bing-custom-connection-id" +3. Set BING_CUSTOM_INSTANCE_NAME environment variable + Example: BING_CUSTOM_INSTANCE_NAME="your-bing-custom-instance-name" + +To set up Bing Custom Search: +1. Go to Azure AI Foundry portal (https://ai.azure.com) +2. Navigate to your project's "Connected resources" section +3. Add a new connection for "Grounding with Bing Custom Search" +4. Copy the connection ID and instance name and set the appropriate environment variables +""" + + +async def main() -> None: + """Main function demonstrating Azure AI agent with Bing Custom Search.""" + # 1. Create Bing Custom Search tool using HostedWebSearchTool + # The connection ID and instance name will be automatically picked up from environment variables + bing_search_tool = HostedWebSearchTool( + name="Bing Custom Search", + description="Search the web for current information using Bing Custom Search", + ) + + # 2. Use AzureAIAgentClient as async context manager for automatic cleanup + async with ( + AzureAIAgentClient(async_credential=AzureCliCredential()) as client, + ChatAgent( + chat_client=client, + name="BingSearchAgent", + instructions=( + "You are a helpful agent that can use Bing Custom Search tools to assist users. " + "Use the available Bing Custom Search tools to answer questions and perform tasks." + ), + tools=bing_search_tool, + ) as agent, + ): + # 3. Demonstrate agent capabilities with bing custom search + print("=== Azure AI Agent with Bing Custom Search ===\n") + + user_input = "Tell me more about foundry agent service" + print(f"User: {user_input}") + response = await agent.run(user_input) + print(f"Agent: {response.text}\n") + + +if __name__ == "__main__": + asyncio.run(main())