|
77 | 77 | }, |
78 | 78 | { |
79 | 79 | "cell_type": "code", |
80 | | - "execution_count": 1, |
| 80 | + "execution_count": null, |
81 | 81 | "id": "e42b4a10", |
82 | 82 | "metadata": {}, |
83 | 83 | "outputs": [], |
|
115 | 115 | }, |
116 | 116 | { |
117 | 117 | "cell_type": "code", |
118 | | - "execution_count": 2, |
| 118 | + "execution_count": null, |
119 | 119 | "id": "91fd6810", |
120 | 120 | "metadata": {}, |
121 | 121 | "outputs": [ |
|
185 | 185 | }, |
186 | 186 | { |
187 | 187 | "cell_type": "code", |
188 | | - "execution_count": 3, |
| 188 | + "execution_count": null, |
189 | 189 | "id": "f98f31e7", |
190 | 190 | "metadata": {}, |
191 | 191 | "outputs": [ |
|
222 | 222 | }, |
223 | 223 | { |
224 | 224 | "cell_type": "code", |
225 | | - "execution_count": 4, |
| 225 | + "execution_count": null, |
226 | 226 | "id": "fbe31e32", |
227 | 227 | "metadata": {}, |
228 | 228 | "outputs": [ |
|
281 | 281 | "execution_count": null, |
282 | 282 | "id": "6eb0ebd3", |
283 | 283 | "metadata": {}, |
284 | | - "outputs": [], |
| 284 | + "outputs": [ |
| 285 | + { |
| 286 | + "data": { |
| 287 | + "text/plain": [ |
| 288 | + "[{'id': 'asst_dI6i1SYCxMihj0uvsbGcLjQW', 'object': 'assistant', 'created_at': 1747758854, 'name': 'earth-search-agent', 'description': None, 'model': 'gpt-4o', 'instructions': '\\nA Q&A agent that can answer questions about the Earth at night.\\nYou must use your tools to answer every question\\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", |
| 289 | + " {'id': 'asst_ea1ZOJEEhfRxFUgfRVRUlCjy', 'object': 'assistant', 'created_at': 1747758145, '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", |
| 290 | + " {'id': 'asst_hGqUOtytuNRYLsF2Xr3GIzcV', 'object': 'assistant', 'created_at': 1747757976, '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", |
| 291 | + " {'id': 'asst_FTlEWjqrKtkdoFeMH8vyxL74', 'object': 'assistant', 'created_at': 1747705852, '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", |
| 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": 7, |
| 301 | + "metadata": {}, |
| 302 | + "output_type": "execute_result" |
| 303 | + } |
| 304 | + ], |
285 | 305 | "source": [ |
286 | 306 | "from azure.ai.projects import AIProjectClient\n", |
287 | 307 | "\n", |
|
292 | 312 | }, |
293 | 313 | { |
294 | 314 | "cell_type": "code", |
295 | | - "execution_count": 6, |
| 315 | + "execution_count": null, |
296 | 316 | "id": "aa363122", |
297 | 317 | "metadata": {}, |
298 | 318 | "outputs": [ |
|
307 | 327 | "source": [ |
308 | 328 | "instructions = \"\"\"\n", |
309 | 329 | "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", |
311 | 330 | "Sources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].\n", |
312 | 331 | "If you do not have the answer, respond with \"I don't know\".\n", |
313 | 332 | "\"\"\"\n", |
|
332 | 351 | }, |
333 | 352 | { |
334 | 353 | "cell_type": "code", |
335 | | - "execution_count": 7, |
| 354 | + "execution_count": null, |
336 | 355 | "id": "de2ee775", |
337 | 356 | "metadata": {}, |
338 | 357 | "outputs": [], |
|
377 | 396 | "functions = FunctionTool({ agentic_retrieval })\n", |
378 | 397 | "toolset = ToolSet()\n", |
379 | 398 | "toolset.add(functions)\n", |
380 | | - "project_client.agents.enable_auto_function_calls(tools=toolset)" |
| 399 | + "project_client.agents.enable_auto_function_calls(toolset)" |
381 | 400 | ] |
382 | 401 | }, |
383 | 402 | { |
|
394 | 413 | }, |
395 | 414 | { |
396 | 415 | "cell_type": "code", |
397 | | - "execution_count": 8, |
| 416 | + "execution_count": null, |
398 | 417 | "id": "f1fc04fc", |
399 | 418 | "metadata": {}, |
400 | 419 | "outputs": [ |
401 | 420 | { |
402 | 421 | "name": "stdout", |
403 | 422 | "output_type": "stream", |
404 | 423 | "text": [ |
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", |
| 424 | + "Agent response: Suburban belts display larger December brightening than urban cores due to differences in light sources and usage patterns\n", |
| 425 | + " Suburban lighting is often concentrated in residential and commercial areas with extensive decorative lighting during the holiday season, leading to larger seasonal brightening\n", |
| 426 | + " Urban cores, despite higher absolute light levels, may have a more consistent year-round light profile due to steady illumination from offices, industrial areas, and traffic systems [ref_id: 1]\n", |
408 | 427 | "\n", |
409 | 428 | "\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", |
| 429 | + "The Phoenix nighttime street grid is sharply visible from space because the city is designed along a regular grid of street blocks, a characteristic of western U\n", |
| 430 | + "S\n", |
| 431 | + " urban planning\n", |
| 432 | + " This grid, combined with widespread automobile use, results in extensive street lighting that defines the layout of the city vividly at night\n", |
| 433 | + " In contrast, large stretches of midwestern interstates between cities remain comparatively dim because highways typically lack dense lighting infrastructure and are less populated compared to urban areas where lighting clusters around streets, intersections, and residential zones [ref_id: 0][ref_id: 1]\n", |
413 | 434 | "\n" |
414 | 435 | ] |
415 | 436 | } |
416 | 437 | ], |
417 | 438 | "source": [ |
| 439 | + "from azure.ai.agents.models import AgentsNamedToolChoice, AgentsNamedToolChoiceType, FunctionName\n", |
| 440 | + "\n", |
418 | 441 | "message = project_client.agents.messages.create(\n", |
419 | 442 | " thread_id=thread.id,\n", |
420 | 443 | " role=\"user\",\n", |
|
427 | 450 | "run = project_client.agents.runs.create_and_process(\n", |
428 | 451 | " thread_id=thread.id,\n", |
429 | 452 | " agent_id=agent.id,\n", |
| 453 | + " tool_choice=AgentsNamedToolChoice(type=AgentsNamedToolChoiceType.FUNCTION, function=FunctionName(name=\"agentic_retrieval\")),\n", |
430 | 454 | " toolset=toolset)\n", |
431 | 455 | "if run.status == \"failed\":\n", |
432 | 456 | " raise RuntimeError(f\"Run failed: {run.last_error}\")\n", |
|
447 | 471 | }, |
448 | 472 | { |
449 | 473 | "cell_type": "code", |
450 | | - "execution_count": 9, |
| 474 | + "execution_count": null, |
451 | 475 | "id": "7b90fefa", |
452 | 476 | "metadata": {}, |
453 | 477 | "outputs": [ |
|
461 | 485 | " \"id\": 0,\n", |
462 | 486 | " \"type\": \"ModelQueryPlanning\",\n", |
463 | 487 | " \"input_tokens\": 1265,\n", |
464 | | - " \"output_tokens\": 276\n", |
| 488 | + " \"output_tokens\": 322\n", |
465 | 489 | " },\n", |
466 | 490 | " {\n", |
467 | 491 | " \"id\": 1,\n", |
468 | 492 | " \"type\": \"AzureSearchQuery\",\n", |
469 | 493 | " \"target_index\": \"earth_at_night\",\n", |
470 | 494 | " \"query\": {\n", |
471 | | - " \"search\": \"suburban belts December brightening urban cores comparison\"\n", |
| 495 | + " \"search\": \"December brightening in suburban belts vs urban cores\"\n", |
472 | 496 | " },\n", |
473 | | - " \"query_time\": \"2025-05-20T16:34:47.991Z\",\n", |
| 497 | + " \"query_time\": \"2025-05-20T17:00:25.483Z\",\n", |
474 | 498 | " \"count\": 0,\n", |
475 | | - " \"elapsed_ms\": 604\n", |
| 499 | + " \"elapsed_ms\": 697\n", |
476 | 500 | " },\n", |
477 | 501 | " {\n", |
478 | 502 | " \"id\": 2,\n", |
479 | 503 | " \"type\": \"AzureSearchQuery\",\n", |
480 | 504 | " \"target_index\": \"earth_at_night\",\n", |
481 | 505 | " \"query\": {\n", |
482 | | - " \"search\": \"Phoenix nighttime street grid visibility from space\"\n", |
| 506 | + " \"search\": \"Visibility of Phoenix nighttime street grid from space\"\n", |
483 | 507 | " },\n", |
484 | | - " \"query_time\": \"2025-05-20T16:34:48.365Z\",\n", |
| 508 | + " \"query_time\": \"2025-05-20T17:00:25.812Z\",\n", |
485 | 509 | " \"count\": 2,\n", |
486 | | - " \"elapsed_ms\": 361\n", |
| 510 | + " \"elapsed_ms\": 315\n", |
487 | 511 | " },\n", |
488 | 512 | " {\n", |
489 | 513 | " \"id\": 3,\n", |
490 | 514 | " \"type\": \"AzureSearchQuery\",\n", |
491 | 515 | " \"target_index\": \"earth_at_night\",\n", |
492 | 516 | " \"query\": {\n", |
493 | | - " \"search\": \"midwestern interstate dimness at night\"\n", |
| 517 | + " \"search\": \"Dimness of midwestern interstate stretches at night\"\n", |
494 | 518 | " },\n", |
495 | | - " \"query_time\": \"2025-05-20T16:34:48.665Z\",\n", |
| 519 | + " \"query_time\": \"2025-05-20T17:00:26.165Z\",\n", |
496 | 520 | " \"count\": 0,\n", |
497 | | - " \"elapsed_ms\": 300\n", |
| 521 | + " \"elapsed_ms\": 351\n", |
498 | 522 | " },\n", |
499 | 523 | " {\n", |
500 | 524 | " \"id\": 4,\n", |
501 | 525 | " \"type\": \"AzureSearchSemanticRanker\",\n", |
502 | | - " \"input_tokens\": 77948\n", |
| 526 | + " \"input_tokens\": 78294\n", |
503 | 527 | " }\n", |
504 | 528 | "]\n", |
505 | 529 | "Retrieval results\n", |
|
543 | 567 | }, |
544 | 568 | { |
545 | 569 | "cell_type": "code", |
546 | | - "execution_count": 10, |
| 570 | + "execution_count": null, |
547 | 571 | "id": "d9478191", |
548 | 572 | "metadata": {}, |
549 | 573 | "outputs": [ |
550 | 574 | { |
551 | 575 | "name": "stdout", |
552 | 576 | "output_type": "stream", |
553 | 577 | "text": [ |
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", |
| 578 | + "Agent response: To find lava at night, you can rely on satellite imagery that captures the glow from active lava flows\n", |
| 579 | + " Instruments like the VIIRS Day/Night Band (DNB) can detect thermal and infrared emissions from lava, even in low-light conditions\n", |
| 580 | + " Satellite systems such as Landsat 8 use thermal and infrared bands to distinguish between hot lava, cooling lava, and flows obscured by cloud cover\n", |
| 581 | + " This capability has been utilized to monitor volcanic activity at locations like Mount Etna (Sicily, Italy) and Kilauea (Hawaii), providing critical data for hazard assessment and emergency management [ref_id: 1][ref_id: 3][ref_id: 5]\n", |
557 | 582 | "\n" |
558 | 583 | ] |
559 | 584 | } |
|
565 | 590 | " content=\"How do I find lava at night? Use the retrieval tool to answer this question.\"\n", |
566 | 591 | ")\n", |
567 | 592 | "\n", |
568 | | - "run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, toolset=toolset)\n", |
| 593 | + "run = project_client.agents.runs.create_and_process(\n", |
| 594 | + " thread_id=thread.id,\n", |
| 595 | + " agent_id=agent.id,\n", |
| 596 | + " tool_choice=AgentsNamedToolChoice(type=AgentsNamedToolChoiceType.FUNCTION, function=FunctionName(name=\"agentic_retrieval\")),\n", |
| 597 | + " toolset=toolset)\n", |
569 | 598 | "if run.status == \"failed\":\n", |
570 | 599 | " raise RuntimeError(f\"Run failed: {run.last_error}\")\n", |
571 | 600 | "output = project_client.agents.messages.get_last_message_text_by_role(thread_id=thread.id, role=\"assistant\").text.value\n", |
572 | 601 | "\n", |
| 602 | + "\n", |
573 | 603 | "print(\"Agent response:\", output.replace(\".\", \"\\n\"))\n" |
574 | 604 | ] |
575 | 605 | }, |
|
583 | 613 | }, |
584 | 614 | { |
585 | 615 | "cell_type": "code", |
586 | | - "execution_count": 11, |
| 616 | + "execution_count": null, |
587 | 617 | "id": "c063c45e", |
588 | 618 | "metadata": {}, |
589 | 619 | "outputs": [ |
|
596 | 626 | " {\n", |
597 | 627 | " \"id\": 0,\n", |
598 | 628 | " \"type\": \"ModelQueryPlanning\",\n", |
599 | | - " \"input_tokens\": 1461,\n", |
600 | | - " \"output_tokens\": 320\n", |
| 629 | + " \"input_tokens\": 1495,\n", |
| 630 | + " \"output_tokens\": 319\n", |
601 | 631 | " },\n", |
602 | 632 | " {\n", |
603 | 633 | " \"id\": 1,\n", |
|
606 | 636 | " \"query\": {\n", |
607 | 637 | " \"search\": \"how to locate lava flows at night\"\n", |
608 | 638 | " },\n", |
609 | | - " \"query_time\": \"2025-05-20T16:35:03.973Z\",\n", |
| 639 | + " \"query_time\": \"2025-05-20T17:01:14.742Z\",\n", |
610 | 640 | " \"count\": 6,\n", |
611 | | - " \"elapsed_ms\": 512\n", |
| 641 | + " \"elapsed_ms\": 416\n", |
612 | 642 | " },\n", |
613 | 643 | " {\n", |
614 | 644 | " \"id\": 2,\n", |
|
617 | 647 | " \"query\": {\n", |
618 | 648 | " \"search\": \"best tools for finding lava at night\"\n", |
619 | 649 | " },\n", |
620 | | - " \"query_time\": \"2025-05-20T16:35:04.297Z\",\n", |
| 650 | + " \"query_time\": \"2025-05-20T17:01:15.101Z\",\n", |
621 | 651 | " \"count\": 0,\n", |
622 | | - " \"elapsed_ms\": 311\n", |
| 652 | + " \"elapsed_ms\": 346\n", |
623 | 653 | " },\n", |
624 | 654 | " {\n", |
625 | 655 | " \"id\": 3,\n", |
|
628 | 658 | " \"query\": {\n", |
629 | 659 | " \"search\": \"safety tips for finding lava at night\"\n", |
630 | 660 | " },\n", |
631 | | - " \"query_time\": \"2025-05-20T16:35:04.605Z\",\n", |
| 661 | + " \"query_time\": \"2025-05-20T17:01:15.538Z\",\n", |
632 | 662 | " \"count\": 0,\n", |
633 | | - " \"elapsed_ms\": 306\n", |
| 663 | + " \"elapsed_ms\": 436\n", |
634 | 664 | " },\n", |
635 | 665 | " {\n", |
636 | 666 | " \"id\": 4,\n", |
637 | 667 | " \"type\": \"AzureSearchSemanticRanker\",\n", |
638 | | - " \"input_tokens\": 72052\n", |
| 668 | + " \"input_tokens\": 71809\n", |
639 | 669 | " }\n", |
640 | 670 | "]\n", |
641 | 671 | "Retrieval results\n", |
|
711 | 741 | }, |
712 | 742 | { |
713 | 743 | "cell_type": "code", |
714 | | - "execution_count": 12, |
| 744 | + "execution_count": null, |
715 | 745 | "id": "d67f8609", |
716 | 746 | "metadata": {}, |
717 | 747 | "outputs": [ |
|
739 | 769 | }, |
740 | 770 | { |
741 | 771 | "cell_type": "code", |
742 | | - "execution_count": 13, |
| 772 | + "execution_count": null, |
743 | 773 | "id": "d9895f27", |
744 | 774 | "metadata": {}, |
745 | 775 | "outputs": [ |
|
0 commit comments