Skip to content

Commit b6a2e9c

Browse files
authored
Merge pull request #225 from koreyspace/main
upgraded to new project endpoint for AI Agents Samples
2 parents 255a020 + f1c6d4e commit b6a2e9c

File tree

8 files changed

+111
-31
lines changed

8 files changed

+111
-31
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GLOBAL_LLM_SERVICE="AzureOpenAI"
44
GITHUB_TOKEN="..."
55

66
# For Running Samples Using Azure AI Agent Service
7-
PROJECT_CONNECTION_STRING="..."
7+
PROJECT_ENDPOINT="..."
88

99
# Only Used For Running Samples Using Azure OpenAI Service + Azure Search
1010
AZURE_OPENAI_API_KEY="..."

00-course-setup/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ You should now be able to run the code samples of this course.
8787

8888
## Set Up for Samples using Azure AI Foundry and Azure AI Agent Service
8989

90-
### Step 1: Retrieve Your Azure Project Connection String
90+
### Step 1: Retrieve Your Azure Project Endpoint
9191

9292

9393
Follow the steps to creating a hub and project in Azure AI Foundry found here: [Hub resources overview](https://learn.microsoft.com/en-us/azure/ai-foundry/concepts/ai-resources)
@@ -97,7 +97,7 @@ Once you have created your project, you will need to retrieve the connection str
9797

9898
This can be done by going to the **Overview** page of your project in the Azure AI Foundry portal.
9999

100-
![Project Connection String](./images/project-connection-string.png)
100+
![Project Connection String](./images/project-endpoint.png)
101101

102102
### Step 2: Create Your `.env` File
103103

@@ -109,7 +109,7 @@ cp .env.example .env
109109

110110
This will copy the example file and create a `.env` in your directory and where you fill in the values for the environment variables.
111111

112-
With your token copied, open the `.env` file in your favorite text editor and paste your token into the `PROJECT_CONNECTION_STRING` field.
112+
With your token copied, open the `.env` file in your favorite text editor and paste your token into the `PROJECT_ENDPOINT` field.
113113

114114
### Step 3: Sign in to Azure
115115

58 KB
Loading

02-explore-agentic-frameworks/code_samples/02-autogen.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
],
159159
"metadata": {
160160
"kernelspec": {
161-
"display_name": ".venv",
161+
"display_name": "Python 3",
162162
"language": "python",
163163
"name": "python3"
164164
},
@@ -172,7 +172,7 @@
172172
"name": "python",
173173
"nbconvert_exporter": "python",
174174
"pygments_lexer": "ipython3",
175-
"version": "3.13.1"
175+
"version": "3.11.12"
176176
}
177177
},
178178
"nbformat": 4,

