Skip to content

Commit 9bbcfa0

Browse files
authored
feat: [draft] update version of azureaiagent (#6581)
<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> There have been updates to the azure ai agent foundry sdk (azure-ai-project). This PR updates the autogen `AzureAIAgent` which wraps the azure ai agent. A list of some changes - Update docstring samples to use `endpoint` (instead of connection string previously) - Update imports and arguments e.g, from `azure.ai.agents` etc - Add a guide in ext docs showing Bing Search Grounding tool example. <img width="1423" alt="image" src="https://github.com/user-attachments/assets/0b7c8fa6-8aa5-4c20-831b-b525ac8243b7" /> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number Closes #6601 <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
1 parent 53d3842 commit 9bbcfa0

File tree

8 files changed

+551
-343
lines changed

8 files changed

+551
-343
lines changed

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@
162162
"metadata": {},
163163
"outputs": [],
164164
"source": [
165+
"from autogen_core.models import UserMessage\n",
165166
"from autogen_ext.auth.azure import AzureTokenProvider\n",
166167
"from autogen_ext.models.openai import AzureOpenAIChatCompletionClient\n",
167168
"from azure.identity import DefaultAzureCredential\n",
168-
"from autogen_core.models import UserMessage\n",
169169
"\n",
170170
"# Create the token provider\n",
171171
"token_provider = AzureTokenProvider(\n",
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Azure AI Foundry Agent\n",
8+
"\n",
9+
"In AutoGen, you can build and deploy agents that are backed by the [Azure AI Foundry Agent Service](https://learn.microsoft.com/en-us/azure/ai-services/agents/overview) using the {py:class}`~autogen_ext.agents.azure._azure_ai_agent.AzureAIAgent` class. Here, important aspects of the agent including the provisioned model, tools (e.g, code interpreter, bing search grounding, file search etc.), observability, and security are managed by Azure. This allows you to focus on building your agent without worrying about the underlying infrastructure.\n",
10+
"\n",
11+
"In this guide, we will explore an example of creating an Azure AI Foundry Agent using the `AzureAIAgent` that can address tasks using the Azure Grounding with Bing Search tool."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# pip install \"autogen-ext[azure]\" # For Azure AI Foundry Agent Service"
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"metadata": {},
26+
"source": [
27+
"# Bing Search Grounding \n",
28+
"\n",
29+
"An {py:class}`~autogen_ext.agents.azure._azure_ai_agent.AzureAIAgent` can be assigned a set of tools including [Grounding with Bing Search](https://learn.microsoft.com/en-us/azure/ai-services/agents/how-to/tools/bing-grounding?tabs=python&pivots=overview#setup). \n",
30+
"\n",
31+
"Grounding with Bing Search allows your Azure AI Agents to incorporate real-time public web data when generating responses. You need to create a Grounding with Bing Search resource, and then connect this resource to your Azure AI Agents. When a user sends a query, Azure AI Agents decide if Grounding with Bing Search should be leveraged or not. If so, it will leverage Bing to search over public web data and return relevant chunks. Lastly, Azure AI Agents will use returned chunks to generate a response.\n",
32+
"\n",
33+
"## Prerequisites\n",
34+
"\n",
35+
"- You need to have an Azure subscription.\n",
36+
"- You need to have the Azure CLI installed and configured. (also login using the command `az login` to enable default credentials)\n",
37+
"- You need to have the `autogen-ext[azure]` package installed.\n",
38+
"\n",
39+
"You can create a [Grounding with Bing Search resource in the Azure portal](https://portal.azure.com/#create/Microsoft.BingGroundingSearch). Note that you will need to have owner or contributor role in your subscription or resource group to create it. Once you have created your resource, you can then pass it to the Azure Foundry Agent using the resource name.\n",
40+
"\n",
41+
"In the following example, we will create a new Azure Foundry Agent that uses the Grounding with Bing Search resource.\n"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"import os\n",
51+
"\n",
52+
"import dotenv\n",
53+
"from autogen_agentchat.messages import TextMessage\n",
54+
"from autogen_core import CancellationToken\n",
55+
"from autogen_ext.agents.azure import AzureAIAgent\n",
56+
"from azure.ai.agents.models import BingGroundingTool\n",
57+
"from azure.ai.projects.aio import AIProjectClient\n",
58+
"from azure.identity.aio import DefaultAzureCredential\n",
59+
"\n",
60+
"dotenv.load_dotenv()\n",
61+
"\n",
62+
"\n",
63+
"async def bing_example() -> None:\n",
64+
" async with DefaultAzureCredential() as credential: # type: ignore\n",
65+
" async with AIProjectClient( # type: ignore\n",
66+
" credential=credential, endpoint=os.getenv(\"AZURE_PROJECT_ENDPOINT\", \"\")\n",
67+
" ) as project_client:\n",
68+
" conn = await project_client.connections.get(name=os.getenv(\"BING_CONNECTION_NAME\", \"\"))\n",
69+
"\n",
70+
" bing_tool = BingGroundingTool(conn.id)\n",
71+
" agent_with_bing_grounding = AzureAIAgent(\n",
72+
" name=\"bing_agent\",\n",
73+
" description=\"An AI assistant with Bing grounding\",\n",
74+
" project_client=project_client,\n",
75+
" deployment_name=\"gpt-4o\",\n",
76+
" instructions=\"You are a helpful assistant.\",\n",
77+
" tools=bing_tool.definitions,\n",
78+
" metadata={\"source\": \"AzureAIAgent\"},\n",
79+
" )\n",
80+
"\n",
81+
" # For the bing grounding tool to return the citations, the message must contain an instruction for the model to do return them.\n",
82+
" # For example: \"Please provide citations for the answers\"\n",
83+
"\n",
84+
" result = await agent_with_bing_grounding.on_messages(\n",
85+
" messages=[\n",
86+
" TextMessage(\n",
87+
" content=\"What is Microsoft's annual leave policy? Provide citations for your answers.\",\n",
88+
" source=\"user\",\n",
89+
" )\n",
90+
" ],\n",
91+
" cancellation_token=CancellationToken(),\n",
92+
" message_limit=5,\n",
93+
" )\n",
94+
" print(result)\n",
95+
"\n",
96+
"\n",
97+
"await bing_example()"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"metadata": {},
103+
"source": [
104+
"Note that you can also provide other Azure Backed [tools](https://learn.microsoft.com/en-us/azure/ai-services/agents/how-to/tools/overview) and local client side functions to the agent.\n",
105+
"\n",
106+
"See the {py:class}`~autogen_ext.agents.azure._azure_ai_agent.AzureAIAgent` class api documentation for more details on how to create an Azure Foundry Agent."
107+
]
108+
}
109+
],
110+
"metadata": {
111+
"kernelspec": {
112+
"display_name": ".venv",
113+
"language": "python",
114+
"name": "python3"
115+
},
116+
"language_info": {
117+
"codemirror_mode": {
118+
"name": "ipython",
119+
"version": 3
120+
},
121+
"file_extension": ".py",
122+
"mimetype": "text/x-python",
123+
"name": "python",
124+
"nbconvert_exporter": "python",
125+
"pygments_lexer": "ipython3",
126+
"version": "3.11.12"
127+
}
128+
},
129+
"nbformat": 4,
130+
"nbformat_minor": 2
131+
}

python/packages/autogen-core/docs/src/user-guide/extensions-user-guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ create-your-own
2222
:caption: Guides
2323
2424
azure-container-code-executor
25+
azure-foundry-agent
2526
```
2627

2728
AutoGen is designed to be extensible. The `autogen-ext` package contains the built-in component implementations maintained by the AutoGen project.

python/packages/autogen-ext/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ dependencies = [
2222
anthropic = ["anthropic>=0.48"]
2323
langchain = ["langchain_core~= 0.3.3"]
2424
azure = [
25-
"azure-ai-inference>=1.0.0b7",
26-
"azure-ai-projects>=1.0.0b8",
25+
"azure-ai-inference>=1.0.0b9",
26+
"azure-ai-projects>=1.0.0b11",
2727
"azure-core",
2828
"azure-identity",
2929
"azure-search-documents>=11.4.0",

0 commit comments

Comments
 (0)