Skip to content

Commit b94b97e

Browse files
committed
update
1 parent 86479bc commit b94b97e

File tree

2 files changed

+53
-106
lines changed

2 files changed

+53
-106
lines changed

agentic-retrieval-pipeline-example/agent-example.ipynb

Lines changed: 52 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@
5656
"\n",
5757
"You can find endpoints for Azure AI Search and Azure OpenAI in the [Azure portal](https://portal.azure.com).\n",
5858
"\n",
59-
"You can find the project connection string in the Azure AI Foundry portal:\n",
59+
"You can find the project endpoint in the Azure AI Foundry portal:\n",
6060
"\n",
6161
"1. Sign in to the [Azure AI Foundry portal](https://ai.azure.com) and open your project. \n",
6262
"\n",
63-
"1. In the **Project details** tile, find and copy the **Project connection string**. \n",
63+
"1. In the **Overview** tile, find and copy the **Azure AI Foundry project endpoint**. \n",
6464
"\n",
65-
" A hypothetical connection string might look like this: `eastus2.api.azureml.ms;00000000-0000-0000-0000-0000000000;rg-my-resource-group-name;my-foundry-project-name`\n",
66-
"\n",
67-
"1. Check the authentication type for your Azure OpenAI resource and make sure it uses an API key shared to all projects. Still in **Project details**, expand the **Connected resources** tile to view the authentication type for your Azure OpenAI resource.\n",
68-
"\n",
69-
"If you don't have an Azure OpenAI resource in your Foundry project, revisit the model deployment prerequisite. A connection to the resource is created when you deploy a model.\n"
65+
" A hypothetical endpoint might look like this: `https://your-foundry-resource.services.ai.azure.com/api/projects/your-foundry-project`"
7066
]
7167
},
7268
{
@@ -189,7 +185,7 @@
189185
},
190186
{
191187
"cell_type": "code",
192-
"execution_count": 4,
188+
"execution_count": 3,
193189
"id": "f98f31e7",
194190
"metadata": {},
195191
"outputs": [
@@ -226,7 +222,7 @@
226222
},
227223
{
228224
"cell_type": "code",
229-
"execution_count": 3,
225+
"execution_count": 4,
230226
"id": "fbe31e32",
231227
"metadata": {},
232228
"outputs": [
@@ -282,26 +278,10 @@
282278
},
283279
{
284280
"cell_type": "code",
285-
"execution_count": 4,
281+
"execution_count": null,
286282
"id": "6eb0ebd3",
287283
"metadata": {},
288-
"outputs": [
289-
{
290-
"data": {
291-
"text/plain": [
292-
"[{'id': 'asst_X7JMxX1SW6EYuovQn6WZobeN', 'object': 'assistant', 'created_at': 1747705233, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nSources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].\\nIf you do not have the answer, respond with \"I don\\'t know\".\\n', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'},\n",
293-
" {'id': 'asst_bFc7GdLyN96HS1BII3mTfc1O', 'object': 'assistant', 'created_at': 1747705029, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nSources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].\\nIf you do not have the answer, respond with \"I don\\'t know\".\\n', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'},\n",
294-
" {'id': 'asst_DAcq0xRvJroakPMxCQ30qW5n', 'object': 'assistant', 'created_at': 1747704511, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nSources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].\\nIf you do not have the answer, respond with \"I don\\'t know\".\\n', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'},\n",
295-
" {'id': 'asst_L6Qdwc5dvghAZ1Z7xeM1RsDb', 'object': 'assistant', 'created_at': 1747703597, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nSources have a JSON format with a ref_id that must be cited in the answer.\\nIf you do not have the answer, respond with \"I don\\'t know\".\\n', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'},\n",
296-
" {'id': 'asst_8l6Md1sf5Hh4A3FuF5p9NsBx', 'object': 'assistant', 'created_at': 1747703585, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nSources have a JSON format with a ref_id that must be cited in the answer.\\nIf you do not have the answer, respond with \"I don\\'t know\".\\n', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'},\n",
297-
" {'id': 'asst_IVF9BRKXJYK4Z6fSPrZByQKD', 'object': 'assistant', 'created_at': 1747701537, 'name': 'Agent638', 'description': None, 'model': 'gpt-4o', 'instructions': '', 'tools': [], 'top_p': 1.0, 'temperature': 1.0, 'tool_resources': {}, 'metadata': {}, 'response_format': 'auto'}]"
298-
]
299-
},
300-
"execution_count": 4,
301-
"metadata": {},
302-
"output_type": "execute_result"
303-
}
304-
],
284+
"outputs": [],
305285
"source": [
306286
"from azure.ai.projects import AIProjectClient\n",
307287
"\n",
@@ -312,7 +292,7 @@
312292
},
313293
{
314294
"cell_type": "code",
315-
"execution_count": 5,
295+
"execution_count": 6,
316296
"id": "aa363122",
317297
"metadata": {},
318298
"outputs": [
@@ -327,6 +307,7 @@
327307
"source": [
328308
"instructions = \"\"\"\n",
329309
"A Q&A agent that can answer questions about the Earth at night.\n",
310+
"You must use your tools to answer every question\n",
330311
"Sources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].\n",
331312
"If you do not have the answer, respond with \"I don't know\".\n",
332313
"\"\"\"\n",
@@ -351,7 +332,7 @@
351332
},
352333
{
353334
"cell_type": "code",
354-
"execution_count": 15,
335+
"execution_count": 7,
355336
"id": "de2ee775",
356337
"metadata": {},
357338
"outputs": [],
@@ -413,25 +394,22 @@
413394
},
414395
{
415396
"cell_type": "code",
416-
"execution_count": 17,
397+
"execution_count": 8,
417398
"id": "f1fc04fc",
418399
"metadata": {},
419400
"outputs": [
420401
{
421402
"name": "stdout",
422403
"output_type": "stream",
423404
"text": [
424-
"Agent response: 1\n",
425-
" **Why do suburban belts display larger December brightening than urban cores even though absolute light levels are higher downtown?**\n",
426-
" This phenomenon likely reflects seasonal increases in localized residential lighting in suburban areas due to holiday decorations, such as string lights on houses and trees, which are less common in dense urban cores\n",
427-
" Downtown areas tend to have more consistent light levels year-round due to commercial and industrial lighting that does not vary significantly seasonally [ref_id:0]\n",
405+
"Agent response: Suburban belts show larger December brightening compared to urban cores due to differences in lighting usage and patterns\n",
406+
" Suburbs often feature residential street lighting and larger areas dedicated to parking lots, strip malls, and other retail spaces that increase lighting during holiday times\n",
407+
" Conversely, urban cores, despite higher absolute light levels, have multistory buildings and concentrated lighting that don't scale as dramatically during seasonal periods [0]\n",
428408
"\n",
429409
"\n",
430-
"2\n",
431-
" **Why is the Phoenix nighttime street grid so sharply visible from space, while large stretches of the interstate between midwestern cities remain comparatively dim?**\n",
432-
" The Phoenix metropolitan area is characterized by a highly organized grid-like structure of blocks and streets, which are illuminated by streetlights throughout the urban and suburban zones\n",
433-
" Additionally, areas along the Grand Avenue and at intersections often have shopping centers and gas stations that contribute to brighter lighting\n",
434-
" Midwestern interstates, in contrast, traverse less densely populated regions between cities where illumination is limited to occasional spots such as rest areas or exits, leading to a less pronounced visibility of the roadway lighting from space [ref_id:1][ref_id:2]\n",
410+
"The Phoenix nighttime street grid is sharply visible from space due to its well-organized urban layout with uniform street lighting\n",
411+
" The grid is illuminated by streetlights, commercial properties, and gas stations at major intersections, creating an easily identifiable pattern from orbit\n",
412+
" In contrast, stretches of interstates between Midwestern cities tend to be dim because they're primarily surrounded by open countryside or agricultural lands, lacking dense urban development or consistent lighting [1]\n",
435413
"\n"
436414
]
437415
}
@@ -446,7 +424,10 @@
446424
" \"\"\"\n",
447425
")\n",
448426
"\n",
449-
"run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, toolset=toolset)\n",
427+
"run = project_client.agents.runs.create_and_process(\n",
428+
" thread_id=thread.id,\n",
429+
" agent_id=agent.id,\n",
430+
" toolset=toolset)\n",
450431
"if run.status == \"failed\":\n",
451432
" raise RuntimeError(f\"Run failed: {run.last_error}\")\n",
452433
"output = project_client.agents.messages.get_last_message_text_by_role(thread_id=thread.id, role=\"assistant\").text.value\n",
@@ -480,7 +461,7 @@
480461
" \"id\": 0,\n",
481462
" \"type\": \"ModelQueryPlanning\",\n",
482463
" \"input_tokens\": 1265,\n",
483-
" \"output_tokens\": 277\n",
464+
" \"output_tokens\": 276\n",
484465
" },\n",
485466
" {\n",
486467
" \"id\": 1,\n",
@@ -489,9 +470,9 @@
489470
" \"query\": {\n",
490471
" \"search\": \"suburban belts December brightening urban cores comparison\"\n",
491472
" },\n",
492-
" \"query_time\": \"2025-05-13T22:22:45.368Z\",\n",
473+
" \"query_time\": \"2025-05-20T16:34:47.991Z\",\n",
493474
" \"count\": 0,\n",
494-
" \"elapsed_ms\": 350\n",
475+
" \"elapsed_ms\": 604\n",
495476
" },\n",
496477
" {\n",
497478
" \"id\": 2,\n",
@@ -500,32 +481,32 @@
500481
" \"query\": {\n",
501482
" \"search\": \"Phoenix nighttime street grid visibility from space\"\n",
502483
" },\n",
503-
" \"query_time\": \"2025-05-13T22:22:45.682Z\",\n",
484+
" \"query_time\": \"2025-05-20T16:34:48.365Z\",\n",
504485
" \"count\": 2,\n",
505-
" \"elapsed_ms\": 304\n",
486+
" \"elapsed_ms\": 361\n",
506487
" },\n",
507488
" {\n",
508489
" \"id\": 3,\n",
509490
" \"type\": \"AzureSearchQuery\",\n",
510491
" \"target_index\": \"earth_at_night\",\n",
511492
" \"query\": {\n",
512-
" \"search\": \"interstate visibility from space midwestern cities\"\n",
493+
" \"search\": \"midwestern interstate dimness at night\"\n",
513494
" },\n",
514-
" \"query_time\": \"2025-05-13T22:22:45.977Z\",\n",
515-
" \"count\": 2,\n",
516-
" \"elapsed_ms\": 291\n",
495+
" \"query_time\": \"2025-05-20T16:34:48.665Z\",\n",
496+
" \"count\": 0,\n",
497+
" \"elapsed_ms\": 300\n",
517498
" },\n",
518499
" {\n",
519500
" \"id\": 4,\n",
520501
" \"type\": \"AzureSearchSemanticRanker\",\n",
521-
" \"input_tokens\": 74224\n",
502+
" \"input_tokens\": 77948\n",
522503
" }\n",
523504
"]\n",
524505
"Retrieval results\n",
525506
"[\n",
526507
" {\n",
527508
" \"type\": \"AzureSearchDoc\",\n",
528-
" \"id\": \"2\",\n",
509+
" \"id\": \"1\",\n",
529510
" \"activity_source\": 2,\n",
530511
" \"doc_key\": \"earth_at_night_508_page_104_verbalized\"\n",
531512
" },\n",
@@ -534,24 +515,13 @@
534515
" \"id\": \"0\",\n",
535516
" \"activity_source\": 2,\n",
536517
" \"doc_key\": \"earth_at_night_508_page_105_verbalized\"\n",
537-
" },\n",
538-
" {\n",
539-
" \"type\": \"AzureSearchDoc\",\n",
540-
" \"id\": \"3\",\n",
541-
" \"activity_source\": 3,\n",
542-
" \"doc_key\": \"earth_at_night_508_page_125_verbalized\"\n",
543-
" },\n",
544-
" {\n",
545-
" \"type\": \"AzureSearchDoc\",\n",
546-
" \"id\": \"1\",\n",
547-
" \"activity_source\": 3,\n",
548-
" \"doc_key\": \"earth_at_night_508_page_124_verbalized\"\n",
549518
" }\n",
550519
"]\n"
551520
]
552521
}
553522
],
554523
"source": [
524+
"import json\n",
555525
"\n",
556526
"retrieval_result = retrieval_results.get(message.id)\n",
557527
"if retrieval_result is None:\n",
@@ -581,48 +551,25 @@
581551
"name": "stdout",
582552
"output_type": "stream",
583553
"text": [
584-
"Agent response: To find lava at night, you can take advantage of various natural and technological methods:\n",
585-
"\n",
586-
"1\n",
587-
" **Natural Glow**: Active lava flows produce a significant glow, which can be visible from a distance at night\n",
588-
" Under good visibility conditions, the bright red-orange light of flowing lava can be seen against the darker landscape\n",
589-
" Observing this from higher vantage points or from areas with minimal light pollution can enhance visibility\n",
590-
"\n",
591-
"\n",
592-
"2\n",
593-
" **Satellite Imagery**: During nighttime, satellites equipped with capabilities like the VIIRS (Visible Infrared Imaging Radiometer Suite) can capture images of areas with volcanic activity\n",
594-
" These images show the glow of active lava flows clearly against the background, which highlights volcanic eruptions and their effects\n",
595-
" For example, images of Mount Etna and Kilauea have shown their lava flows brightly illuminated at night (Source: ref_id 1, ref_id 4)\n",
596-
"\n",
597-
"\n",
598-
"3\n",
599-
" **Infrared Imaging**: Thermal imaging can also assist in identifying hot lava spots\n",
600-
" This method utilizes infrared sensors to detect heat emitted by lava flows, making it effective even in darkness\n",
601-
" Satellites and drones equipped with thermal cameras can provide detailed imagery showing lava flows and their progression\n",
602-
"\n",
603-
"\n",
604-
"4\n",
605-
" **Safety Considerations**: While observing lava, always prioritize safety\n",
606-
" Ensure you are at a safe distance from volcanic activity and follow any guidance from local authorities regarding volcanic eruptions\n",
607-
"\n",
608-
"\n",
609-
"In summary, you can find lava at night by looking for its natural glow, using satellite imagery and infrared sensors, and ensuring a safe viewing approach\n",
554+
"Agent response: To find lava at night, monitor glowing lava flows near active volcanic sites using satellite imagery or specialized instruments like the VIIRS Day/Night Band (DNB) and thermal sensors\n",
555+
" These tools can detect bright red or orange emissions specific to lava flows, even under moonlight or faint natural illumination\n",
556+
" For instance, eruptions like at Mount Etna and Kilauea are often observed using such technologies, highlighting the thermal infrared glow and visible lava flow patterns against the backdrop of city lights or natural landscapes [0][1][4]\n",
610557
"\n"
611558
]
612559
}
613560
],
614561
"source": [
615-
"message = project_client.agents.create_message(\n",
562+
"message = project_client.agents.messages.create(\n",
616563
" thread_id=thread.id,\n",
617564
" role=\"user\",\n",
618-
" content=\"How do I find lava at night?\"\n",
565+
" content=\"How do I find lava at night? Use the retrieval tool to answer this question.\"\n",
619566
")\n",
620567
"\n",
621-
"run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id, toolset=toolset)\n",
568+
"run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, toolset=toolset)\n",
622569
"if run.status == \"failed\":\n",
623570
" raise RuntimeError(f\"Run failed: {run.last_error}\")\n",
571+
"output = project_client.agents.messages.get_last_message_text_by_role(thread_id=thread.id, role=\"assistant\").text.value\n",
624572
"\n",
625-
"output = project_client.agents.list_messages(thread_id=thread.id).get_last_text_message_by_role(\"assistant\").text.value\n",
626573
"print(\"Agent response:\", output.replace(\".\", \"\\n\"))\n"
627574
]
628575
},
@@ -649,8 +596,8 @@
649596
" {\n",
650597
" \"id\": 0,\n",
651598
" \"type\": \"ModelQueryPlanning\",\n",
652-
" \"input_tokens\": 1565,\n",
653-
" \"output_tokens\": 299\n",
599+
" \"input_tokens\": 1461,\n",
600+
" \"output_tokens\": 320\n",
654601
" },\n",
655602
" {\n",
656603
" \"id\": 1,\n",
@@ -659,36 +606,36 @@
659606
" \"query\": {\n",
660607
" \"search\": \"how to locate lava flows at night\"\n",
661608
" },\n",
662-
" \"query_time\": \"2025-05-13T22:23:07.269Z\",\n",
609+
" \"query_time\": \"2025-05-20T16:35:03.973Z\",\n",
663610
" \"count\": 6,\n",
664-
" \"elapsed_ms\": 376\n",
611+
" \"elapsed_ms\": 512\n",
665612
" },\n",
666613
" {\n",
667614
" \"id\": 2,\n",
668615
" \"type\": \"AzureSearchQuery\",\n",
669616
" \"target_index\": \"earth_at_night\",\n",
670617
" \"query\": {\n",
671-
" \"search\": \"best tools for viewing lava at night\"\n",
618+
" \"search\": \"best tools for finding lava at night\"\n",
672619
" },\n",
673-
" \"query_time\": \"2025-05-13T22:23:07.575Z\",\n",
674-
" \"count\": 1,\n",
675-
" \"elapsed_ms\": 293\n",
620+
" \"query_time\": \"2025-05-20T16:35:04.297Z\",\n",
621+
" \"count\": 0,\n",
622+
" \"elapsed_ms\": 311\n",
676623
" },\n",
677624
" {\n",
678625
" \"id\": 3,\n",
679626
" \"type\": \"AzureSearchQuery\",\n",
680627
" \"target_index\": \"earth_at_night\",\n",
681628
" \"query\": {\n",
682-
" \"search\": \"safety tips for exploring lava at night\"\n",
629+
" \"search\": \"safety tips for finding lava at night\"\n",
683630
" },\n",
684-
" \"query_time\": \"2025-05-13T22:23:07.857Z\",\n",
631+
" \"query_time\": \"2025-05-20T16:35:04.605Z\",\n",
685632
" \"count\": 0,\n",
686-
" \"elapsed_ms\": 281\n",
633+
" \"elapsed_ms\": 306\n",
687634
" },\n",
688635
" {\n",
689636
" \"id\": 4,\n",
690637
" \"type\": \"AzureSearchSemanticRanker\",\n",
691-
" \"input_tokens\": 70920\n",
638+
" \"input_tokens\": 72052\n",
692639
" }\n",
693640
"]\n",
694641
"Retrieval results\n",

agentic-retrieval-pipeline-example/sample.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROJECT_CONNECTION_STRING=<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<HubName>
1+
PROJECT_ENDPOINT=https://your-foundry-resource.services.ai.azure.com/api/projects/your-foundry-project
22
AZURE_OPENAI_ENDPOINT=https://your-openai-service.openai.azure.com
33
AZURE_OPENAI_GPT_DEPLOYMENT=gpt-4o-mini
44
AZURE_SEARCH_ENDPOINT=https://your-search-service.search.windows.net

0 commit comments

Comments
 (0)