02-explore-agentic-frameworks/code_samples/02-azureaiagent.ipynb

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,67 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"metadata": {},
77
"outputs": [],
88
"source": [
99
"import os\n",
1010
"from dotenv import load_dotenv\n",
1111
"\n",
1212
"from azure.ai.projects import AIProjectClient\n",
13-
"from azure.ai.projects.models import CodeInterpreterTool\n",
13+
"from azure.ai.agents.models import CodeInterpreterTool\n",
1414
"from azure.identity import DefaultAzureCredential\n",
1515
"from typing import Any\n",
1616
"from pathlib import Path\n",
17-
"from datetime import datetime\n",
18-
"\n"
17+
"from datetime import datetime\n"
1918
]
2019
},
2120
{
2221
"cell_type": "code",
23-
"execution_count": null,
22+
"execution_count": 2,
2423
"metadata": {},
2524
"outputs": [],
2625
"source": [
2726
"load_dotenv()\n",
28-
"project_client = AIProjectClient.from_connection_string(\n",
29-
" credential=DefaultAzureCredential(), conn_str=os.environ[\"PROJECT_CONNECTION_STRING\"]\n",
27+
"project_endpoint = os.environ[\"PROJECT_ENDPOINT\"]\n",
28+
"\n",
29+
"project_client = AIProjectClient(\n",
30+
" endpoint=project_endpoint,\n",
31+
" # Use Azure Default Credential for authentication\n",
32+
" credential=DefaultAzureCredential(),\n",
3033
")"
3134
]
3235
},
3336
{
3437
"cell_type": "code",
3538
"execution_count": null,
3639
"metadata": {},
37-
"outputs": [],
40+
"outputs": [
41+
{
42+
"data": {
43+
"text/html": [
44+
"<h2>Azure AI Agent Execution</h2><div><strong>Created agent</strong> with ID: asst_BehQldbWIkw0LsJPj1N38FA8</div><div><strong>Created thread</strong> with ID: thread_cvWuXbcYkne8rovyAbzV8v1N</div><div style='margin:15px 0; padding:10px; background-color:#f5f5f5; border-left:4px solid #007bff; border-radius:4px;'><strong>User:</strong><br><div style='margin-left:15px'>Could you please create a bar chart for the operating profit using the following data and provide the file to me? Bali: 100 Travelers, Paris: 356 Travelers, London: 900 Travelers, Tokyo: 850 Travellers</div></div><div style='color:#007bff'><i>Processing request...</i></div>"
45+
],
46+
"text/plain": [
47+
"<IPython.core.display.HTML object>"
48+
]
49+
},
50+
"metadata": {},
51+
"output_type": "display_data"
52+
},
53+
{
54+
"ename": "AttributeError",
55+
"evalue": "'AgentsClient' object has no attribute 'list_messages'",
56+
"output_type": "error",
57+
"traceback": [
58+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
59+
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
60+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 137\u001b[39m\n\u001b[32m 134\u001b[39m display(Image(img_file))\n\u001b[32m 136\u001b[39m \u001b[38;5;66;03m# Execute the function\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m137\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m run_agent_with_visualization()\n",
61+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 58\u001b[39m, in \u001b[36mrun_agent_with_visualization\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 55\u001b[39m html_output += \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m<div style=\u001b[39m\u001b[33m'\u001b[39m\u001b[33mcolor:red\u001b[39m\u001b[33m'\u001b[39m\u001b[33m><strong>Run failed:</strong> \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrun.last_error\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m</div>\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 57\u001b[39m \u001b[38;5;66;03m# Get messages from the thread\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m58\u001b[39m messages = \u001b[43mproject_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43magents\u001b[49m\u001b[43m.\u001b[49m\u001b[43mlist_messages\u001b[49m(thread_id=thread.id)\n\u001b[32m 60\u001b[39m \u001b[38;5;66;03m# Format assistant response\u001b[39;00m\n\u001b[32m 61\u001b[39m html_output += \u001b[33m\"\u001b[39m\u001b[33m<div style=\u001b[39m\u001b[33m'\u001b[39m\u001b[33mmargin:15px 0; padding:10px; background-color:#f0f7ff; border-left:4px solid #28a745; border-radius:4px;\u001b[39m\u001b[33m'\u001b[39m\u001b[33m>\u001b[39m\u001b[33m\"\u001b[39m\n",
62+
"\u001b[31mAttributeError\u001b[39m: 'AgentsClient' object has no attribute 'list_messages'"
63+
]
64+
}
65+
],
3866
"source": [
3967
"from IPython.display import display, HTML, Image\n",
4068
"from pathlib import Path\n",
@@ -50,16 +78,17 @@
5078
" # The CodeInterpreterTool needs to be included in creation of the agent\n",
5179
" # Ensure to set the correct model name as deployed in Azure AI Foundry for your use case\n",
5280
" agent = project_client.agents.create_agent(\n",
53-
" model=\"gpt-4o-mini\",\n",
81+
" model=\"gpt-4o\",\n",
5482
" name=\"my-agent\",\n",
5583
" instructions=\"You are helpful agent\",\n",
5684
" tools=code_interpreter.definitions,\n",
57-
" tool_resources=code_interpreter.resources,\n",
5885
" )\n",
86+
"\n",
87+
" \n",
5988
" html_output += f\"<div><strong>Created agent</strong> with ID: {agent.id}</div>\"\n",
6089
"\n",
6190
" # Create a thread\n",
62-
" thread = project_client.agents.create_thread()\n",
91+
" thread = project_client.agents.threads.create()\n",
6392
" html_output += f\"<div><strong>Created thread</strong> with ID: {thread.id}</div>\"\n",
6493
"\n",
6594
" # User query - display nicely\n",
@@ -70,7 +99,7 @@
7099
" html_output += \"</div>\"\n",
71100
"\n",
72101
" # Create a message\n",
73-
" message = project_client.agents.create_message(\n",
102+
" message = project_client.agents.messages.create(\n",
74103
" thread_id=thread.id,\n",
75104
" role=\"user\",\n",
76105
" content=user_query,\n",
@@ -81,7 +110,7 @@
81110
" html_output + \"<div style='color:#007bff'><i>Processing request...</i></div>\"))\n",
82111
"\n",
83112
" # Execute the run\n",
84-
" run = project_client.agents.create_and_process_run(\n",
113+
" run = project_client.agents.runs.create_and_process(\n",
85114
" thread_id=thread.id, agent_id=agent.id)\n",
86115
"\n",
87116
" # Update status\n",
@@ -92,7 +121,7 @@
92121
" html_output += f\"<div style='color:red'><strong>Run failed:</strong> {run.last_error}</div>\"\n",
93122
"\n",
94123
" # Get messages from the thread\n",
95-
" messages = project_client.agents.list_messages(thread_id=thread.id)\n",
124+
" messages = project_client.agents.messages.list(thread_id=thread.id)\n",
96125
"\n",
97126
" # Format assistant response\n",
98127
" html_output += \"<div style='margin:15px 0; padding:10px; background-color:#f0f7ff; border-left:4px solid #28a745; border-radius:4px;'>\"\n",
@@ -191,7 +220,7 @@
191220
"name": "python",
192221
"nbconvert_exporter": "python",
193222
"pygments_lexer": "ipython3",
194-
"version": "3.13.1"
223+
"version": "3.12.11"
195224
}
196225
},
197226
"nbformat": 4,

02-explore-agentic-frameworks/code_samples/02-semantic-kernel.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
],
246246
"metadata": {
247247
"kernelspec": {
248-
"display_name": ".venv",
248+
"display_name": "Python 3",
249249
"language": "python",
250250
"name": "python3"
251251
},
@@ -259,7 +259,7 @@
259259
"name": "python",
260260
"nbconvert_exporter": "python",
261261
"pygments_lexer": "ipython3",
262-
"version": "3.11.11"
262+
"version": "3.11.12"
263263
}
264264
},
265265
"nbformat": 4,

04-tool-use/code_samples/04-semantic-kernel-tool.ipynb

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": null,
19+
"execution_count": 4,
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": null,
53+
"execution_count": 5,
5454
"metadata": {},
5555
"outputs": [],
5656
"source": [
@@ -96,7 +96,7 @@
9696
},
9797
{
9898
"cell_type": "code",
99-
"execution_count": null,
99+
"execution_count": 6,
100100
"metadata": {},
101101
"outputs": [],
102102
"source": [
@@ -124,7 +124,7 @@
124124
},
125125
{
126126
"cell_type": "code",
127-
"execution_count": null,
127+
"execution_count": 7,
128128
"metadata": {},
129129
"outputs": [],
130130
"source": [
@@ -152,9 +152,60 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": null,
155+
"execution_count": 8,
156156
"metadata": {},
157-
"outputs": [],
157+
"outputs": [
158+
{
159+
"data": {
160+
"text/html": [
161+
"<div style='margin-bottom:10px'><div style='font-weight:bold'>User:</div><div style='margin-left:20px'>What destinations are available?</div></div><div style='margin-bottom:20px'><div style='font-weight:bold'>TravelAgent:</div><div style='margin-left:20px; white-space:pre-wrap'>The available destinations are:\n",
162+
"\n",
163+
"1. Barcelona, Spain\n",
164+
"2. Paris, France\n",
165+
"3. Berlin, Germany\n",
166+
"4. Tokyo, Japan\n",
167+
"5. New York, USA</div></div><hr>"
168+
],
169+
"text/plain": [
170+
"<IPython.core.display.HTML object>"
171+
]
172+
},
173+
"metadata": {},
174+
"output_type": "display_data"
175+
},
176+
{
177+
"data": {
178+
"text/html": [
179+
"<div style='margin-bottom:10px'><div style='font-weight:bold'>User:</div><div style='margin-left:20px'>Is Barcelona available?</div></div><div style='margin-bottom:20px'><div style='font-weight:bold'>TravelAgent:</div><div style='margin-left:20px; white-space:pre-wrap'>Barcelona is currently unavailable. However, the following destinations are available:\n",
180+
"\n",
181+
"- Paris, France\n",
182+
"- Berlin, Germany\n",
183+
"- New York, USA</div></div><hr>"
184+
],
185+
"text/plain": [
186+
"<IPython.core.display.HTML object>"
187+
]
188+
},
189+
"metadata": {},
190+
"output_type": "display_data"
191+
},
192+
{
193+
"data": {
194+
"text/html": [
195+
"<div style='margin-bottom:10px'><div style='font-weight:bold'>User:</div><div style='margin-left:20px'>Are there any vacation destinations available not in Europe?</div></div><div style='margin-bottom:20px'><div style='font-weight:bold'>TravelAgent:</div><div style='margin-left:20px; white-space:pre-wrap'>The vacation destinations outside of Europe that are currently available are:\n",
196+
"\n",
197+
"- New York, USA\n",
198+
"\n",
199+
"Tokyo, Japan is unavailable.</div></div><hr>"
200+
],
201+
"text/plain": [
202+
"<IPython.core.display.HTML object>"
203+
]
204+
},
205+
"metadata": {},
206+
"output_type": "display_data"
207+
}
208+
],
158209
"source": [
159210
"user_inputs = [\n",
160211
" \"What destinations are available?\",\n",
@@ -253,7 +304,7 @@
253304
"name": "python",
254305
"nbconvert_exporter": "python",
255306
"pygments_lexer": "ipython3",
256-
"version": "3.11.11"
307+
"version": "3.12.11"
257308
}
258309
},
259310
"nbformat": 4,

05-agentic-rag/code_samples/05-semantic-kernel-azuresearch.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
"name": "python",
379379
"nbconvert_exporter": "python",
380380
"pygments_lexer": "ipython3",
381-
"version": "3.11.11"
381+
"version": "3.12.11"
382382
}
383383
},
384384
"nbformat": 4,

0 commit comments

Comments
 (0)