From 2e4fc68217df6bb622909a343805df204d2ce4d4 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 14:20:15 -0700 Subject: [PATCH 01/24] upse agent endpoints --- sdk/ai/azure-ai-projects/assets.json | 2 +- .../samples/agents/agent_retrieve_helper.py | 69 -------- .../samples/agents/sample_agent_basic.py | 76 ++++----- .../agents/sample_agent_basic_async.py | 22 ++- .../agents/sample_agent_retrieve_basic.py | 26 +-- .../sample_agent_retrieve_basic_async.py | 35 +++- .../agents/sample_agent_stream_events.py | 21 ++- .../agents/sample_agent_structured_output.py | 21 ++- .../sample_agent_structured_output_async.py | 20 +-- ..._agent_basic_with_azure_monitor_tracing.py | 27 +-- ...sample_agent_basic_with_console_tracing.py | 26 +-- .../samples/agents/telemetry/util.py | 23 +++ .../agents/tools/sample_agent_ai_search.py | 95 ++++++----- .../tools/sample_agent_azure_function.py | 41 ++--- .../tools/sample_agent_bing_custom_search.py | 89 +++++----- .../tools/sample_agent_bing_grounding.py | 81 ++++----- .../tools/sample_agent_browser_automation.py | 85 +++++----- .../tools/sample_agent_code_interpreter.py | 77 +++++---- .../sample_agent_code_interpreter_async.py | 77 +++++---- .../agents/tools/sample_agent_computer_use.py | 154 ++++++++--------- .../tools/sample_agent_computer_use_async.py | 160 +++++++++--------- .../agents/tools/sample_agent_fabric.py | 85 +++++----- .../agents/tools/sample_agent_fabric_iq.py | 39 +++-- .../tools/sample_agent_fabric_iq_async.py | 39 ++--- .../tools/sample_agent_function_tool.py | 88 +++++----- .../tools/sample_agent_function_tool_async.py | 85 +++++----- .../tools/sample_agent_image_generation.py | 71 ++++---- .../sample_agent_image_generation_async.py | 73 ++++---- .../samples/agents/tools/sample_agent_mcp.py | 99 +++++------ .../agents/tools/sample_agent_mcp_async.py | 102 +++++------ ...ample_agent_mcp_with_project_connection.py | 100 +++++------ ...agent_mcp_with_project_connection_async.py | 104 ++++++------ .../tools/sample_agent_memory_search.py | 94 +++++----- .../tools/sample_agent_memory_search_async.py | 111 ++++++------ .../agents/tools/sample_agent_openapi.py | 38 ++--- ...e_agent_openapi_with_project_connection.py | 40 ++--- .../agents/tools/sample_agent_sharepoint.py | 93 +++++----- .../agents/tools/sample_agent_to_agent.py | 85 +++++----- .../tools/sample_agent_toolbox_skill.py | 76 +++++---- .../agents/tools/sample_agent_web_search.py | 97 ++++++----- .../tools/sample_agent_web_search_preview.py | 104 ++++++------ ...ple_agent_web_search_with_custom_search.py | 106 ++++++------ .../agents/tools/sample_agent_work_iq.py | 39 +++-- .../tools/sample_agent_work_iq_async.py | 39 ++--- .../sample_toolboxes_with_search_preview.py | 66 ++++---- ...ple_toolboxes_with_search_preview_async.py | 68 ++++---- .../samples/agents/tools/util.py | 23 +++ .../azure-ai-projects/samples/agents/util.py | 23 +++ sdk/ai/azure-ai-projects/samples/util.py | 125 +++++++++++++- 49 files changed, 1787 insertions(+), 1552 deletions(-) delete mode 100644 sdk/ai/azure-ai-projects/samples/agents/agent_retrieve_helper.py create mode 100644 sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py create mode 100644 sdk/ai/azure-ai-projects/samples/agents/tools/util.py create mode 100644 sdk/ai/azure-ai-projects/samples/agents/util.py diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 3a0bb4a43b15..b90eac7d41a5 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_c84bf9341a" + "Tag": "python/ai/azure-ai-projects_8013d08d61" } diff --git a/sdk/ai/azure-ai-projects/samples/agents/agent_retrieve_helper.py b/sdk/ai/azure-ai-projects/samples/agents/agent_retrieve_helper.py deleted file mode 100644 index a1efd3b86a52..000000000000 --- a/sdk/ai/azure-ai-projects/samples/agents/agent_retrieve_helper.py +++ /dev/null @@ -1,69 +0,0 @@ -# pylint: disable=name-too-long -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ -"""Helper utilities for retrieve samples. - -This module centralizes setup used by the retrieve samples. It provides a -context manager that creates an agent version and conversation, yields -their identifiers for retrieve/get demonstrations, and performs agent cleanup -when the context exits. -""" - -from contextlib import contextmanager, asynccontextmanager -from typing import Generator, AsyncGenerator - -from azure.ai.projects.models import PromptAgentDefinition -from azure.ai.projects import AIProjectClient -from azure.ai.projects.aio import AIProjectClient as AsyncAIProjectClient - - -@contextmanager -def create_and_retrieve_agent_and_conversation( - project_client: AIProjectClient, model: str -) -> Generator[tuple[str, str], None, None]: - - with (project_client.get_openai_client() as openai_client,): - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=model, - instructions="You are a helpful assistant.", - ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - conversation = openai_client.conversations.create() - print(f"Conversation created (id: {conversation.id})") - - try: - yield agent.name, conversation.id - finally: - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") - - -@asynccontextmanager -async def create_and_retrieve_agent_and_conversation_async( - project_client: AsyncAIProjectClient, model: str -) -> AsyncGenerator[tuple[str, str], None]: - - async with (project_client.get_openai_client() as openai_client,): - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=model, - instructions="You are a helpful assistant.", - ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - conversation = await openai_client.conversations.create() - print(f"Conversation created (id: {conversation.id})") - - try: - yield agent.name, conversation.id - finally: - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py index 260902b53c4b..f27a5c2a8043 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py @@ -29,6 +29,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition @@ -36,47 +37,44 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - - with project_client.get_openai_client() as openai_client: - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - conversation = openai_client.conversations.create( - items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", ) - print(f"Created conversation with initial user message (id: {conversation.id})") - - response = openai_client.responses.create( - conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - openai_client.conversations.items.create( - conversation_id=conversation.id, - items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], - ) - print("Added a second user message to the conversation") - - response = openai_client.responses.create( - conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - openai_client.conversations.delete(conversation_id=conversation.id) - print("Conversation deleted") - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + conversation = openai_client.conversations.create( + items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], + ) + print(f"Created conversation with initial user message (id: {conversation.id})") + + response = openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + openai_client.conversations.items.create( + conversation_id=conversation.id, + items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], + ) + print("Added a second user message to the conversation") + + response = openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + openai_client.conversations.delete(conversation_id=conversation.id) + print("Conversation deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py index 3936a1aec2e6..20af98c88582 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py @@ -30,6 +30,7 @@ import asyncio import os from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition @@ -37,23 +38,25 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, - ): - - agent = await project_client.agents.create_version( - agent_name="MyAgent", + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions.", ), - ) - print(f"Agent created (name: {agent.name}, id: {agent.id}, version: {agent.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (name: {agent.name}, id: {agent.id}, version: {agent.versions.latest.version})") conversation = await openai_client.conversations.create( items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], @@ -62,7 +65,6 @@ async def main() -> None: response = await openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") @@ -74,16 +76,12 @@ async def main() -> None: response = await openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") await openai_client.conversations.delete(conversation_id=conversation.id) print("Conversation deleted") - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") - if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py index c1f456866c9e..cfcc8200e3be 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py @@ -30,33 +30,38 @@ import os from dotenv import load_dotenv -from agent_retrieve_helper import create_and_retrieve_agent_and_conversation # pylint: disable=import-error +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient +from azure.ai.projects.models import PromptAgentDefinition load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model = os.environ["FOUNDRY_MODEL_NAME"] - +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - # Creates prerequisite resources and yields (agent_name, conversation_id). - # Then automatically deletes the created agent version when this context manager exits. - create_and_retrieve_agent_and_conversation(project_client=project_client, model=model) as ( - agent_name, - conversation_id, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=model, + instructions="You are a helpful assistant.", + ), ), - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + conversation = openai_client.conversations.create() + print(f"Conversation created (id: {conversation.id})") # Retrieve latest version for the prerequisite agent. - agent = project_client.agents.get(agent_name=agent_name) print(f"Agent retrieved (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Retrieve the prerequisite conversation. - conversation = openai_client.conversations.retrieve(conversation_id=conversation_id) + conversation = openai_client.conversations.retrieve(conversation_id=conversation.id) print(f"Retrieved conversation (id: {conversation.id})") # Add a new user text message to the conversation @@ -68,6 +73,5 @@ response = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py index 8c6491746f70..d1ff140e8041 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py @@ -30,36 +30,54 @@ import os import asyncio +import sys +from pathlib import Path from dotenv import load_dotenv -from agent_retrieve_helper import create_and_retrieve_agent_and_conversation_async # pylint: disable=import-error +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient +from azure.ai.projects.models import PromptAgentDefinition + +_SAMPLES_DIR = Path(__file__).resolve().parents[1] +if str(_SAMPLES_DIR) not in sys.path: + sys.path.insert(0, str(_SAMPLES_DIR)) load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model = os.environ["FOUNDRY_MODEL_NAME"] +agent_name = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - # Creates prerequisite resources and yields (agent_name, conversation_id). - # Then automatically deletes the created agent version when this context manager exits. - create_and_retrieve_agent_and_conversation_async(project_client=project_client, model=model) as ( - agent_name, - conversation_id, + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=model, + instructions="You are a helpful assistant.", + ), ), - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent_version = await project_client.agents.get(agent_name=agent_name) + print( + f"Agent created (id: {agent_version.id}, name: {agent_version.name}, " + f"version: {agent_version.versions.latest.version})" + ) + + conversation = await openai_client.conversations.create() + print(f"Conversation created (id: {conversation.id})") # Retrieve latest version for the prerequisite agent. agent = await project_client.agents.get(agent_name=agent_name) print(f"Agent retrieved (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Retrieve the prerequisite conversation. - conversation = await openai_client.conversations.retrieve(conversation_id=conversation_id) + conversation = await openai_client.conversations.retrieve(conversation_id=conversation.id) print(f"Retrieved conversation (id: {conversation.id})") # Add a new user text message to the conversation @@ -71,7 +89,6 @@ async def main(): response = await openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py index 417baa7d3ee5..b4e8bc5c0a94 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py @@ -29,6 +29,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition @@ -36,21 +37,23 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, -): - - agent = project_client.agents.create_version( - agent_name="MyAgent", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions", ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create( items=[{"type": "message", "role": "user", "content": "Tell me about the capital city of France"}], @@ -59,7 +62,6 @@ with openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, stream=True, ) as response_stream_events: @@ -75,6 +77,3 @@ openai_client.conversations.delete(conversation_id=conversation.id) print("Conversation deleted") - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py index 5579038bac2c..f927d1c2bf3a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py @@ -33,6 +33,7 @@ import os from dotenv import load_dotenv from pydantic import BaseModel, Field +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -52,15 +53,14 @@ class CalendarEvent(BaseModel): endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, -): - - agent = project_client.agents.create_version( - agent_name="MyAgent", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], text=PromptAgentDefinitionTextOptions( @@ -71,8 +71,11 @@ class CalendarEvent(BaseModel): and returns it in the desired structured output format. """, ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create( items=[ @@ -87,12 +90,8 @@ class CalendarEvent(BaseModel): response = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") openai_client.conversations.delete(conversation_id=conversation.id) print("Conversation deleted") - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py index c4a652cf846b..a3f23c200763 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py @@ -34,6 +34,7 @@ import os from dotenv import load_dotenv from pydantic import BaseModel, Field +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import ( @@ -45,6 +46,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" class CalendarEvent(BaseModel): @@ -58,10 +60,9 @@ async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, - ): - agent = await project_client.agents.create_version( - agent_name="MyAgent", + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], text=PromptAgentDefinitionTextOptions( @@ -72,8 +73,11 @@ async def main() -> None: and returns it in the desired structured output format. """, ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = await openai_client.conversations.create( items=[ @@ -88,16 +92,12 @@ async def main() -> None: response = await openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") await openai_client.conversations.delete(conversation_id=conversation.id) print("Conversation deleted") - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") - if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py index 795d5aa7c6dc..307269a0c1d1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py @@ -30,6 +30,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from opentelemetry import trace from azure.monitor.opentelemetry import configure_azure_monitor @@ -41,6 +42,7 @@ load_dotenv() agent = None +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, @@ -54,21 +56,25 @@ scenario = os.path.basename(__file__) with tracer.start_as_current_span(scenario): - with project_client.get_openai_client() as openai_client: - agent_definition = PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ) - - agent = project_client.agents.create_version(agent_name="MyAgent", definition=agent_definition) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create() print(f"Created conversation with initial user message (id: {conversation.id})") response = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "id": agent.id, "type": "agent_reference"}}, input="What is the size of France in square miles?", ) print(f"Response output: {response.output_text}") @@ -76,6 +82,3 @@ openai_client.conversations.delete(conversation_id=conversation.id) print("Conversation deleted") - if agent: - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py index 8b9be473e7dc..792476344e09 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py @@ -30,6 +30,7 @@ import os from typing import Any from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.core.settings import settings @@ -82,26 +83,29 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o AIProjectInstrumentor().instrument() scenario = os.path.basename(__file__) +agent_name = "MyAgent" with tracer.start_as_current_span(scenario): with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent_definition = PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ) - - agent = project_client.agents.create_version(agent_name="MyAgent", definition=agent_definition) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create() request = "Hello, tell me a joke." response = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, input=request, ) print(f"Answer: {response.output}") @@ -109,7 +113,6 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o response = openai_client.responses.create( conversation=conversation.id, input="Tell another one about computers.", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Answer: {response.output}") @@ -119,6 +122,3 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o # Print all the items for item in items: display_conversation_item(item) - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py new file mode 100644 index 000000000000..62353ed618d0 --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py @@ -0,0 +1,23 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +from importlib.util import module_from_spec, spec_from_file_location +from pathlib import Path +import sys + +_AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" +_PKG_ROOT = Path(__file__).resolve().parents[3] +if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) + +_SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) +if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") + +_MODULE = module_from_spec(_SPEC) +_SPEC.loader.exec_module(_MODULE) + +create_version_with_endpoint = _MODULE.create_version_with_endpoint +create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async \ No newline at end of file diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py index e5d6d816ea6e..36ee0ecc6f37 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py @@ -29,6 +29,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -42,11 +43,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = AzureAISearchTool( @@ -61,53 +62,55 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="""You are a helpful assistant. You must always provide citations for - answers using the tool and render them as: `\u3010message_idx:search_idx\u2020source\u3011`.""", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="""You are a helpful assistant. You must always provide citations for + answers using the tool and render them as: `\u3010message_idx:search_idx\u2020source\u3011`.""", + tools=[tool], + ), + description="You are a helpful agent.", ), - description="You are a helpful agent.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Get user input from environment variable or prompt - user_input = os.environ.get("AI_SEARCH_USER_INPUT") - if not user_input: - user_input = input("Enter your question (e.g., 'Tell me about mental health services'): \n") + # Get user input from environment variable or prompt + user_input = os.environ.get("AI_SEARCH_USER_INPUT") + if not user_input: + user_input = input("Enter your question (e.g., 'Tell me about mental health services'): \n") - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Agent response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Agent response: {event.response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py index 09c98f891a00..9873cad9fd8f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py @@ -29,6 +29,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -45,11 +46,11 @@ agent = None endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = AzureFunctionTool( @@ -77,26 +78,28 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = "What is the weather in Seattle?" + user_input = "What is the weather in Seattle?" - response = openai_client.responses.create( - tool_choice="required", - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + response = openai_client.responses.create( + tool_choice="required", + input=user_input, + ) - print(f"Response output: {response.output_text}") + print(f"Response output: {response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index 0f52fbfa8e47..197dc91d1394 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py @@ -39,6 +39,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -51,11 +52,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = BingCustomSearchPreviewTool( @@ -69,49 +70,51 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - 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=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + 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=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") + user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") - # Send initial request that will trigger the Bing Custom Search tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send initial request that will trigger the Bing Custom Search tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("Cleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("Cleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py index 735462eb82b0..7a1fd853f451 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py @@ -44,6 +44,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -56,11 +57,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = BingGroundingTool( @@ -71,43 +72,45 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), + description="You are a helpful agent.", ), - description="You are a helpful agent.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input="What is today's date and whether in Seattle?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input="What is today's date and whether in Seattle?", + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print(f"URL Citation: {annotation.url}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print(f"URL Citation: {annotation.url}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index 54471e71aff4..ad70ec791d74 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -28,6 +28,7 @@ import os import json from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -40,11 +41,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = BrowserAutomationPreviewTool( @@ -55,53 +56,55 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="""You are an Agent helping with browser automation tasks. + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + 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=[tool], + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=""" + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=""" 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.""", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - item = event.item - if item.type == "browser_automation_preview_call": # TODO: support browser_automation_preview_call schema - arguments_str = getattr(item, "arguments", "{}") - - # Parse the arguments string into a dictionary - arguments = json.loads(arguments_str) - query = arguments.get("query") - - print(f"Call ID: {getattr(item, 'call_id')}") - print(f"Query arguments: {query}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + item = event.item + if item.type == "browser_automation_preview_call": # TODO: support browser_automation_preview_call schema + arguments_str = getattr(item, "arguments", "{}") + + # Parse the arguments string into a dictionary + arguments = json.loads(arguments_str) + query = arguments.get("query") + + print(f"Call ID: {getattr(item, 'call_id')}") + print(f"Query arguments: {query}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py index d1da6fcd4181..8bdb3fce1d9d 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py @@ -25,6 +25,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, CodeInterpreterTool @@ -32,48 +33,46 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): - - tool = CodeInterpreterTool() - - # Create agent with code interpreter tool - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[CodeInterpreterTool()], + ), + description="Code interpreter agent for data analysis and visualization.", ), - description="Code interpreter agent for data analysis and visualization.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send request for the agent to generate a multiplication chart. - response = openai_client.responses.create( - conversation=conversation.id, - input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - tool_choice="required", - ) - print(f"Response completed (id: {response.id})") - - # Print code executed by the code interpreter tool. - code = next((output.code for output in response.output if output.type == "code_interpreter_call"), "") - print("Code Interpreter code:") - print(code) - - # Print final assistant text output. - print(f"Agent response: {response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send request for the agent to generate a multiplication chart. + response = openai_client.responses.create( + conversation=conversation.id, + input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", + tool_choice="required", + ) + print(f"Response completed (id: {response.id})") + + # Print code executed by the code interpreter tool. + code = next((output.code for output in response.output if output.type == "code_interpreter_call"), "") + print("Code Interpreter code:") + print(code) + + # Print final assistant text output. + print(f"Agent response: {response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index 5371a781e75a..7c8580006b6a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -26,6 +26,7 @@ import asyncio import os from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, CodeInterpreterTool @@ -33,51 +34,53 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): - - # Create agent with code interpreter tool - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[CodeInterpreterTool()], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[CodeInterpreterTool()], + ), + description="Code interpreter agent for data analysis and visualization.", ), - description="Code interpreter agent for data analysis and visualization.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation for the agent interaction - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send request for the agent to generate a multiplication chart. - response = await openai_client.responses.create( - conversation=conversation.id, - input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - tool_choice="required", - ) - print(f"Response completed (id: {response.id})") - - # Print code executed by the code interpreter tool. - code = next((output.code for output in response.output if output.type == "code_interpreter_call"), None) - if code: - print(f"Code Interpreter code:\n {code}") - - # Print final assistant text output. - print(f"Agent response: {response.output_text}") - - print("\nCleaning up...") - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Create a conversation for the agent interaction + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send request for the agent to generate a multiplication chart. + response = await openai_client.responses.create( + conversation=conversation.id, + input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", + tool_choice="required", + ) + print(f"Response completed (id: {response.id})") + + # Print code executed by the code interpreter tool. + code = next((output.code for output in response.output if output.type == "code_interpreter_call"), None) + if code: + print(f"Code Interpreter code:\n {code}") + + # Print final assistant text output. + print(f"Agent response: {response.output_text}") + + print("\nCleaning up...") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index 59e5af777531..105752d44b25 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -31,6 +31,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint # Import shared helper functions from computer_use_util import ( # pylint: disable=import-error @@ -46,11 +47,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): # Initialize state machine current_state = SearchState.INITIAL @@ -65,96 +66,97 @@ tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), - instructions=""" + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), + instructions=""" You are a computer automation assistant. Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. """, - tools=[tool], + tools=[tool], + ), + description="Computer automation agent with screen interaction capabilities.", ), - description="Computer automation agent with screen interaction capabilities.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Initial request with screenshot - start with Bing search page - print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") - response = openai_client.responses.create( - input=[ - { - "role": "user", - "content": [ - { - "type": "input_text", - "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", - }, - { - "type": "input_image", - "image_url": screenshots["browser_search"]["url"], - "detail": "high", - }, # Start with Bing search page - ], - } - ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - truncation="auto", - ) + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Initial request with screenshot - start with Bing search page + print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") + response = openai_client.responses.create( + input=[ + { + "role": "user", + "content": [ + { + "type": "input_text", + "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", + }, + { + "type": "input_image", + "image_url": screenshots["browser_search"]["url"], + "detail": "high", + }, + ], + } + ], + truncation="auto", + ) - print(f"Initial response received (ID: {response.id})") + print(f"Initial response received (ID: {response.id})") - # Main interaction loop with deterministic completion - max_iterations = 10 # Allow enough iterations for completion - iteration = 0 + # Main interaction loop with deterministic completion + max_iterations = 10 # Allow enough iterations for completion + iteration = 0 - while True: - if iteration >= max_iterations: - print(f"\nReached maximum iterations ({max_iterations}). Stopping.") - break + while True: + if iteration >= max_iterations: + print(f"\nReached maximum iterations ({max_iterations}). Stopping.") + break - iteration += 1 - print(f"\n--- Iteration {iteration} ---") + iteration += 1 + print(f"\n--- Iteration {iteration} ---") - # Check for computer calls in the response - computer_calls = [item for item in response.output if item.type == "computer_call"] + # Check for computer calls in the response + computer_calls = [item for item in response.output if item.type == "computer_call"] - if not computer_calls: - print_final_output(response) - break + if not computer_calls: + print_final_output(response) + break - # Process the first computer call - computer_call = computer_calls[0] - action = computer_call.action - call_id = computer_call.call_id + # Process the first computer call + computer_call = computer_calls[0] + action = computer_call.action + call_id = computer_call.call_id - print(f"Processing computer call (ID: {call_id})") + print(f"Processing computer call (ID: {call_id})") - # Handle the action and get the screenshot info - screenshot_info, current_state = handle_computer_action_and_take_screenshot(action, current_state, screenshots) + # Handle the action and get the screenshot info + screenshot_info, current_state = handle_computer_action_and_take_screenshot(action, current_state, screenshots) - print(f"Sending action result back to agent (using {screenshot_info['filename']})...") + print(f"Sending action result back to agent (using {screenshot_info['filename']})...") - # Regular response with just the screenshot - response = openai_client.responses.create( - previous_response_id=response.id, - input=[ - { - "call_id": call_id, - "type": "computer_call_output", - "output": { - "type": "computer_screenshot", - "image_url": screenshot_info["url"], - }, - } - ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - truncation="auto", - ) + # Regular response with just the screenshot + response = openai_client.responses.create( + previous_response_id=response.id, + input=[ + { + "call_id": call_id, + "type": "computer_call_output", + "output": { + "type": "computer_screenshot", + "image_url": screenshot_info["url"], + }, + } + ], + truncation="auto", + ) - print(f"Follow-up response received (ID: {response.id})") + print(f"Follow-up response received (ID: {response.id})") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py index 5fd68ef7eda6..e8b70bf907a7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py @@ -33,6 +33,7 @@ import asyncio import os from dotenv import load_dotenv +from util import create_version_with_endpoint_async from computer_use_util import ( # pylint: disable=import-error SearchState, load_screenshot_assets, @@ -46,6 +47,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" async def main(): @@ -53,7 +55,6 @@ async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): """Main async function to demonstrate Computer Use Agent functionality.""" @@ -70,101 +71,104 @@ async def main(): computer_use_tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), - instructions=""" + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), + instructions=""" You are a computer automation assistant. Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. """, - tools=[computer_use_tool], + tools=[computer_use_tool], + ), + description="Computer automation agent with screen interaction capabilities.", ), - description="Computer automation agent with screen interaction capabilities.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Initial request with screenshot - start with Bing search page - print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") - response = await openai_client.responses.create( - input=[ - { - "role": "user", - "content": [ - { - "type": "input_text", - "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", - }, - { - "type": "input_image", - "image_url": screenshots["browser_search"]["url"], - "detail": "high", - }, # Start with Bing search page - ], - } - ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - truncation="auto", - ) + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Initial request with screenshot - start with Bing search page + print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") + response = await openai_client.responses.create( + input=[ + { + "role": "user", + "content": [ + { + "type": "input_text", + "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", + }, + { + "type": "input_image", + "image_url": screenshots["browser_search"]["url"], + "detail": "high", + }, + ], + } + ], + truncation="auto", + ) - print(f"Initial response received (ID: {response.id})") + print(f"Initial response received (ID: {response.id})") - # Main interaction loop with deterministic completion - max_iterations = 10 # Allow enough iterations for completion - iteration = 0 + # Main interaction loop with deterministic completion + max_iterations = 10 # Allow enough iterations for completion + iteration = 0 - while True: - if iteration >= max_iterations: - print(f"\nReached maximum iterations ({max_iterations}). Stopping.") - break + while True: + if iteration >= max_iterations: + print(f"\nReached maximum iterations ({max_iterations}). Stopping.") + break - iteration += 1 - print(f"\n--- Iteration {iteration} ---") + iteration += 1 + print(f"\n--- Iteration {iteration} ---") - # Check for computer calls in the response - computer_calls = [item for item in response.output if item.type == "computer_call"] + # Check for computer calls in the response + computer_calls = [item for item in response.output if item.type == "computer_call"] - if not computer_calls: - print_final_output(response) - break + if not computer_calls: + print_final_output(response) + break - # Process the first computer call - computer_call = computer_calls[0] - action = computer_call.action - call_id = computer_call.call_id + # Process the first computer call + computer_call = computer_calls[0] + action = computer_call.action + call_id = computer_call.call_id - print(f"Processing computer call (ID: {call_id})") + print(f"Processing computer call (ID: {call_id})") - # Handle the action and get the screenshot info - screenshot_info, current_state = handle_computer_action_and_take_screenshot( - action, current_state, screenshots - ) + # Handle the action and get the screenshot info + screenshot_info, current_state = handle_computer_action_and_take_screenshot( + action, current_state, screenshots + ) - print(f"Sending action result back to agent (using {screenshot_info['filename']})...") + print(f"Sending action result back to agent (using {screenshot_info['filename']})...") - # Regular response with just the screenshot - response = await openai_client.responses.create( - previous_response_id=response.id, - input=[ - { - "call_id": call_id, - "type": "computer_call_output", - "output": { - "type": "computer_screenshot", - "image_url": screenshot_info["url"], - }, - } - ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - truncation="auto", - ) + # Regular response with just the screenshot + response = await openai_client.responses.create( + previous_response_id=response.id, + input=[ + { + "call_id": call_id, + "type": "computer_call_output", + "output": { + "type": "computer_screenshot", + "image_url": screenshot_info["url"], + }, + } + ], + truncation="auto", + ) - print(f"Follow-up response received (ID: {response.id})") + print(f"Follow-up response received (ID: {response.id})") - print("\nCleaning up...") - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py index 587394c4e1aa..ab27add4ae72 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py @@ -28,6 +28,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -40,11 +41,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = MicrosoftFabricPreviewTool( fabric_dataagent_preview=FabricDataAgentToolParameters( @@ -54,48 +55,50 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_USER_INPUT") or input("Enter your question: \n") + user_input = os.environ.get("FABRIC_USER_INPUT") or input("Enter your question: \n") - stream_response = openai_client.responses.create( - tool_choice="required", - stream=True, - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + stream_response = openai_client.responses.create( + tool_choice="required", + stream=True, + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py index f43fba64a401..97776d9db6f8 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py @@ -27,6 +27,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, FabricIQPreviewTool @@ -34,36 +35,38 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool_payload = FabricIQPreviewTool( project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], require_approval="never", ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", - tools=[tool_payload], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", + tools=[tool_payload], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") - response = openai_client.responses.create( - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + response = openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # Clean up the agent version so unused versions don't accumulate in the project. - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # The helper restores the endpoint and deletes the temporary version automatically. diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py index bdd5881cba07..fb7c36a98a11 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py @@ -28,6 +28,7 @@ import os import asyncio from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, FabricIQPreviewTool @@ -35,41 +36,41 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool_payload = FabricIQPreviewTool( project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], require_approval="never", ) - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", - tools=[tool_payload], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", + tools=[tool_payload], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = await openai_client.responses.create( - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") - print(f"Agent response: {response.output_text}") + response = await openai_client.responses.create( + input=user_input, + ) - # Clean up the agent version so unused versions don't accumulate in the project. - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py index 991406256f1a..80a659e351a0 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py @@ -28,12 +28,15 @@ import json from dotenv import load_dotenv from openai.types.responses.response_input_param import FunctionCallOutput, ResponseInputParam +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, FunctionTool load_dotenv() +AGENT_NAME = "MyAgent" + def get_horoscope(sign: str) -> str: """Generate a horoscope for the given astrological sign.""" @@ -45,7 +48,6 @@ def get_horoscope(sign: str) -> str: with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = FunctionTool( @@ -65,50 +67,52 @@ def get_horoscope(sign: str) -> str: strict=True, ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can use function tools.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can use function tools.", + tools=[tool], + ), ), - ) - - # Prompt the model with tools defined - response = openai_client.responses.create( - input="What is my horoscope? I am an Aquarius.", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - input_list: ResponseInputParam = [] - # Process function calls - for item in response.output: - if item.type == "function_call": - if item.name == "get_horoscope": - # Execute the function logic for get_horoscope - horoscope = get_horoscope(**json.loads(item.arguments)) - - # Provide function call results to the model - input_list.append( - FunctionCallOutput( - type="function_call_output", - call_id=item.call_id, - output=json.dumps({"horoscope": horoscope}), + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Prompt the model with tools defined + response = openai_client.responses.create( + input="What is my horoscope? I am an Aquarius.", + ) + print(f"Response output: {response.output_text}") + + input_list: ResponseInputParam = [] + # Process function calls + for item in response.output: + if item.type == "function_call": + if item.name == "get_horoscope": + # Execute the function logic for get_horoscope + horoscope = get_horoscope(**json.loads(item.arguments)) + + # Provide function call results to the model + input_list.append( + FunctionCallOutput( + type="function_call_output", + call_id=item.call_id, + output=json.dumps({"horoscope": horoscope}), + ) ) - ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py index 249f9a936419..f88e4cb6630e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py @@ -30,6 +30,7 @@ import asyncio from dotenv import load_dotenv from openai.types.responses.response_input_param import FunctionCallOutput, ResponseInputParam +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, FunctionTool @@ -37,6 +38,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" async def get_horoscope(sign: str) -> str: @@ -48,7 +50,6 @@ async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): # Define a function tool for the model to use func_tool = FunctionTool( @@ -68,49 +69,55 @@ async def main(): strict=True, ) - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can use function tools.", - tools=[func_tool], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can use function tools.", + tools=[func_tool], + ), ), - ) - - # Prompt the model with tools defined - response = await openai_client.responses.create( - input="What is my horoscope? I am an Aquarius.", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - input_list: ResponseInputParam = [] - # Process function calls - for item in response.output: - if item.type == "function_call": - if item.name == "get_horoscope": - # Execute the function logic for get_horoscope - horoscope = await get_horoscope(**json.loads(item.arguments)) - - # Provide function call results to the model - input_list.append( - FunctionCallOutput( - type="function_call_output", - call_id=item.call_id, - output=json.dumps({"horoscope": horoscope}), + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Prompt the model with tools defined + response = await openai_client.responses.create( + input="What is my horoscope? I am an Aquarius.", + ) + print(f"Response output: {response.output_text}") + + input_list: ResponseInputParam = [] + # Process function calls + for item in response.output: + if item.type == "function_call": + if item.name == "get_horoscope": + # Execute the function logic for get_horoscope + horoscope = await get_horoscope(**json.loads(item.arguments)) + + # Provide function call results to the model + input_list.append( + FunctionCallOutput( + type="function_call_output", + call_id=item.call_id, + output=json.dumps({"horoscope": horoscope}), + ) ) - ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py index b1a4e20fda11..e2a5533a2867 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py @@ -46,6 +46,7 @@ import os import tempfile from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient @@ -54,11 +55,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] @@ -68,37 +69,39 @@ size="1024x1024", ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Generate images based on user prompts", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Generate images based on user prompts", + tools=[tool], + ), + description="Agent for image generation.", ), - description="Agent for image generation.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - response = openai_client.responses.create( - input="Generate an image of Microsoft logo.", - extra_headers={ - "x-ms-oai-image-generation-deployment": image_generation_model - }, # this is required at the moment for image generation - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response created: {response.id}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") - - image_data = [output.result for output in response.output if output.type == "image_generation_call"] - if image_data and image_data[0]: - print("Downloading generated image...") - filename = "microsoft.png" - file_path = os.path.join(tempfile.gettempdir(), filename) - - with open(file_path, "wb") as f: - f.write(base64.b64decode(image_data[0])) - - print(f"Image saved to: {file_path}") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + response = openai_client.responses.create( + input="Generate an image of Microsoft logo.", + extra_headers={ + "x-ms-oai-image-generation-deployment": image_generation_model + }, # this is required at the moment for image generation + ) + print(f"Response created: {response.id}") + + print("\nCleaning up...") + + image_data = [output.result for output in response.output if output.type == "image_generation_call"] + if image_data and image_data[0]: + print("Downloading generated image...") + filename = "microsoft.png" + file_path = os.path.join(tempfile.gettempdir(), filename) + + with open(file_path, "wb") as f: + f.write(base64.b64decode(image_data[0])) + + print(f"Image saved to: {file_path}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py index 37fa57e82a16..ff286a34bcdf 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py @@ -47,6 +47,7 @@ import os import tempfile from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient @@ -54,52 +55,54 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Generate images based on user prompts", - tools=[ImageGenTool(model=image_generation_model, quality="low", size="1024x1024")], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Generate images based on user prompts", + tools=[ImageGenTool(model=image_generation_model, quality="low", size="1024x1024")], + ), + description="Agent for image generation.", ), - description="Agent for image generation.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - response = await openai_client.responses.create( - input="Generate an image of Microsoft logo.", - extra_headers={ - "x-ms-oai-image-generation-deployment": image_generation_model - }, # this is required at the moment for image generation - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response created: {response.id}") - - print("\nCleaning up...") - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") - - # Save the image to a file - image_data = [output.result for output in response.output if output.type == "image_generation_call"] - if image_data and image_data[0]: - print("Downloading generated image...") - filename = "microsoft.png" - file_path = os.path.join(tempfile.gettempdir(), filename) - - with open(file_path, "wb") as f: - f.write(base64.b64decode(image_data[0])) - - print(f"Image saved to: {file_path}") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + response = await openai_client.responses.create( + input="Generate an image of Microsoft logo.", + extra_headers={ + "x-ms-oai-image-generation-deployment": image_generation_model + }, # this is required at the moment for image generation + ) + print(f"Response created: {response.id}") + + print("\nCleaning up...") + + # Save the image to a file + image_data = [output.result for output in response.output if output.type == "image_generation_call"] + if image_data and image_data[0]: + print("Downloading generated image...") + filename = "microsoft.png" + file_path = os.path.join(tempfile.gettempdir(), filename) + + with open(file_path, "wb") as f: + f.write(base64.b64decode(image_data[0])) + + print(f"Image saved to: {file_path}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index 934a83781e92..6d88341b908a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -26,6 +26,7 @@ import os from dotenv import load_dotenv from openai.types.responses.response_input_param import McpApprovalResponse, ResponseInputParam +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, MCPTool @@ -33,11 +34,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -45,56 +46,58 @@ require_approval="always", ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", - tools=[mcp_tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", + tools=[mcp_tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = openai_client.responses.create( - conversation=conversation.id, - input="Please summarize the Azure REST API specifications Readme", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation thread to maintain context across multiple interactions + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = openai_client.responses.create( + conversation=conversation.id, + input="Please summarize the Azure REST API specifications Readme", + ) + + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, + ) ) - ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # Clean up resources by deleting the agent version + # This prevents accumulation of unused agent versions in your project + print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py index 55c32cd0602c..4f57aec97f2b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py @@ -27,6 +27,7 @@ import asyncio from dotenv import load_dotenv from openai.types.responses.response_input_param import McpApprovalResponse, ResponseInputParam +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, MCPTool, Tool @@ -34,13 +35,13 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -51,60 +52,63 @@ async def main(): # Create tools list with proper typing for the agent definition tools: list[Tool] = [mcp_tool] - # Create a prompt agent with MCP tool capabilities - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", - tools=tools, + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", + tools=tools, + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = await openai_client.responses.create( - conversation=conversation.id, - input="Please summarize the Azure REST API specifications Readme", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Create a conversation thread to maintain context across multiple interactions + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = await openai_client.responses.create( + conversation=conversation.id, + input="Please summarize the Azure REST API specifications Readme", + ) + + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, + ) ) - ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # Clean up resources by deleting the agent version + # This prevents accumulation of unused agent versions in your project + print("Agent deleted") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index 3042ac9458db..5375bbc603d4 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -28,6 +28,7 @@ import os from dotenv import load_dotenv from openai.types.responses.response_input_param import McpApprovalResponse, ResponseInputParam +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, MCPTool @@ -35,11 +36,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent7" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = MCPTool( @@ -49,57 +50,58 @@ project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], ) - # Create a prompt agent with MCP tool capabilities - agent = project_client.agents.create_version( - agent_name="MyAgent7", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use MCP tools as needed", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use MCP tools as needed", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = openai_client.responses.create( - conversation=conversation.id, - input="What is my username in Github profile?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation thread to maintain context across multiple interactions + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = openai_client.responses.create( + conversation=conversation.id, + input="What is my username in Github profile?", + ) + + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, + ) ) - ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Response: {response.output_text}") + print(f"Response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # Clean up resources by deleting the agent version + # This prevents accumulation of unused agent versions in your project + print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py index 8de0155f94ec..9737115cde16 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py @@ -29,6 +29,7 @@ import asyncio from dotenv import load_dotenv from openai.types.responses.response_input_param import McpApprovalResponse, ResponseInputParam +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, MCPTool, Tool @@ -36,13 +37,13 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -54,59 +55,62 @@ async def main(): # Create tools list with proper typing for the agent definition tools: list[Tool] = [mcp_tool] - # Create a prompt agent with MCP tool capabilities - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use MCP tools as needed", - tools=tools, + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use MCP tools as needed", + tools=tools, + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = await openai_client.responses.create( - conversation=conversation.id, - input="What is my username in GitHub profile?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Create a conversation thread to maintain context across multiple interactions + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = await openai_client.responses.create( + conversation=conversation.id, + input="What is my username in GitHub profile?", + ) + + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, + ) ) - ) - - print("Final input:") - print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response: {response.output_text}") + print("Final input:") + print(input_list) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) + + print(f"Response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # Clean up resources by deleting the agent version + # This prevents accumulation of unused agent versions in your project + print("Agent deleted") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py index 433b315b2920..c3f3028ed04d 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py @@ -36,6 +36,7 @@ import os import time from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.core.exceptions import ResourceNotFoundError from azure.ai.projects import AIProjectClient @@ -48,11 +49,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): # Delete memory store, if it already exists @@ -86,52 +87,53 @@ # In a real application, set this to a higher value like 300 (5 minutes, default) ) - # Create a prompt agent with memory search tool - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation with the agent with memory tool enabled - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Create an agent response to initial user message - response = openai_client.responses.create( - input="I prefer dark roast coffee", - conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - # After an inactivity in the conversation, memories will be extracted from the conversation and stored - print("Waiting for memories to be stored...") - time.sleep(60) - - # Create a new conversation - new_conversation = openai_client.conversations.create() - print(f"Created new conversation (id: {new_conversation.id})") - - # Create an agent response with stored memories - new_response = openai_client.responses.create( - input="Please order my usual coffee", - conversation=new_conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {new_response.output_text}") - - # Clean up - openai_client.conversations.delete(conversation.id) - openai_client.conversations.delete(new_conversation.id) - print("Conversations deleted") - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation with the agent with memory tool enabled + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Create an agent response to initial user message + response = openai_client.responses.create( + input="I prefer dark roast coffee", + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + # After an inactivity in the conversation, memories will be extracted from the conversation and stored + print("Waiting for memories to be stored...") + time.sleep(60) + + # Create a new conversation + new_conversation = openai_client.conversations.create() + print(f"Created new conversation (id: {new_conversation.id})") + + # Create an agent response with stored memories + new_response = openai_client.responses.create( + input="Please order my usual coffee", + conversation=new_conversation.id, + ) + print(f"Response output: {new_response.output_text}") + + # Clean up + openai_client.conversations.delete(conversation.id) + openai_client.conversations.delete(new_conversation.id) + print("Conversations deleted") + + print("Agent deleted") project_client.beta.memory_stores.delete(memory_store.name) print("Memory store deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py index d69d5dea0751..2b2dfafa11b3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py @@ -36,6 +36,7 @@ import asyncio import os from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.core.exceptions import ResourceNotFoundError from azure.ai.projects.aio import AIProjectClient @@ -47,6 +48,8 @@ load_dotenv() +AGENT_NAME = "MyAgent" + async def main() -> None: @@ -55,7 +58,6 @@ async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): # Delete memory store, if it already exists @@ -82,59 +84,62 @@ async def main() -> None: # You can also use "{{$userId}}" to take the oid of the request authentication header scope = "user_123" - # Create a prompt agent with memory search tool - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - tools=[ - MemorySearchPreviewTool( - memory_store_name=memory_store.name, - scope=scope, - update_delay=1, # Wait 1 second of inactivity before updating memories - # In a real application, set this to a higher value like 300 (5 minutes, default) - ) - ], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + tools=[ + MemorySearchPreviewTool( + memory_store_name=memory_store.name, + scope=scope, + update_delay=1, # Wait 1 second of inactivity before updating memories + # In a real application, set this to a higher value like 300 (5 minutes, default) + ) + ], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation with the agent with memory tool enabled - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Create an agent response to initial user message - response = await openai_client.responses.create( - input="I prefer dark roast coffee", - conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {response.output_text}") - - # After an inactivity in the conversation, memories will be extracted from the conversation and stored - print("Waiting for memories to be stored...") - await asyncio.sleep(60) - - # Create a new conversation - new_conversation = await openai_client.conversations.create() - print(f"Created new conversation (id: {new_conversation.id})") - - # Create an agent response with stored memories - new_response = await openai_client.responses.create( - input="Please order my usual coffee", - conversation=new_conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Response output: {new_response.output_text}") - - # Clean up - await openai_client.conversations.delete(conversation.id) - await openai_client.conversations.delete(new_conversation.id) - print("Conversations deleted") - - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" + ) + + # Create a conversation with the agent with memory tool enabled + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Create an agent response to initial user message + response = await openai_client.responses.create( + input="I prefer dark roast coffee", + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + # After an inactivity in the conversation, memories will be extracted from the conversation and stored + print("Waiting for memories to be stored...") + await asyncio.sleep(60) + + # Create a new conversation + new_conversation = await openai_client.conversations.create() + print(f"Created new conversation (id: {new_conversation.id})") + + # Create an agent response with stored memories + new_response = await openai_client.responses.create( + input="Please order my usual coffee", + conversation=new_conversation.id, + ) + print(f"Response output: {new_response.output_text}") + + # Clean up + await openai_client.conversations.delete(conversation.id) + await openai_client.conversations.delete(new_conversation.id) + print("Conversations deleted") + + print("Agent deleted") await project_client.beta.memory_stores.delete(memory_store.name) print("Memory store deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py index 729971029a6d..dbdd1a9cc0d7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py @@ -27,6 +27,7 @@ from typing import Any, cast import jsonref from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -39,13 +40,12 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): - weather_asset_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/weather_openapi.json")) with open(weather_asset_file_path, "r", encoding="utf-8") as f: @@ -60,22 +60,22 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = openai_client.responses.create( - input="Use the OpenAPI tool to print out, what is the weather in Seattle today.", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - print(f"Agent response: {response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + response = openai_client.responses.create( + input="Use the OpenAPI tool to print out, what is the weather in Seattle today.", + ) + print(f"Agent response: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py index 890b7388608a..abd15eef4006 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py @@ -30,6 +30,7 @@ from typing import Any, cast import jsonref from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -43,13 +44,12 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): - tripadvisor_asset_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "../assets/tripadvisor_openapi.json") ) @@ -70,23 +70,23 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = openai_client.responses.create( - input="Recommend me 5 top hotels in the United States", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - # The response to the question may contain non ASCII letters. To avoid error, encode and re decode them. - print(f"Response created: {response.output_text.encode().decode('ascii', errors='ignore')}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + response = openai_client.responses.create( + input="Recommend me 5 top hotels in the United States", + ) + # The response to the question may contain non ASCII letters. To avoid error, encode and re decode them. + print(f"Response created: {response.output_text.encode().decode('ascii', errors='ignore')}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py index d1c4db82eb1c..62a8f517901b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py @@ -28,6 +28,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -40,11 +41,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = SharepointPreviewTool( sharepoint_grounding_preview=SharepointGroundingToolParameters( @@ -54,52 +55,54 @@ ) ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="""You are a helpful agent that can use SharePoint tools to assist users. - Use the available SharePoint tools to answer questions and perform tasks.""", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="""You are a helpful agent that can use SharePoint tools to assist users. + Use the available SharePoint tools to answer questions and perform tasks.""", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Get user input from environment variable or prompt - user_input = os.environ.get("SHAREPOINT_USER_INPUT") - if not user_input: - user_input = input("Enter your question corresponded to the documents in SharePoint:\n") + # Get user input from environment variable or prompt + user_input = os.environ.get("SHAREPOINT_USER_INPUT") + if not user_input: + user_input = input("Enter your question corresponded to the documents in SharePoint:\n") - # Send initial request that will trigger the SharePoint tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send initial request that will trigger the SharePoint tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Agent response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Agent response: {event.response.output_text}") - print("Cleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("Cleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py index edb7a46fc760..9f2d41304608 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py @@ -32,6 +32,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -42,11 +43,11 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = A2APreviewTool( @@ -56,48 +57,50 @@ if os.environ.get("A2A_ENDPOINT"): tool.base_url = os.environ["A2A_ENDPOINT"] - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("A2A_USER_INPUT") or input( - "Enter your question (e.g., 'What can the secondary agent do?'): \n" - ) + user_input = os.environ.get("A2A_USER_INPUT") or input( + "Enter your question (e.g., 'What can the secondary agent do?'): \n" + ) - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - item = event.item - if item.type == "a2a_preview_call": - print(f"Request ID: {getattr(item, 'id')}") - if hasattr(item, "model_extra"): - extra = getattr(item, "model_extra") - if isinstance(extra, dict): - print(f"Arguments: {extra['arguments']}") - elif item.type == "a2a_preview_call_output": - print(f"Response ID: {getattr(item, 'id')}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + item = event.item + if item.type == "a2a_preview_call": + print(f"Request ID: {getattr(item, 'id')}") + if hasattr(item, "model_extra"): + extra = getattr(item, "model_extra") + if isinstance(extra, dict): + print(f"Arguments: {extra['arguments']}") + elif item.type == "a2a_preview_call_output": + print(f"Response ID: {getattr(item, 'id')}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py index 847a9d206333..847b725548be 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py @@ -38,6 +38,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.ai.projects.models._models import ToolboxSearchPreviewToolboxTool from azure.core.exceptions import ResourceNotFoundError @@ -64,7 +65,6 @@ with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): try: @@ -110,43 +110,47 @@ require_approval="never", ) - agent = project_client.agents.create_version( - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Answer the user using the `shipping-cost-skill` instructions " - "available in your context. Do not call `tool_search`; the " - "skill rules are already part of your knowledge. Apply the " - "skill's formula exactly as given and state the formula in " - "your answer." + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Answer the user using the `shipping-cost-skill` instructions " + "available in your context. Do not call `tool_search`; the " + "skill rules are already part of your knowledge. Apply the " + "skill's formula exactly as given and state the formula in " + "your answer." + ), + temperature=0, + tools=[toolbox_mcp_tool], ), - temperature=0, - tools=[toolbox_mcp_tool], ), - ) - print(f"Agent created (id={agent.id}, name={agent.name}, version={agent.version})") - - user_input = "Compute the shipping cost for a 3 kg package shipped domestically." - print(f"User: {user_input}") - response = openai_client.responses.create( - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - for item in response.output: - if item.type == "mcp_list_tools": - print(f"mcp_list_tools server_label={item.server_label} tools={[t.name for t in (item.tools or [])]}") - elif item.type == "mcp_call": - print(f"mcp_call server_label={item.server_label} name={item.name} error={item.error}") - if getattr(item, "output", None): - print(f" output: {item.output}") - elif item.type == "mcp_approval_request": - print(f"mcp_approval_request server_label={item.server_label} name={item.name}") - else: - print(f"output item type={item.type}") - - print(f"Response: {response.output_text}") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id={agent.id}, name={agent.name}, version={agent.versions.latest.version})") + + user_input = "Compute the shipping cost for a 3 kg package shipped domestically." + print(f"User: {user_input}") + response = openai_client.responses.create( + input=user_input, + ) + + for item in response.output: + if item.type == "mcp_list_tools": + print(f"mcp_list_tools server_label={item.server_label} tools={[t.name for t in (item.tools or [])]}") + elif item.type == "mcp_call": + print(f"mcp_call server_label={item.server_label} name={item.name} error={item.error}") + if getattr(item, "output", None): + print(f" output: {item.output}") + elif item.type == "mcp_approval_request": + print(f"mcp_approval_request server_label={item.server_label} name={item.name}") + else: + print(f"output item type={item.type}") + + print(f"Response: {response.output_text}") project_client.toolboxes.delete(TOOLBOX_NAME) print("Toolbox deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py index a08477e27096..b1f4b19fcf81 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py @@ -34,6 +34,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient @@ -47,60 +48,62 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = WebSearchTool(user_location=WebSearchApproximateLocation(country="GB", city="London", region="London")) - # Create Agent with web search tool - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web", + tools=[tool], + ), + description="Agent for web search.", ), - description="Agent for web search.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + # Create Agent with web search tool + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") - # Send a query to search the web - user_input = "Show me the latest London Underground service updates" - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + # Send a query to search the web + user_input = "Show me the latest London Underground service updates" + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py index cdef1789b143..dc004755cc2b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py @@ -34,6 +34,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient @@ -43,61 +44,62 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent105" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = WebSearchPreviewTool(user_location=ApproximateLocation(country="GB", city="London", region="London")) - # Create Agent with web search tool - agent = project_client.agents.create_version( - agent_name="MyAgent105", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web", + tools=[tool], + ), + description="Agent for web search.", ), - description="Agent for web search.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send a query to search the web - user_input = "Show me the latest London Underground service updates" - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send a query to search the web + user_input = "Show me the latest London Underground service updates" + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", + ) + + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py index b66e18e00241..102d109f7337 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py @@ -39,6 +39,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient @@ -52,11 +53,11 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool = WebSearchTool( custom_search_configuration=WebSearchConfiguration( @@ -64,56 +65,57 @@ instance_name=os.environ["BING_CUSTOM_SEARCH_INSTANCE_NAME"], ) ) - # Create Agent with web search tool - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web and bing", - tools=[tool], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web and bing", + tools=[tool], + ), + description="Agent for web search.", ), - description="Agent for web search.", - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") - - # Send a query to search the web - # Send initial request that will trigger the Bing Custom Search tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") + + # Send a query to search the web + # Send initial request that will trigger the Bing Custom Search tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py index 6ec54359df61..ef0aff98dab1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py @@ -27,6 +27,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, WorkIQPreviewTool @@ -34,35 +35,37 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool_payload = WorkIQPreviewTool( project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available WorkIQ tools to answer questions and perform tasks.", - tools=[tool_payload], + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available WorkIQ tools to answer questions and perform tasks.", + tools=[tool_payload], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") - response = openai_client.responses.create( - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + response = openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # Clean up the agent version so unused versions don't accumulate in the project. - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + # The helper restores the endpoint and deletes the temporary version automatically. diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py index 7f101778079f..95b721023949 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py @@ -28,6 +28,7 @@ import os import asyncio from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition, WorkIQPreviewTool @@ -35,40 +36,40 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] +agent_name = "MyAgent" async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): tool_payload = WorkIQPreviewTool( project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], ) - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available WorkIQ tools to answer questions and perform tasks.", - tools=[tool_payload], + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available WorkIQ tools to answer questions and perform tasks.", + tools=[tool_payload], + ), ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - - user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = await openai_client.responses.create( - input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) + user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") - print(f"Agent response: {response.output_text}") + response = await openai_client.responses.create( + input=user_input, + ) - # Clean up the agent version so unused versions don't accumulate in the project. - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py index ff4e7faa33f6..3ec7e9343b6f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py @@ -37,6 +37,7 @@ import os from dotenv import load_dotenv +from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( @@ -54,12 +55,12 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" +AGENT_NAME = "MyAgent" with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): inner_mcp_tool = MCPToolboxTool( @@ -86,36 +87,37 @@ require_approval="never", ) - agent = project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Always use the toolbox search tool to answer questions and perform tasks. " - "Use `tool_search` to discover a relevant tool, then `call_tool` " - "with the tool name returned by the search." + with ( + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Always use the toolbox search tool to answer questions and perform tasks. " + "Use `tool_search` to discover a relevant tool, then `call_tool` " + "with the tool name returned by the search." + ), + tools=[toolbox_mcp_tool], ), - tools=[toolbox_mcp_tool], ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version}).") - - response = openai_client.responses.create( - input="What is my username in Github profile?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - for item in response.output: - if item.type == "mcp_approval_request": - print(f"server_label={item.server_label}, name={item.name}") - elif item.type == "mcp_list_tools": - print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") - elif item.type == "mcp_call": - print(f"server_label={item.server_label}, name={item.name}, error={item.error}") - else: - print() - - print(f"Response: {response.output_text}") - - project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print(f"Agent version {agent.version} deleted.") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version}).") + + response = openai_client.responses.create( + input="What is my username in Github profile?", + ) + + for item in response.output: + if item.type == "mcp_approval_request": + print(f"server_label={item.server_label}, name={item.name}") + elif item.type == "mcp_list_tools": + print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") + elif item.type == "mcp_call": + print(f"server_label={item.server_label}, name={item.name}, error={item.error}") + else: + print() + + print(f"Response: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py index 1a44ab930311..866a825bea48 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py @@ -38,6 +38,7 @@ import asyncio import os from dotenv import load_dotenv +from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient from azure.ai.projects.models import ( @@ -55,13 +56,13 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" +AGENT_NAME = "MyAgent" async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, ): inner_mcp_tool = MCPToolboxTool( @@ -88,39 +89,42 @@ async def main() -> None: require_approval="never", ) - agent = await project_client.agents.create_version( - agent_name="MyAgent", - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Always use the toolbox search tool to answer questions and perform tasks. " - "Use `tool_search` to discover a relevant tool, then `call_tool` " - "with the tool name returned by the search." + async with ( + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Always use the toolbox search tool to answer questions and perform tasks. " + "Use `tool_search` to discover a relevant tool, then `call_tool` " + "with the tool name returned by the search." + ), + tools=[toolbox_mcp_tool], ), - tools=[toolbox_mcp_tool], ), - ) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version}).") - - response = await openai_client.responses.create( - input="What is my username in Github profile?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, - ) - - for item in response.output: - if item.type == "mcp_approval_request": - print(f"server_label={item.server_label}, name={item.name}") - elif item.type == "mcp_list_tools": - print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") - elif item.type == "mcp_call": - print(f"server_label={item.server_label}, name={item.name}, error={item.error}") - else: - print() - - print(f"Response: {response.output_text}") - - await project_client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print(f"Agent version {agent.version} deleted.") + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, + ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print( + f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})." + ) + + response = await openai_client.responses.create( + input="What is my username in Github profile?", + ) + + for item in response.output: + if item.type == "mcp_approval_request": + print(f"server_label={item.server_label}, name={item.name}") + elif item.type == "mcp_list_tools": + print(f"server_label={item.server_label}, tools={[t.name for t in (item.tools or [])]}") + elif item.type == "mcp_call": + print(f"server_label={item.server_label}, name={item.name}, error={item.error}") + else: + print() + + print(f"Response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py new file mode 100644 index 000000000000..62353ed618d0 --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py @@ -0,0 +1,23 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +from importlib.util import module_from_spec, spec_from_file_location +from pathlib import Path +import sys + +_AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" +_PKG_ROOT = Path(__file__).resolve().parents[3] +if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) + +_SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) +if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") + +_MODULE = module_from_spec(_SPEC) +_SPEC.loader.exec_module(_MODULE) + +create_version_with_endpoint = _MODULE.create_version_with_endpoint +create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async \ No newline at end of file diff --git a/sdk/ai/azure-ai-projects/samples/agents/util.py b/sdk/ai/azure-ai-projects/samples/agents/util.py new file mode 100644 index 000000000000..34fefb49c2cb --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/util.py @@ -0,0 +1,23 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +from importlib.util import module_from_spec, spec_from_file_location +from pathlib import Path +import sys + +_SAMPLES_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" +_PKG_ROOT = Path(__file__).resolve().parents[2] +if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) + +_SPEC = spec_from_file_location("samples_shared_util", _SAMPLES_UTIL_PATH) +if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load shared samples util from {_SAMPLES_UTIL_PATH}") + +_MODULE = module_from_spec(_SPEC) +_SPEC.loader.exec_module(_MODULE) + +create_version_with_endpoint = _MODULE.create_version_with_endpoint +create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async diff --git a/sdk/ai/azure-ai-projects/samples/util.py b/sdk/ai/azure-ai-projects/samples/util.py index 818a62ccc853..932b57913bfe 100644 --- a/sdk/ai/azure-ai-projects/samples/util.py +++ b/sdk/ai/azure-ai-projects/samples/util.py @@ -5,10 +5,29 @@ import hashlib import os +import sys import tempfile import zipfile +from contextlib import asynccontextmanager, contextmanager from pathlib import Path -from typing import Optional, Tuple +from typing import Any, AsyncIterator, Iterator, Optional, Tuple + +_PKG_ROOT = Path(__file__).resolve().parents[1] +if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) + +from azure.ai.projects import AIProjectClient +from azure.ai.projects.aio import AIProjectClient as AsyncAIProjectClient +from azure.ai.projects.models import ( + AgentBlueprintReference, + AgentDefinition, + AgentEndpointConfig, + AgentVersionDetails, + FixedRatioVersionSelectionRule, + ProtocolConfiguration, + ResponsesProtocolConfiguration, + VersionSelector, +) def _resolve_zip_file(zip_file: str) -> Path: @@ -54,3 +73,107 @@ def zip_directory( zip_sha256 = hashlib.sha256(zip_bytes).hexdigest() print(f"Built zip from {source_dir}: {len(zip_bytes)} bytes, sha256={zip_sha256}, path={zip_path}") return zip_bytes, zip_sha256, zip_path + + +@contextmanager +def create_version_with_endpoint( + project_client: AIProjectClient, + agent_name: str, + *, + definition: AgentDefinition, + metadata: Optional[dict[str, str]] = None, + description: Optional[str] = None, + blueprint_reference: Optional[AgentBlueprintReference] = None, + draft: Optional[bool] = None, + **kwargs: Any, +) -> Iterator[AgentVersionDetails]: + """Create a version, point the agent endpoint to it, then restore and delete on exit.""" + created_version = None + original_agent_endpoint = None + + try: + created_version = project_client.agents.create_version( + agent_name=agent_name, + definition=definition, + metadata=metadata, + description=description, + blueprint_reference=blueprint_reference, + draft=draft, + **kwargs, + ) + + original_agent_endpoint = project_client.agents.get(agent_name=agent_name).agent_endpoint + endpoint_config = AgentEndpointConfig( + version_selector=VersionSelector( + version_selection_rules=[ + FixedRatioVersionSelectionRule(agent_version=created_version.version, traffic_percentage=100), + ] + ), + protocol_configuration=ProtocolConfiguration(responses=ResponsesProtocolConfiguration()), + ) + project_client.agents.update_details(agent_name=agent_name, agent_endpoint=endpoint_config) + print(f"Agent endpoint configured for version {created_version.version}") + + yield created_version + finally: + if original_agent_endpoint is not None: + project_client.agents.update_details(agent_name=agent_name, agent_endpoint=original_agent_endpoint) + print("Agent endpoint restored") + + if created_version is not None: + project_client.agents.delete_version( + agent_name=agent_name, agent_version=created_version.version, force=True + ) + print(f"Hosted agent version {created_version.version} deleted") + + +@asynccontextmanager +async def create_version_with_endpoint_async( + project_client: AsyncAIProjectClient, + agent_name: str, + *, + definition: AgentDefinition, + metadata: Optional[dict[str, str]] = None, + description: Optional[str] = None, + blueprint_reference: Optional[AgentBlueprintReference] = None, + draft: Optional[bool] = None, + **kwargs: Any, +) -> AsyncIterator[AgentVersionDetails]: + """Async variant of :func:`create_version_with_endpoint`.""" + created_version = None + original_agent_endpoint = None + + try: + created_version = await project_client.agents.create_version( + agent_name=agent_name, + definition=definition, + metadata=metadata, + description=description, + blueprint_reference=blueprint_reference, + draft=draft, + **kwargs, + ) + + original_agent_endpoint = (await project_client.agents.get(agent_name=agent_name)).agent_endpoint + endpoint_config = AgentEndpointConfig( + version_selector=VersionSelector( + version_selection_rules=[ + FixedRatioVersionSelectionRule(agent_version=created_version.version, traffic_percentage=100), + ] + ), + protocol_configuration=ProtocolConfiguration(responses=ResponsesProtocolConfiguration()), + ) + await project_client.agents.update_details(agent_name=agent_name, agent_endpoint=endpoint_config) + print(f"Agent endpoint configured for version {created_version.version}") + + yield created_version + finally: + if original_agent_endpoint is not None: + await project_client.agents.update_details(agent_name=agent_name, agent_endpoint=original_agent_endpoint) + print("Agent endpoint restored") + + if created_version is not None: + await project_client.agents.delete_version( + agent_name=agent_name, agent_version=created_version.version, force=True + ) + print(f"Hosted agent version {created_version.version} deleted") From 649e8d1d2e94eff1ce4b87a95898cb1f5c807d10 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 16:03:14 -0700 Subject: [PATCH 02/24] Refactor print statements for improved readability and remove unnecessary comments in sample agent scripts --- .../samples/agents/sample_agent_basic.py | 2 +- .../sample_agent_basic_with_azure_monitor_tracing.py | 2 -- sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py | 2 +- .../agents/tools/sample_agent_browser_automation.py | 4 +++- .../agents/tools/sample_agent_code_interpreter_async.py | 4 +--- .../samples/agents/tools/sample_agent_computer_use.py | 4 +++- .../agents/tools/sample_agent_computer_use_async.py | 4 +--- .../agents/tools/sample_agent_function_tool_async.py | 4 +--- .../samples/agents/tools/sample_agent_mcp.py | 4 ---- .../samples/agents/tools/sample_agent_mcp_async.py | 8 +------- .../tools/sample_agent_mcp_with_project_connection.py | 4 ---- .../sample_agent_mcp_with_project_connection_async.py | 8 +------- .../samples/agents/tools/sample_agent_memory_search.py | 2 -- .../agents/tools/sample_agent_memory_search_async.py | 6 +----- .../tools/sample_toolboxes_with_search_preview_async.py | 4 +--- sdk/ai/azure-ai-projects/samples/agents/tools/util.py | 2 +- sdk/ai/azure-ai-projects/samples/util.py | 6 +----- 17 files changed, 17 insertions(+), 53 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py index f27a5c2a8043..84ce12dd3979 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py @@ -48,7 +48,7 @@ definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions", - ) + ), ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py index 307269a0c1d1..ef5de04537ea 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py @@ -80,5 +80,3 @@ print(f"Response output: {response.output_text}") openai_client.conversations.delete(conversation_id=conversation.id) - print("Conversation deleted") - diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py index 62353ed618d0..a6159e1c1dcb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py @@ -20,4 +20,4 @@ _SPEC.loader.exec_module(_MODULE) create_version_with_endpoint = _MODULE.create_version_with_endpoint -create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async \ No newline at end of file +create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index ad70ec791d74..a335eb19f971 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -94,7 +94,9 @@ print("\nFollow-up response done!") elif event.type == "response.output_item.done": item = event.item - if item.type == "browser_automation_preview_call": # TODO: support browser_automation_preview_call schema + if ( + item.type == "browser_automation_preview_call" + ): # TODO: support browser_automation_preview_call schema arguments_str = getattr(item, "arguments", "{}") # Parse the arguments string into a dictionary diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index 7c8580006b6a..6b9251eead47 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -56,9 +56,7 @@ async def main() -> None: project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Create a conversation for the agent interaction conversation = await openai_client.conversations.create() diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index 105752d44b25..d1ae61eb3f7f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -137,7 +137,9 @@ print(f"Processing computer call (ID: {call_id})") # Handle the action and get the screenshot info - screenshot_info, current_state = handle_computer_action_and_take_screenshot(action, current_state, screenshots) + screenshot_info, current_state = handle_computer_action_and_take_screenshot( + action, current_state, screenshots + ) print(f"Sending action result back to agent (using {screenshot_info['filename']})...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py index e8b70bf907a7..bc07bfe319e9 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py @@ -89,9 +89,7 @@ async def main(): project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Initial request with screenshot - start with Bing search page print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py index f88e4cb6630e..078b13c821c7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py @@ -82,9 +82,7 @@ async def main(): project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Prompt the model with tools defined response = await openai_client.responses.create( diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index 6d88341b908a..e62a3bdd52ba 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -97,7 +97,3 @@ ) print(f"Agent response: {response.output_text}") - - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py index 4f57aec97f2b..58419cfde80b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py @@ -65,9 +65,7 @@ async def main(): project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Create a conversation thread to maintain context across multiple interactions conversation = await openai_client.conversations.create() @@ -106,10 +104,6 @@ async def main(): print(f"Agent response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - print("Agent deleted") - if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index 5375bbc603d4..e5757e56d2dc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -101,7 +101,3 @@ ) print(f"Response: {response.output_text}") - - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py index 9737115cde16..1b70de2e42bb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py @@ -68,9 +68,7 @@ async def main(): project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Create a conversation thread to maintain context across multiple interactions conversation = await openai_client.conversations.create() @@ -108,10 +106,6 @@ async def main(): print(f"Response: {response.output_text}") - # Clean up resources by deleting the agent version - # This prevents accumulation of unused agent versions in your project - print("Agent deleted") - if __name__ == "__main__": # Run the async main function diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py index c3f3028ed04d..a19a56920f95 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py @@ -133,7 +133,5 @@ openai_client.conversations.delete(new_conversation.id) print("Conversations deleted") - print("Agent deleted") - project_client.beta.memory_stores.delete(memory_store.name) print("Memory store deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py index 2b2dfafa11b3..50f31bf2ac27 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py @@ -104,9 +104,7 @@ async def main() -> None: project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})" - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") # Create a conversation with the agent with memory tool enabled conversation = await openai_client.conversations.create() @@ -139,8 +137,6 @@ async def main() -> None: await openai_client.conversations.delete(new_conversation.id) print("Conversations deleted") - print("Agent deleted") - await project_client.beta.memory_stores.delete(memory_store.name) print("Memory store deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py index 866a825bea48..4c2ca5aad051 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py @@ -106,9 +106,7 @@ async def main() -> None: project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): agent = await project_client.agents.get(agent_name=AGENT_NAME) - print( - f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})." - ) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version}).") response = await openai_client.responses.create( input="What is my username in Github profile?", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py index 62353ed618d0..a6159e1c1dcb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py @@ -20,4 +20,4 @@ _SPEC.loader.exec_module(_MODULE) create_version_with_endpoint = _MODULE.create_version_with_endpoint -create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async \ No newline at end of file +create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async diff --git a/sdk/ai/azure-ai-projects/samples/util.py b/sdk/ai/azure-ai-projects/samples/util.py index 932b57913bfe..94e9e1799a5d 100644 --- a/sdk/ai/azure-ai-projects/samples/util.py +++ b/sdk/ai/azure-ai-projects/samples/util.py @@ -110,7 +110,7 @@ def create_version_with_endpoint( ] ), protocol_configuration=ProtocolConfiguration(responses=ResponsesProtocolConfiguration()), - ) + ) project_client.agents.update_details(agent_name=agent_name, agent_endpoint=endpoint_config) print(f"Agent endpoint configured for version {created_version.version}") @@ -118,13 +118,11 @@ def create_version_with_endpoint( finally: if original_agent_endpoint is not None: project_client.agents.update_details(agent_name=agent_name, agent_endpoint=original_agent_endpoint) - print("Agent endpoint restored") if created_version is not None: project_client.agents.delete_version( agent_name=agent_name, agent_version=created_version.version, force=True ) - print(f"Hosted agent version {created_version.version} deleted") @asynccontextmanager @@ -170,10 +168,8 @@ async def create_version_with_endpoint_async( finally: if original_agent_endpoint is not None: await project_client.agents.update_details(agent_name=agent_name, agent_endpoint=original_agent_endpoint) - print("Agent endpoint restored") if created_version is not None: await project_client.agents.delete_version( agent_name=agent_name, agent_version=created_version.version, force=True ) - print(f"Hosted agent version {created_version.version} deleted") From 5e6cb1f83ca3edd13bbcd004ae157eb943438f69 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 16:05:34 -0700 Subject: [PATCH 03/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index b90eac7d41a5..bfffdce576e4 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_8013d08d61" + "Tag": "python/ai/azure-ai-projects_1bf6987770" } From 10fbd6547f1580633e055e24c93adee7ba2d6d00 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 21:28:49 -0700 Subject: [PATCH 04/24] Update agent name retrieval to use environment variable with fallback to default value "MyAgent" across multiple sample scripts and tests. --- .../samples/agents/sample_agent_basic.py | 2 +- .../agents/sample_agent_basic_async.py | 2 +- .../agents/sample_agent_retrieve_basic.py | 2 +- .../sample_agent_retrieve_basic_async.py | 2 +- .../agents/sample_agent_stream_events.py | 2 +- .../agents/sample_agent_structured_output.py | 2 +- .../sample_agent_structured_output_async.py | 2 +- .../agents/tools/sample_agent_fabric.py | 2 +- .../agents/tools/sample_agent_fabric_iq.py | 2 +- .../agents/tools/sample_agent_file_search.py | 2 +- ...ple_agent_file_search_structured_inputs.py | 2 +- .../tools/sample_agent_function_tool.py | 2 +- .../tools/sample_agent_function_tool_async.py | 2 +- .../tools/sample_agent_image_generation.py | 2 +- .../sample_agent_image_generation_async.py | 2 +- .../samples/agents/tools/sample_agent_mcp.py | 2 +- .../agents/tools/sample_agent_mcp_async.py | 2 +- ...ample_agent_mcp_with_project_connection.py | 2 +- ...agent_mcp_with_project_connection_async.py | 2 +- .../tools/sample_agent_memory_search.py | 2 +- .../tools/sample_agent_memory_search_async.py | 2 +- .../agents/tools/sample_agent_openapi.py | 2 +- ...e_agent_openapi_with_project_connection.py | 2 +- .../agents/tools/sample_agent_sharepoint.py | 2 +- .../agents/tools/sample_agent_to_agent.py | 2 +- .../agents/tools/sample_agent_web_search.py | 2 +- .../tools/sample_agent_web_search_preview.py | 2 +- ...ple_agent_web_search_with_custom_search.py | 2 +- .../agents/tools/sample_agent_work_iq.py | 2 +- .../tools/sample_agent_work_iq_async.py | 2 +- .../sample_toolboxes_with_search_preview.py | 2 +- ...ple_toolboxes_with_search_preview_async.py | 2 +- .../evaluations/sample_agent_evaluation.py | 2 +- .../sample_agent_response_evaluation.py | 2 +- ..._response_evaluation_with_function_tool.py | 2 +- .../sample_continuous_evaluation_rule.py | 2 +- ...ample_multiturn_conversation_simulation.py | 2 +- .../evaluations/sample_redteam_evaluations.py | 2 +- .../sample_scheduled_evaluations.py | 2 +- .../sample_synthetic_data_agent_evaluation.py | 2 +- sdk/ai/azure-ai-projects/tests/conftest.py | 20 +++++++++++++++++++ sdk/ai/azure-ai-projects/tests/test_base.py | 1 + 42 files changed, 61 insertions(+), 40 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py index 84ce12dd3979..d0036b47d190 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py @@ -37,7 +37,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py index 20af98c88582..d72a62aa793f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py @@ -38,7 +38,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py index cfcc8200e3be..d980732ebd00 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py @@ -39,7 +39,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model = os.environ["FOUNDRY_MODEL_NAME"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py index d1ff140e8041..a97b14f77f95 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py @@ -46,7 +46,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model = os.environ["FOUNDRY_MODEL_NAME"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py index b4e8bc5c0a94..e7b803cc5049 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py @@ -37,7 +37,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py index f927d1c2bf3a..0950cbbd1733 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py @@ -53,7 +53,7 @@ class CalendarEvent(BaseModel): endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py index a3f23c200763..82213fb22c91 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py @@ -46,7 +46,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") class CalendarEvent(BaseModel): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py index ab27add4ae72..c1cb4cbf3d2e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py @@ -41,7 +41,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py index 97776d9db6f8..8d47d2a96bbe 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py @@ -35,7 +35,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py index e6f64c060be0..cdb62d7a2808 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py @@ -55,7 +55,7 @@ # Create agent with file search tool agent = project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that can search through product information.", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py index f9af76a1c920..0188498e3c77 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py @@ -83,7 +83,7 @@ # Create agent with file search tool agent = project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=agent_definition, description="File search agent for product information queries.", ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py index 80a659e351a0..c829e9012be7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py @@ -35,7 +35,7 @@ load_dotenv() -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") def get_horoscope(sign: str) -> str: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py index 078b13c821c7..927d9114971c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py @@ -38,7 +38,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def get_horoscope(sign: str) -> str: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py index e2a5533a2867..30b376598154 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py @@ -55,7 +55,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py index ff286a34bcdf..6c96aa28cedc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py @@ -55,7 +55,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index e62a3bdd52ba..db0776e20783 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -34,7 +34,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py index 58419cfde80b..4633539cbeb9 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py @@ -35,7 +35,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index e5757e56d2dc..af8d0674c4dd 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -36,7 +36,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent7" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py index 1b70de2e42bb..d906814ff09d 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py @@ -37,7 +37,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py index a19a56920f95..add9488be7ec 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py @@ -49,7 +49,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py index 50f31bf2ac27..90bac741f81b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py @@ -48,7 +48,7 @@ load_dotenv() -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py index dbdd1a9cc0d7..6fbe68f75df4 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py @@ -40,7 +40,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py index abd15eef4006..f0a95aa7cb44 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py @@ -44,7 +44,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py index 62a8f517901b..50832674d84b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py @@ -41,7 +41,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py index 9f2d41304608..5259c39ebe06 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py @@ -43,7 +43,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py index b1f4b19fcf81..d25cedfb823f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py @@ -48,7 +48,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py index dc004755cc2b..4b3203cb0da7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py @@ -44,7 +44,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent105" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py index 102d109f7337..80ae0eb5aa84 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py @@ -53,7 +53,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py index ef0aff98dab1..990de95f638e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py @@ -35,7 +35,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py index 95b721023949..3bd37599440a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py @@ -36,7 +36,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py index 3ec7e9343b6f..915452eb68f5 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py @@ -55,7 +55,7 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py index 4c2ca5aad051..aec943359ce0 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py @@ -56,7 +56,7 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py index 5a930105fb95..56695a4bb03c 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py @@ -54,7 +54,7 @@ project_client.get_openai_client() as openai_client, ): agent = project_client.agents.create_version( - agent_name=os.environ["FOUNDRY_AGENT_NAME"], + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=model_deployment_name, instructions="You are a helpful assistant that answers general questions", diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py index 2e60f43b3430..3b63dd923ac4 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py @@ -55,7 +55,7 @@ ): agent = project_client.agents.create_version( - agent_name=os.environ["FOUNDRY_AGENT_NAME"], + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions", diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py index 03d33aa6dd40..77dc5aba4649 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py @@ -85,7 +85,7 @@ def get_horoscope(sign: str) -> str: project_client.get_openai_client() as openai_client, ): agent = project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=model_deployment_name, instructions="You are a helpful assistant that can use function tools.", diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py index ea1591a95a41..3a508b9992e2 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py @@ -63,7 +63,7 @@ # Create agent agent = project_client.agents.create_version( - agent_name=os.environ["FOUNDRY_AGENT_NAME"], + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions", diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py index 6dd7db32cd9f..47a04a909fe6 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py @@ -51,7 +51,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model_deployment_name = os.environ["FOUNDRY_MODEL_NAME"] -agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") # Path to the simulation scenarios data file script_dir = os.path.dirname(os.path.abspath(__file__)) diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py index a88d71125b12..1ec69606d828 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py @@ -48,7 +48,7 @@ def main() -> None: # pylint: disable=too-many-statements load_dotenv() # endpoint = os.environ.get("FOUNDRY_PROJECT_ENDPOINT", "") - agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "") + agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py index 8762ed0a9541..832ac536de4d 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py @@ -328,7 +328,7 @@ def schedule_redteam_evaluation() -> None: # pylint: disable=too-many-locals load_dotenv() # endpoint = os.environ.get("FOUNDRY_PROJECT_ENDPOINT", "") - agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "") + agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") # Construct the paths to the data folder and data file used in this sample script_dir = os.path.dirname(os.path.abspath(__file__)) diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py index dada3b8e2418..f4235a5d14f7 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py @@ -51,7 +51,7 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] model_deployment_name = os.environ["FOUNDRY_MODEL_NAME"] -agent_name = os.environ["FOUNDRY_AGENT_NAME"] +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/tests/conftest.py b/sdk/ai/azure-ai-projects/tests/conftest.py index 4ea07947a42e..5d5722183e64 100644 --- a/sdk/ai/azure-ai-projects/tests/conftest.py +++ b/sdk/ai/azure-ai-projects/tests/conftest.py @@ -52,6 +52,7 @@ class SanitizedValues: ACCOUNT_NAME = "sanitized-account-name" PROJECT_NAME = "sanitized-project-name" COMPONENT_NAME = "sanitized-component-name" + AGENT_NAME = "sanitized-agent-name" AGENTS_API_VERSION = "sanitized-api-version" API_KEY = "sanitized-api-key" MODEL_DEPLOYMENT_NAME = "sanitized-model-deployment-name" @@ -65,6 +66,7 @@ def sanitized_values(): "project_name": f"{SanitizedValues.PROJECT_NAME}", "account_name": f"{SanitizedValues.ACCOUNT_NAME}", "component_name": f"{SanitizedValues.COMPONENT_NAME}", + "agent_name": f"{SanitizedValues.AGENT_NAME}", "agents_api_version": f"{SanitizedValues.AGENTS_API_VERSION}", "api_key": f"{SanitizedValues.API_KEY}", "model_deployment_name": f"{SanitizedValues.MODEL_DEPLOYMENT_NAME}", @@ -260,6 +262,24 @@ def sanitize_url_paths(): value=sanitized_values["model_deployment_name"], ) + agent_names = { + value + for value in ( + os.environ.get("FOUNDRY_AGENT_NAME"), + os.environ.get("foundry_agent_name"), + ) + if value and value != sanitized_values["agent_name"] + } + for agent_name in agent_names: + add_general_regex_sanitizer( + regex=re.escape(agent_name), + value=sanitized_values["agent_name"], + ) + add_body_string_sanitizer( + target=agent_name, + value=sanitized_values["agent_name"], + ) + # Deterministic fallback sanitization for model deployment names returned by # OpenAI-compatible endpoints. These can appear in response bodies and headers # even when the live value was not supplied through a known environment variable. diff --git a/sdk/ai/azure-ai-projects/tests/test_base.py b/sdk/ai/azure-ai-projects/tests/test_base.py index ed71677fe225..4069479fdcb3 100644 --- a/sdk/ai/azure-ai-projects/tests/test_base.py +++ b/sdk/ai/azure-ai-projects/tests/test_base.py @@ -41,6 +41,7 @@ "", foundry_project_endpoint="https://sanitized-account-name.services.ai.azure.com/api/projects/sanitized-project-name", foundry_project_api_key="sanitized-api-key", + foundry_agent_name="sanitized-agent-name", foundry_model_name="sanitized-model-deployment-name", llm_validation_project_endpoint="https://sanitized-account-name.services.ai.azure.com/api/projects/sanitized-project-name", image_generation_model_deployment_name="sanitized-gpt-image", From 4c75eecacd467bacc1439118fcdcd39c3f9940cd Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 21:55:28 -0700 Subject: [PATCH 05/24] Update asset tag in assets.json for versioning --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index bfffdce576e4..f8cdf0473dca 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_1bf6987770" + "Tag": "python/ai/azure-ai-projects_3adea0edfc" } From 01074b63890daa2d8a8d6120f006c3f7f1747189 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Thu, 9 Jul 2026 22:08:03 -0700 Subject: [PATCH 06/24] Update asset tag in assets.json for versioning --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index f8cdf0473dca..19dc8875351a 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_3adea0edfc" + "Tag": "python/ai/azure-ai-projects_2769f09075" } From b94c5b6b00ed161111cc7aa7c0a950d6ff4c6e2b Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 08:00:34 -0700 Subject: [PATCH 07/24] sample update --- .../sample_agent_basic_with_azure_monitor_tracing.py | 2 +- .../telemetry/sample_agent_basic_with_console_tracing.py | 2 +- ...mple_agent_basic_with_console_tracing_custom_attributes.py | 4 +++- .../samples/agents/tools/sample_agent_ai_search.py | 2 +- .../samples/agents/tools/sample_agent_azure_function.py | 2 +- .../samples/agents/tools/sample_agent_bing_custom_search.py | 2 +- .../samples/agents/tools/sample_agent_bing_grounding.py | 2 +- .../samples/agents/tools/sample_agent_browser_automation.py | 2 +- .../samples/agents/tools/sample_agent_code_interpreter.py | 2 +- .../agents/tools/sample_agent_code_interpreter_async.py | 2 +- .../tools/sample_agent_code_interpreter_structured_inputs.py | 2 +- .../agents/tools/sample_agent_code_interpreter_with_files.py | 2 +- .../tools/sample_agent_code_interpreter_with_files_async.py | 2 +- .../samples/agents/tools/sample_agent_computer_use.py | 2 +- .../samples/agents/tools/sample_agent_computer_use_async.py | 2 +- .../samples/agents/tools/sample_agent_fabric_iq_async.py | 2 +- 16 files changed, 18 insertions(+), 16 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py index ef5de04537ea..4fba56cee889 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py @@ -42,7 +42,7 @@ load_dotenv() agent = None -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py index 792476344e09..a0090e7849ff 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py @@ -83,7 +83,7 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o AIProjectInstrumentor().instrument() scenario = os.path.basename(__file__) -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with tracer.start_as_current_span(scenario): with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py index 5bfcea4034e0..365f8ba721f7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py @@ -94,7 +94,9 @@ def on_end(self, span: ReadableSpan): instructions="You are a helpful assistant that answers general questions", ) - agent = client.agents.create_version(agent_name="MyAgent", definition=agent_definition) + agent = client.agents.create_version( + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=agent_definition + ) client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py index 36ee0ecc6f37..abbe3c2e0a2e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py @@ -43,7 +43,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py index 9873cad9fd8f..7d6b547ed529 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py @@ -46,7 +46,7 @@ agent = None endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index 197dc91d1394..eac2d03d8600 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py @@ -52,7 +52,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py index 7a1fd853f451..3a7aae939c11 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py @@ -57,7 +57,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index a335eb19f971..529ad09c55c3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -41,7 +41,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py index 8bdb3fce1d9d..d0fee296faa7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py @@ -33,7 +33,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index 6b9251eead47..0e61ae964f18 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -34,7 +34,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py index 15921ab7fd2c..0a048c3941de 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py @@ -74,7 +74,7 @@ # Create agent with code interpreter tool agent = project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=agent_definition, description="Code interpreter agent for data analysis and visualization.", ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py index 3421bd5715d9..71405243cecc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py @@ -55,7 +55,7 @@ # Create agent with code interpreter tool agent = project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant.", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py index 88b59c545e49..86323422c7f1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py @@ -57,7 +57,7 @@ async def main() -> None: # Create agent with code interpreter tool agent = await project_client.agents.create_version( - agent_name="MyAgent", + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant.", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index d1ae61eb3f7f..bca1fe6b43b2 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -47,7 +47,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py index bc07bfe319e9..ddfe17dfc710 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py @@ -47,7 +47,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = "MyAgent" +AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py index fb7c36a98a11..a9c695567487 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py @@ -36,7 +36,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -agent_name = "MyAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): From e383ebf4e7ff70207ef4c78ce9e453f4446d6c43 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 08:40:22 -0700 Subject: [PATCH 08/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- .../samples/agents/sample_agent_basic.py | 105 +++++++++++------ .../agents/sample_agent_basic_async.py | 108 ++++++++++++------ 3 files changed, 140 insertions(+), 75 deletions(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 19dc8875351a..f7062560e81e 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_2769f09075" + "Tag": "python/ai/azure-ai-projects_8401b0201f" } diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py index d0036b47d190..4534b5d7f27e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py @@ -25,14 +25,21 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os from dotenv import load_dotenv -from util import create_version_with_endpoint from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient -from azure.ai.projects.models import PromptAgentDefinition +from azure.ai.projects.models import ( + AgentEndpointConfig, + FixedRatioVersionSelectionRule, + PromptAgentDefinition, + ProtocolConfiguration, + ResponsesProtocolConfiguration, + VersionSelector, +) load_dotenv() @@ -42,39 +49,63 @@ with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ), - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - conversation = openai_client.conversations.create( - items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], - ) - print(f"Created conversation with initial user message (id: {conversation.id})") - - response = openai_client.responses.create( - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - openai_client.conversations.items.create( - conversation_id=conversation.id, - items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], - ) - print("Added a second user message to the conversation") - - response = openai_client.responses.create( - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - openai_client.conversations.delete(conversation_id=conversation.id) - print("Conversation deleted") + created_version = None + original_agent_endpoint = None + + try: + created_version = project_client.agents.create_version( + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + ), + ) + + original_agent_endpoint = project_client.agents.get(agent_name=agent_name).agent_endpoint + endpoint_config = AgentEndpointConfig( + version_selector=VersionSelector( + version_selection_rules=[ + FixedRatioVersionSelectionRule(agent_version=created_version.version, traffic_percentage=100), + ] + ), + protocol_configuration=ProtocolConfiguration(responses=ResponsesProtocolConfiguration()), + ) + project_client.agents.update_details(agent_name=agent_name, agent_endpoint=endpoint_config) + print(f"Agent endpoint configured for version {created_version.version}") + + with project_client.get_openai_client(agent_name=agent_name) as openai_client: + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + conversation = openai_client.conversations.create( + items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], + ) + print(f"Created conversation with initial user message (id: {conversation.id})") + + response = openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + openai_client.conversations.items.create( + conversation_id=conversation.id, + items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], + ) + print("Added a second user message to the conversation") + + response = openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + openai_client.conversations.delete(conversation_id=conversation.id) + print("Conversation deleted") + finally: + if original_agent_endpoint is not None: + project_client.agents.update_details(agent_name=agent_name, agent_endpoint=original_agent_endpoint) + + if created_version is not None: + project_client.agents.delete_version( + agent_name=agent_name, agent_version=created_version.version, force=True + ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py index d72a62aa793f..ca8fb15d1e7a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py @@ -25,15 +25,22 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import asyncio import os from dotenv import load_dotenv -from util import create_version_with_endpoint_async from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient -from azure.ai.projects.models import PromptAgentDefinition +from azure.ai.projects.models import ( + AgentEndpointConfig, + FixedRatioVersionSelectionRule, + PromptAgentDefinition, + ProtocolConfiguration, + ResponsesProtocolConfiguration, + VersionSelector, +) load_dotenv() @@ -45,42 +52,69 @@ async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - create_version_with_endpoint_async( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions.", - ), - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = await project_client.agents.get(agent_name=agent_name) - print(f"Agent created (name: {agent.name}, id: {agent.id}, version: {agent.versions.latest.version})") - - conversation = await openai_client.conversations.create( - items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], - ) - print(f"Created conversation with initial user message (id: {conversation.id})") - - response = await openai_client.responses.create( - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - await openai_client.conversations.items.create( - conversation_id=conversation.id, - items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], - ) - print("Added a second user message to the conversation") - - response = await openai_client.responses.create( - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - await openai_client.conversations.delete(conversation_id=conversation.id) - print("Conversation deleted") + created_version = None + original_agent_endpoint = None + + try: + created_version = await project_client.agents.create_version( + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions.", + ), + ) + + original_agent_endpoint = (await project_client.agents.get(agent_name=agent_name)).agent_endpoint + endpoint_config = AgentEndpointConfig( + version_selector=VersionSelector( + version_selection_rules=[ + FixedRatioVersionSelectionRule(agent_version=created_version.version, traffic_percentage=100), + ] + ), + protocol_configuration=ProtocolConfiguration(responses=ResponsesProtocolConfiguration()), + ) + await project_client.agents.update_details(agent_name=agent_name, agent_endpoint=endpoint_config) + print(f"Agent endpoint configured for version {created_version.version}") + + openai_client = project_client.get_openai_client(agent_name=agent_name) + + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (name: {agent.name}, id: {agent.id}, version: {agent.versions.latest.version})") + + conversation = await openai_client.conversations.create( + items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], + ) + print(f"Created conversation with initial user message (id: {conversation.id})") + + response = await openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + await openai_client.conversations.items.create( + conversation_id=conversation.id, + items=[{"type": "message", "role": "user", "content": "And what is the capital city?"}], + ) + print("Added a second user message to the conversation") + + response = await openai_client.responses.create( + conversation=conversation.id, + ) + print(f"Response output: {response.output_text}") + + await openai_client.conversations.delete(conversation_id=conversation.id) + print("Conversation deleted") + finally: + if original_agent_endpoint is not None: + await project_client.agents.update_details( + agent_name=agent_name, agent_endpoint=original_agent_endpoint + ) + + if created_version is not None: + await project_client.agents.delete_version( + agent_name=agent_name, agent_version=created_version.version, force=True + ) if __name__ == "__main__": From df68ff3c70c1c272ee1f5718e6832d3e6e3aa484 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 08:48:52 -0700 Subject: [PATCH 09/24] update comments --- .../samples/agents/sample_agent_retrieve_basic.py | 1 + .../samples/agents/sample_agent_retrieve_basic_async.py | 1 + .../samples/agents/sample_agent_stream_events.py | 1 + .../samples/agents/sample_agent_structured_output.py | 1 + .../samples/agents/sample_agent_structured_output_async.py | 1 + .../sample_agent_basic_with_azure_monitor_tracing.py | 5 +++-- .../telemetry/sample_agent_basic_with_console_tracing.py | 5 +++-- ...e_agent_basic_with_console_tracing_custom_attributes.py | 5 +++-- .../samples/agents/tools/sample_agent_ai_search.py | 7 ++++--- .../samples/agents/tools/sample_agent_azure_function.py | 7 ++++--- .../agents/tools/sample_agent_bing_custom_search.py | 7 ++++--- .../samples/agents/tools/sample_agent_bing_grounding.py | 3 ++- .../agents/tools/sample_agent_browser_automation.py | 3 ++- .../samples/agents/tools/sample_agent_code_interpreter.py | 1 + .../agents/tools/sample_agent_code_interpreter_async.py | 1 + .../sample_agent_code_interpreter_structured_inputs.py | 1 + .../tools/sample_agent_code_interpreter_with_files.py | 1 + .../sample_agent_code_interpreter_with_files_async.py | 1 + .../samples/agents/tools/sample_agent_computer_use.py | 1 + .../agents/tools/sample_agent_computer_use_async.py | 1 + .../samples/agents/tools/sample_agent_fabric.py | 5 +++-- .../samples/agents/tools/sample_agent_fabric_iq.py | 5 +++-- .../samples/agents/tools/sample_agent_fabric_iq_async.py | 5 +++-- .../samples/agents/tools/sample_agent_file_search.py | 1 + .../tools/sample_agent_file_search_structured_inputs.py | 3 ++- .../samples/agents/tools/sample_agent_function_tool.py | 1 + .../agents/tools/sample_agent_function_tool_async.py | 1 + .../samples/agents/tools/sample_agent_image_generation.py | 3 ++- .../agents/tools/sample_agent_image_generation_async.py | 3 ++- .../samples/agents/tools/sample_agent_mcp.py | 1 + .../samples/agents/tools/sample_agent_mcp_async.py | 1 + .../tools/sample_agent_mcp_with_project_connection.py | 3 ++- .../sample_agent_mcp_with_project_connection_async.py | 3 ++- .../samples/agents/tools/sample_agent_memory_search.py | 5 +++-- .../agents/tools/sample_agent_memory_search_async.py | 5 +++-- .../samples/agents/tools/sample_agent_openapi.py | 1 + .../tools/sample_agent_openapi_with_project_connection.py | 3 ++- .../samples/agents/tools/sample_agent_sharepoint.py | 5 +++-- .../samples/agents/tools/sample_agent_to_agent.py | 7 ++++--- .../samples/agents/tools/sample_agent_web_search.py | 1 + .../agents/tools/sample_agent_web_search_preview.py | 1 + .../tools/sample_agent_web_search_with_custom_search.py | 7 ++++--- .../samples/agents/tools/sample_agent_work_iq.py | 5 +++-- .../samples/agents/tools/sample_agent_work_iq_async.py | 5 +++-- .../agents/tools/sample_toolboxes_with_search_preview.py | 3 ++- .../tools/sample_toolboxes_with_search_preview_async.py | 3 ++- .../samples/evaluations/sample_agent_evaluation.py | 4 ++-- .../evaluations/sample_agent_response_evaluation.py | 4 ++-- .../sample_agent_response_evaluation_with_function_tool.py | 1 + .../evaluations/sample_continuous_evaluation_rule.py | 4 ++-- .../sample_multiturn_conversation_simulation.py | 2 +- .../samples/evaluations/sample_redteam_evaluations.py | 2 +- .../samples/evaluations/sample_scheduled_evaluations.py | 2 +- .../evaluations/sample_synthetic_data_agent_evaluation.py | 2 +- 54 files changed, 104 insertions(+), 57 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py index d980732ebd00..98fb61604346 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic.py @@ -26,6 +26,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py index a97b14f77f95..94cafecfbb91 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_retrieve_basic_async.py @@ -26,6 +26,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py index e7b803cc5049..30fe2d135aa1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py @@ -25,6 +25,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py index 0950cbbd1733..5eca564668b4 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py @@ -28,6 +28,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py index 82213fb22c91..f1eea65de8a6 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output_async.py @@ -28,6 +28,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import asyncio diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py index 4fba56cee889..1623b63f0c42 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py @@ -22,9 +22,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is disabled by default. - 4) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat + 5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat messages, which may contain personal data. False by default. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py index a0090e7849ff..60e2eba13e15 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py @@ -21,9 +21,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is disabled by default. - 4) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat + 5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat messages, which may contain personal data. False by default. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py index 365f8ba721f7..d614a13bb45e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py @@ -22,9 +22,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to `true` to enable GenAI telemetry tracing, which is disabled by default. - 4) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat + 5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to `true` to trace the content of chat messages, which may contain personal data. False by default. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py index abbe3c2e0a2e..603b792d0714 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py @@ -21,10 +21,11 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) AI_SEARCH_PROJECT_CONNECTION_ID - The AI Search project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) AI_SEARCH_PROJECT_CONNECTION_ID - The AI Search project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) AI_SEARCH_INDEX_NAME - The name of the AI Search index to use for searching. - 5) AI_SEARCH_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 5) AI_SEARCH_INDEX_NAME - The name of the AI Search index to use for searching. + 6) AI_SEARCH_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py index 7d6b547ed529..2dcea26b85c4 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py @@ -22,9 +22,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) STORAGE_INPUT_QUEUE_NAME - The name of the Azure Storage Queue to use for input and output in the Azure Function tool. - 4) STORAGE_OUTPUT_QUEUE_NAME - The name of the Azure Storage Queue to use for output in the Azure Function tool. - 5) STORAGE_QUEUE_SERVICE_ENDPOINT - The endpoint of the Azure Storage Queue service. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) STORAGE_INPUT_QUEUE_NAME - The name of the Azure Storage Queue to use for input and output in the Azure Function tool. + 5) STORAGE_OUTPUT_QUEUE_NAME - The name of the Azure Storage Queue to use for output in the Azure Function tool. + 6) STORAGE_QUEUE_SERVICE_ENDPOINT - The endpoint of the Azure Storage Queue service. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index eac2d03d8600..598c9b39a42f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py @@ -31,10 +31,11 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID - The Bing Custom Search project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID - The Bing Custom Search project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) BING_CUSTOM_SEARCH_INSTANCE_NAME - The Bing Custom Search instance name - 5) BING_CUSTOM_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 5) BING_CUSTOM_SEARCH_INSTANCE_NAME - The Bing Custom Search instance name + 6) BING_CUSTOM_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py index 3a7aae939c11..fd46977a5aba 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py @@ -39,7 +39,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) BING_PROJECT_CONNECTION_ID - The Bing project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) BING_PROJECT_CONNECTION_ID - The Bing project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index 529ad09c55c3..4cfd05db831a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -21,7 +21,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) BROWSER_AUTOMATION_PROJECT_CONNECTION_ID - The browser automation project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) BROWSER_AUTOMATION_PROJECT_CONNECTION_ID - The browser automation project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py index d0fee296faa7..7866686a2d84 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index 0e61ae964f18..3c82a8587489 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import asyncio diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py index 0a048c3941de..f631ca4ed14b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_structured_inputs.py @@ -27,6 +27,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py index 71405243cecc..c4891fc02731 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py index 86323422c7f1..49a7f1112856 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_with_files_async.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index bca1fe6b43b2..e631a3155e26 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -27,6 +27,7 @@ page of your Microsoft Foundry portal. 2) (Optional) COMPUTER_USE_MODEL_DEPLOYMENT_NAME - The deployment name of the computer-use-preview model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py index ddfe17dfc710..d37c6365df31 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py @@ -27,6 +27,7 @@ page of your Microsoft Foundry portal. 2) (Optional) COMPUTER_USE_MODEL_DEPLOYMENT_NAME - The deployment name of the computer-use-preview model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ # pylint: disable=pointless-string-statement diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py index c1cb4cbf3d2e..be07408214c1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py @@ -21,9 +21,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) FABRIC_PROJECT_CONNECTION_ID - The Fabric project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) FABRIC_PROJECT_CONNECTION_ID - The Fabric project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) FABRIC_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 5) FABRIC_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py index 8d47d2a96bbe..35742a0b9295 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py @@ -21,8 +21,9 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) FABRIC_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the Fabric IQ project connection. - 4) FABRIC_IQ_USER_INPUT - The natural-language question to send to the agent. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) FABRIC_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the Fabric IQ project connection. + 5) FABRIC_IQ_USER_INPUT - The natural-language question to send to the agent. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py index a9c695567487..b81fcc1c5e05 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py @@ -21,8 +21,9 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) FABRIC_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the Fabric IQ project connection. - 4) FABRIC_IQ_USER_INPUT - The natural-language question to send to the agent. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) FABRIC_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the Fabric IQ project connection. + 5) FABRIC_IQ_USER_INPUT - The natural-language question to send to the agent. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py index cdb62d7a2808..fc6e7da22dd8 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search.py @@ -20,6 +20,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py index 0188498e3c77..c2e04b85efa5 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_structured_inputs.py @@ -22,10 +22,11 @@ Set these environment variables with your own values: 1) FOUNDRY_PROJECT_ENDPOINT (preferred) or AZURE_AI_PROJECT_ENDPOINT - The Azure AI Project endpoint. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". NOTES: This sample is intentionally kept very close to `sample_agent_file_search.py`. - It does not include fallback logic. + It demonstrates the same `FOUNDRY_AGENT_NAME` fallback behavior with structured inputs. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py index c829e9012be7..4daf16887f71 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ # pylint: disable=docstring-missing-param,docstring-missing-return,docstring-missing-rtype diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py index 927d9114971c..2dc522f426ec 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py @@ -22,6 +22,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ # pylint: disable=docstring-missing-param,docstring-missing-return,docstring-missing-rtype diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py index 30b376598154..b62359b8b725 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py @@ -32,7 +32,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the chat model (e.g., gpt-4o, gpt-4o-mini, gpt-5o, gpt-5o-mini) used by the Agent for understanding and responding to prompts. This is NOT the image generation model. - 3) IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME - The deployment name of the image generation model (e.g. gpt-image-1) + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME - The deployment name of the image generation model (e.g. gpt-image-1) used by the ImageGenTool. NOTE: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py index 6c96aa28cedc..c5263d9ef407 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py @@ -32,7 +32,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the chat model (e.g., gpt-4o, gpt-4o-mini, gpt-5o, gpt-5o-mini) used by the Agent for understanding and responding to prompts. This is NOT the image generation model. - 3) IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME - The deployment name of the image generation model (e.g. gpt-image-1) + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME - The deployment name of the image generation model (e.g. gpt-image-1) used by the ImageGenTool. NOTE: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index db0776e20783..802f94006e6b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py index 4633539cbeb9..bdaad16a6a4a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index af8d0674c4dd..aa7b3805ec00 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -20,7 +20,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys with key equals to "Authorization" and value to be "Bearer ". Token can be created in https://github.com/settings/personal-access-tokens/new """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py index d906814ff09d..cd1cf90b3dcc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py @@ -20,7 +20,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys with key equals to "Authorization" and value to be "Bearer ". Token can be created in https://github.com/settings/personal-access-tokens/new """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py index add9488be7ec..490e4f7394a3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py @@ -27,9 +27,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the Agent's AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME - The deployment name of the chat model for memory, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME - The deployment name of the chat model for memory, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 4) MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME - The deployment name of the embedding model for memory, + 5) MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME - The deployment name of the embedding model for memory, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py index 90bac741f81b..18425071c3df 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py @@ -27,9 +27,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the Agent's AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME - The deployment name of the chat model for memory, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME - The deployment name of the chat model for memory, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 4) MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME - The deployment name of the embedding model for memory, + 5) MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME - The deployment name of the embedding model for memory, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py index 6fbe68f75df4..432fb2c623f2 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py @@ -21,6 +21,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py index f0a95aa7cb44..625cd76fa5eb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py @@ -22,7 +22,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) OPENAPI_PROJECT_CONNECTION_ID - The OpenAPI project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) OPENAPI_PROJECT_CONNECTION_ID - The OpenAPI project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py index 50832674d84b..facd205cda9e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py @@ -21,9 +21,10 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) SHAREPOINT_PROJECT_CONNECTION_ID - The SharePoint project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) SHAREPOINT_PROJECT_CONNECTION_ID - The SharePoint project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) SHAREPOINT_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 5) SHAREPOINT_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py index 5259c39ebe06..a67eca13799c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py @@ -23,11 +23,12 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) A2A_PROJECT_CONNECTION_ID - The A2A project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) A2A_PROJECT_CONNECTION_ID - The A2A project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) A2A_ENDPOINT - (Optional) If the connection is missing target i.e. if it is of "Custom keys" type, we need to set the A2A + 5) A2A_ENDPOINT - (Optional) If the connection is missing target i.e. if it is of "Custom keys" type, we need to set the A2A endpoint on the tool. - 5) A2A_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 6) A2A_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py index d25cedfb823f..eb4147378004 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py @@ -30,6 +30,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py index 4b3203cb0da7..d178395ea52b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py @@ -30,6 +30,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py index 80ae0eb5aa84..4a1d57efd7b5 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py @@ -31,10 +31,11 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID - The Bing Custom Search project connection ID, + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID - The Bing Custom Search project connection ID, as found in the "Connections" tab in your Microsoft Foundry project. - 4) BING_CUSTOM_SEARCH_INSTANCE_NAME - The Bing Custom Search instance name - 5) BING_CUSTOM_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. + 5) BING_CUSTOM_SEARCH_INSTANCE_NAME - The Bing Custom Search instance name + 6) BING_CUSTOM_USER_INPUT - (Optional) The question to ask. If not set, you will be prompted. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py index 990de95f638e..09e6e2c7c6ca 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py @@ -21,8 +21,9 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection. - 4) WORK_IQ_USER_INPUT - The natural-language question to send to the agent. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection. + 5) WORK_IQ_USER_INPUT - The natural-language question to send to the agent. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py index 3bd37599440a..d0e74c3bb195 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py @@ -21,8 +21,9 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection. - 4) WORK_IQ_USER_INPUT - The natural-language question to send to the agent. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) WORK_IQ_PROJECT_CONNECTION_ID - The fully-qualified resource id of the WorkIQ project connection. + 5) WORK_IQ_USER_INPUT - The natural-language question to send to the agent. """ import os diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py index 915452eb68f5..d9c9d45a3ea9 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py @@ -31,7 +31,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys used by + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys used by the inner MCP server inside the toolbox. """ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py index aec943359ce0..71af3ee3bd1a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py @@ -31,7 +31,8 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. - 3) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys used by + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". + 4) MCP_PROJECT_CONNECTION_ID - The connection resource ID in Custom keys used by the inner MCP server inside the toolbox. """ diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py index 56695a4bb03c..9c9f48b5f6a4 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_evaluation.py @@ -21,9 +21,9 @@ Set these environment variables with your own values: 1) FOUNDRY_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview page of your Microsoft Foundry portal. - 2) FOUNDRY_AGENT_NAME - The name of the AI agent to use for evaluation. - 3) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in + 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py index 3b63dd923ac4..6074d6f3e644 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation.py @@ -21,9 +21,9 @@ Set these environment variables with your own values: 1) FOUNDRY_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview page of your Microsoft Foundry portal. - 2) FOUNDRY_AGENT_NAME - The name of the AI agent to use for evaluation. - 3) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in + 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py index 77dc5aba4649..6ae7d9c8048f 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_agent_response_evaluation_with_function_tool.py @@ -23,6 +23,7 @@ page of your Microsoft Foundry portal. 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ # pylint: disable=docstring-missing-param,docstring-missing-return,docstring-missing-rtype diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py index 3a508b9992e2..89b0f2741a64 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_continuous_evaluation_rule.py @@ -30,9 +30,9 @@ Set these environment variables with your own values: 1) FOUNDRY_PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview page of your Microsoft Foundry portal. - 2) FOUNDRY_AGENT_NAME - The name of the AI agent to use for evaluation. - 3) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in + 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py index 47a04a909fe6..3c0892a97e7b 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_multiturn_conversation_simulation.py @@ -35,7 +35,7 @@ 1) FOUNDRY_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint. 2) FOUNDRY_MODEL_NAME - Required. The model deployment name for the simulator and AI-assisted evaluators. - 3) FOUNDRY_AGENT_NAME - Required. The name of the Foundry agent to simulate against. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py index 1ec69606d828..546ec8ade411 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_redteam_evaluations.py @@ -19,7 +19,7 @@ Set these environment variables with your own values: 1) FOUNDRY_PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your Microsoft Foundry project. It has the form: https://.services.ai.azure.com/api/projects/. - 2) FOUNDRY_AGENT_NAME - Required. The name of the Agent to perform red teaming evaluation on. + 2) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py index 832ac536de4d..cbb22294f3d3 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_scheduled_evaluations.py @@ -24,7 +24,7 @@ 4) DATASET_NAME - Optional. The name of the Dataset to create and use in this sample. 5) DATASET_VERSION - Optional. The version of the Dataset to create and use in this sample. 6) DATA_FOLDER - Optional. The folder path where the data files for upload are located. - 7) FOUNDRY_AGENT_NAME - Required. The name of the Agent to perform red teaming evaluation on. + 7) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ from datetime import datetime diff --git a/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py b/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py index f4235a5d14f7..8ce3ea90d7c9 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/evaluations/sample_synthetic_data_agent_evaluation.py @@ -31,7 +31,7 @@ Microsoft Foundry project. It has the form: https://.services.ai.azure.com/api/projects/. 2) FOUNDRY_MODEL_NAME - Required. The name of the model deployment to use for generating synthetic data and for AI-assisted evaluators. - 3) FOUNDRY_AGENT_NAME - Required. The name of the Foundry agent to evaluate. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os From fccc3445cc3bde56915d1c10dde35aca0670751a Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 09:37:55 -0700 Subject: [PATCH 10/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index f7062560e81e..3f33a3c392e2 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_8401b0201f" + "Tag": "python/ai/azure-ai-projects_13326ed47f" } From ad6f467de4e11472b0a82d63b1b5e8619d5201d1 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 10:21:03 -0700 Subject: [PATCH 11/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 3f33a3c392e2..8b9ce516fff9 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_13326ed47f" + "Tag": "python/ai/azure-ai-projects_db67af458f" } From dd536c135988ff3cb79ca4ecf7769519a6b8204f Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 11:54:41 -0700 Subject: [PATCH 12/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 8b9ce516fff9..060b6d4b5f99 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_db67af458f" + "Tag": "python/ai/azure-ai-projects_fd6bdcfb57" } From 40c8a19a788ca260604d89cfa37ee5476f914fe5 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 12:00:09 -0700 Subject: [PATCH 13/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 060b6d4b5f99..d2220e46624f 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_fd6bdcfb57" + "Tag": "python/ai/azure-ai-projects_78b4b86611" } From d12535449bf4e5558f75c67ce68f2f8f600f5226 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 12:39:00 -0700 Subject: [PATCH 14/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index d2220e46624f..fcec788463a1 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_78b4b86611" + "Tag": "python/ai/azure-ai-projects_44c5336f0c" } From e25419446ad248bcac23dcde5a9c88609eb7e59d Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 15:55:30 -0700 Subject: [PATCH 15/24] sample update --- .../samples/agents/__init__.py | 1 + .../samples/agents/telemetry/__init__.py | 1 + ...sample_agent_basic_with_console_tracing.py | 74 +++---- ..._with_console_tracing_custom_attributes.py | 34 +-- .../samples/agents/telemetry/util.py | 26 ++- .../samples/agents/tools/__init__.py | 1 + .../agents/tools/sample_agent_ai_search.py | 120 ++++++----- .../tools/sample_agent_azure_function.py | 92 ++++----- .../tools/sample_agent_bing_custom_search.py | 112 +++++----- .../tools/sample_agent_bing_grounding.py | 94 +++++---- .../tools/sample_agent_browser_automation.py | 120 ++++++----- .../tools/sample_agent_code_interpreter.py | 64 +++--- .../sample_agent_code_interpreter_async.py | 74 ++++--- .../agents/tools/sample_agent_computer_use.py | 190 +++++++++-------- .../tools/sample_agent_computer_use_async.py | 194 +++++++++--------- .../agents/tools/sample_agent_fabric.py | 98 +++++---- .../agents/tools/sample_agent_fabric_iq.py | 48 +++-- .../tools/sample_agent_fabric_iq_async.py | 46 ++--- .../tools/sample_agent_function_tool.py | 120 ++++++----- .../tools/sample_agent_function_tool_async.py | 120 ++++++----- .../tools/sample_agent_image_generation.py | 79 ++++--- .../sample_agent_image_generation_async.py | 74 +++---- .../samples/agents/tools/sample_agent_mcp.py | 102 +++++---- .../agents/tools/sample_agent_mcp_async.py | 108 +++++----- ...ample_agent_mcp_with_project_connection.py | 104 +++++----- ...agent_mcp_with_project_connection_async.py | 112 +++++----- .../tools/sample_agent_memory_search.py | 152 +++++++------- .../tools/sample_agent_memory_search_async.py | 158 +++++++------- .../agents/tools/sample_agent_openapi.py | 58 +++--- ...e_agent_openapi_with_project_connection.py | 70 +++---- .../agents/tools/sample_agent_sharepoint.py | 108 +++++----- .../agents/tools/sample_agent_to_agent.py | 99 +++++---- .../tools/sample_agent_toolbox_skill.py | 39 ++-- .../agents/tools/sample_agent_web_search.py | 98 +++++---- .../tools/sample_agent_web_search_preview.py | 104 +++++----- ...ple_agent_web_search_with_custom_search.py | 116 +++++------ .../agents/tools/sample_agent_work_iq.py | 46 ++--- .../tools/sample_agent_work_iq_async.py | 44 ++-- .../sample_toolboxes_with_search_preview.py | 30 ++- ...ple_toolboxes_with_search_preview_async.py | 31 ++- .../samples/agents/tools/util.py | 26 ++- .../azure-ai-projects/samples/agents/util.py | 26 ++- 42 files changed, 1668 insertions(+), 1745 deletions(-) create mode 100644 sdk/ai/azure-ai-projects/samples/agents/__init__.py create mode 100644 sdk/ai/azure-ai-projects/samples/agents/telemetry/__init__.py create mode 100644 sdk/ai/azure-ai-projects/samples/agents/tools/__init__.py diff --git a/sdk/ai/azure-ai-projects/samples/agents/__init__.py b/sdk/ai/azure-ai-projects/samples/agents/__init__.py new file mode 100644 index 000000000000..91cacbdf2f80 --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/__init__.py @@ -0,0 +1 @@ +# Package marker for sample type-checking. diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/__init__.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/__init__.py new file mode 100644 index 000000000000..91cacbdf2f80 --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/__init__.py @@ -0,0 +1 @@ +# Package marker for sample type-checking. diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py index 60e2eba13e15..29b08bc6bfd1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py @@ -85,41 +85,41 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o scenario = os.path.basename(__file__) agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") -with tracer.start_as_current_span(scenario): - with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client, - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ), +with ( + tracer.start_as_current_span(scenario), + DefaultAzureCredential() as credential, + AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - conversation = openai_client.conversations.create() - - request = "Hello, tell me a joke." - response = openai_client.responses.create( - conversation=conversation.id, - input=request, - ) - print(f"Answer: {response.output}") - - response = openai_client.responses.create( - conversation=conversation.id, - input="Tell another one about computers.", - ) - print(f"Answer: {response.output}") - - print("\n📋 Listing conversation items...") - items = openai_client.conversations.items.list(conversation_id=conversation.id) - - # Print all the items - for item in items: - display_conversation_item(item) + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + conversation = openai_client.conversations.create() + + request = "Hello, tell me a joke." + response = openai_client.responses.create( + conversation=conversation.id, + input=request, + ) + print(f"Answer: {response.output}") + + response = openai_client.responses.create( + conversation=conversation.id, + input="Tell another one about computers.", + ) + print(f"Answer: {response.output}") + + print("\n📋 Listing conversation items...") + items = openai_client.conversations.items.list(conversation_id=conversation.id) + + # Print all the items + for item in items: + display_conversation_item(item) diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py index d614a13bb45e..5c9fd3e87dba 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing_custom_attributes.py @@ -84,20 +84,20 @@ def on_end(self, span: ReadableSpan): provider.add_span_processor(CustomAttributeSpanProcessor()) scenario = os.path.basename(__file__) -with tracer.start_as_current_span(scenario): - with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as client, - ): - - agent_definition = PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - ) - - agent = client.agents.create_version( - agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=agent_definition - ) - - client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) - print("Agent deleted") +with ( + tracer.start_as_current_span(scenario), + DefaultAzureCredential() as credential, + AIProjectClient(endpoint=endpoint, credential=credential) as client, +): + + agent_definition = PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + ) + + agent = client.agents.create_version( + agent_name=os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent"), definition=agent_definition + ) + + client.agents.delete_version(agent_name=agent.name, agent_version=agent.version) + print("Agent deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py index a6159e1c1dcb..bc55b40b1291 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py @@ -6,18 +6,22 @@ from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path import sys +from typing import TYPE_CHECKING -_AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" -_PKG_ROOT = Path(__file__).resolve().parents[3] -if str(_PKG_ROOT) not in sys.path: - sys.path.insert(0, str(_PKG_ROOT)) +if TYPE_CHECKING: + from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async +else: + _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" + _PKG_ROOT = Path(__file__).resolve().parents[3] + if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) -_SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) -if _SPEC is None or _SPEC.loader is None: - raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") + _SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) + if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") -_MODULE = module_from_spec(_SPEC) -_SPEC.loader.exec_module(_MODULE) + _MODULE = module_from_spec(_SPEC) + _SPEC.loader.exec_module(_MODULE) -create_version_with_endpoint = _MODULE.create_version_with_endpoint -create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async + create_version_with_endpoint = _MODULE.create_version_with_endpoint + create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/__init__.py b/sdk/ai/azure-ai-projects/samples/agents/tools/__init__.py new file mode 100644 index 000000000000..91cacbdf2f80 --- /dev/null +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/__init__.py @@ -0,0 +1 @@ +# Package marker for sample type-checking. diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py index 603b792d0714..6252dc7b3793 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py @@ -46,72 +46,68 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") -with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = AzureAISearchTool( - azure_ai_search=AzureAISearchToolResource( - indexes=[ - AISearchIndexResource( - project_connection_id=os.environ["AI_SEARCH_PROJECT_CONNECTION_ID"], - index_name=os.environ["AI_SEARCH_INDEX_NAME"], - query_type=AzureAISearchQueryType.SIMPLE, - ), - ] - ) +tool = AzureAISearchTool( + azure_ai_search=AzureAISearchToolResource( + indexes=[ + AISearchIndexResource( + project_connection_id=os.environ["AI_SEARCH_PROJECT_CONNECTION_ID"], + index_name=os.environ["AI_SEARCH_INDEX_NAME"], + query_type=AzureAISearchQueryType.SIMPLE, + ), + ] ) +) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="""You are a helpful assistant. You must always provide citations for - answers using the tool and render them as: `\u3010message_idx:search_idx\u2020source\u3011`.""", - tools=[tool], - ), - description="You are a helpful agent.", +with ( + DefaultAzureCredential() as credential, + AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="""You are a helpful assistant. You must always provide citations for + answers using the tool and render them as: `\u3010message_idx:search_idx\u2020source\u3011`.""", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Get user input from environment variable or prompt - user_input = os.environ.get("AI_SEARCH_USER_INPUT") - if not user_input: - user_input = input("Enter your question (e.g., 'Tell me about mental health services'): \n") + description="You are a helpful agent.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=user_input, - ) + # Get user input from environment variable or prompt + user_input = os.environ.get("AI_SEARCH_USER_INPUT") + if not user_input: + user_input = input("Enter your question (e.g., 'Tell me about mental health services'): \n") - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Agent response: {event.response.output_text}") + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=user_input, + ) - print("\nCleaning up...") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Agent response: {event.response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py index 2dcea26b85c4..4c47280ff889 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py @@ -49,58 +49,56 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") -with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = AzureFunctionTool( - azure_function=AzureFunctionDefinition( - input_binding=AzureFunctionBinding( - storage_queue=AzureFunctionStorageQueue( - queue_name=os.environ["STORAGE_INPUT_QUEUE_NAME"], - queue_service_endpoint=os.environ["STORAGE_QUEUE_SERVICE_ENDPOINT"], - ) - ), - output_binding=AzureFunctionBinding( - storage_queue=AzureFunctionStorageQueue( - queue_name=os.environ["STORAGE_OUTPUT_QUEUE_NAME"], - queue_service_endpoint=os.environ["STORAGE_QUEUE_SERVICE_ENDPOINT"], - ) - ), - function=AzureFunctionDefinitionFunction( - name="queue_trigger", - description="Get weather for a given location", - parameters={ - "type": "object", - "properties": {"location": {"type": "string", "description": "location to determine weather for"}}, - }, - ), - ) +tool = AzureFunctionTool( + azure_function=AzureFunctionDefinition( + input_binding=AzureFunctionBinding( + storage_queue=AzureFunctionStorageQueue( + queue_name=os.environ["STORAGE_INPUT_QUEUE_NAME"], + queue_service_endpoint=os.environ["STORAGE_QUEUE_SERVICE_ENDPOINT"], + ) + ), + output_binding=AzureFunctionBinding( + storage_queue=AzureFunctionStorageQueue( + queue_name=os.environ["STORAGE_OUTPUT_QUEUE_NAME"], + queue_service_endpoint=os.environ["STORAGE_QUEUE_SERVICE_ENDPOINT"], + ) + ), + function=AzureFunctionDefinitionFunction( + name="queue_trigger", + description="Get weather for a given location", + parameters={ + "type": "object", + "properties": {"location": {"type": "string", "description": "location to determine weather for"}}, + }, + ), ) +) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), +with ( + DefaultAzureCredential() as credential, + AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = "What is the weather in Seattle?" + user_input = "What is the weather in Seattle?" - response = openai_client.responses.create( - tool_choice="required", - input=user_input, - ) + response = openai_client.responses.create( + tool_choice="required", + input=user_input, + ) - print(f"Response output: {response.output_text}") + print(f"Response output: {response.output_text}") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index 598c9b39a42f..d8ed36141e37 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py @@ -55,67 +55,65 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + +tool = BingCustomSearchPreviewTool( + bing_custom_search_preview=BingCustomSearchToolParameters( + search_configurations=[ + BingCustomSearchConfiguration( + project_connection_id=os.environ["BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID"], + instance_name=os.environ["BING_CUSTOM_SEARCH_INSTANCE_NAME"], + ) + ] + ) +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + 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=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") - tool = BingCustomSearchPreviewTool( - bing_custom_search_preview=BingCustomSearchToolParameters( - search_configurations=[ - BingCustomSearchConfiguration( - project_connection_id=os.environ["BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID"], - instance_name=os.environ["BING_CUSTOM_SEARCH_INSTANCE_NAME"], - ) - ] - ) + # Send initial request that will trigger the Bing Custom Search tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - 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=[tool], - ), - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") - - # Send initial request that will trigger the Bing Custom Search tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - ) - - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("Cleaning up...") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("Cleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py index fd46977a5aba..ade6847db10a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py @@ -60,58 +60,56 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + +tool = BingGroundingTool( + bing_grounding=BingGroundingSearchToolParameters( + search_configurations=[ + BingGroundingSearchConfiguration(project_connection_id=os.environ["BING_PROJECT_CONNECTION_ID"]) + ] + ) +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), + description="You are a helpful agent.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - tool = BingGroundingTool( - bing_grounding=BingGroundingSearchToolParameters( - search_configurations=[ - BingGroundingSearchConfiguration(project_connection_id=os.environ["BING_PROJECT_CONNECTION_ID"]) - ] - ) + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input="What is today's date and whether in Seattle?", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), - description="You are a helpful agent.", - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input="What is today's date and whether in Seattle?", - ) - - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print(f"URL Citation: {annotation.url}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print(f"URL Citation: {annotation.url}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index 4cfd05db831a..4fcd57fbe084 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -42,72 +42,68 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") -with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = BrowserAutomationPreviewTool( - browser_automation_preview=BrowserAutomationToolParameters( - connection=BrowserAutomationToolConnectionParameters( - project_connection_id=os.environ["BROWSER_AUTOMATION_PROJECT_CONNECTION_ID"], - ) +tool = BrowserAutomationPreviewTool( + browser_automation_preview=BrowserAutomationToolParameters( + connection=BrowserAutomationToolConnectionParameters( + project_connection_id=os.environ["BROWSER_AUTOMATION_PROJECT_CONNECTION_ID"], ) ) +) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - 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=[tool], - ), +with ( + DefaultAzureCredential() as credential, + AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + 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=[tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=""" - 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.""", - ) + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=""" + 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.""", + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - item = event.item - if ( - item.type == "browser_automation_preview_call" - ): # TODO: support browser_automation_preview_call schema - arguments_str = getattr(item, "arguments", "{}") - - # Parse the arguments string into a dictionary - arguments = json.loads(arguments_str) - query = arguments.get("query") - - print(f"Call ID: {getattr(item, 'call_id')}") - print(f"Query arguments: {query}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + item = event.item + if item.type == "browser_automation_preview_call": # TODO: support browser_automation_preview_call schema + arguments_str = getattr(item, "arguments", "{}") + + # Parse the arguments string into a dictionary + arguments = json.loads(arguments_str) + query = arguments.get("query") + + print(f"Call ID: {getattr(item, 'call_id')}") + print(f"Query arguments: {query}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py index 7866686a2d84..b8c3c893bb27 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py @@ -34,46 +34,44 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[CodeInterpreterTool()], - ), - description="Code interpreter agent for data analysis and visualization.", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[CodeInterpreterTool()], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + description="Code interpreter agent for data analysis and visualization.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") - # Send request for the agent to generate a multiplication chart. - response = openai_client.responses.create( - conversation=conversation.id, - input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", - tool_choice="required", - ) - print(f"Response completed (id: {response.id})") + # Send request for the agent to generate a multiplication chart. + response = openai_client.responses.create( + conversation=conversation.id, + input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", + tool_choice="required", + ) + print(f"Response completed (id: {response.id})") - # Print code executed by the code interpreter tool. - code = next((output.code for output in response.output if output.type == "code_interpreter_call"), "") - print("Code Interpreter code:") - print(code) + # Print code executed by the code interpreter tool. + code = next((output.code for output in response.output if output.type == "code_interpreter_call"), "") + print("Code Interpreter code:") + print(code) - # Print final assistant text output. - print(f"Agent response: {response.output_text}") + # Print final assistant text output. + print(f"Agent response: {response.output_text}") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index 3c82a8587489..deb49bf3b063 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -35,51 +35,49 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - ): - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[CodeInterpreterTool()], - ), - description="Code interpreter agent for data analysis and visualization.", + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[CodeInterpreterTool()], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation for the agent interaction - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send request for the agent to generate a multiplication chart. - response = await openai_client.responses.create( - conversation=conversation.id, - input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", - tool_choice="required", - ) - print(f"Response completed (id: {response.id})") - - # Print code executed by the code interpreter tool. - code = next((output.code for output in response.output if output.type == "code_interpreter_call"), None) - if code: - print(f"Code Interpreter code:\n {code}") - - # Print final assistant text output. - print(f"Agent response: {response.output_text}") - - print("\nCleaning up...") + description="Code interpreter agent for data analysis and visualization.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send request for the agent to generate a multiplication chart. + response = await openai_client.responses.create( + conversation=conversation.id, + input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?", + tool_choice="required", + ) + print(f"Response completed (id: {response.id})") + + # Print code executed by the code interpreter tool. + code = next((output.code for output in response.output if output.type == "code_interpreter_call"), None) + if code: + print(f"Code Interpreter code:\n {code}") + + # Print final assistant text output. + print(f"Agent response: {response.output_text}") + + print("\nCleaning up...") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index e631a3155e26..00975014798a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -48,118 +48,114 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + +# Initialize state machine +current_state = SearchState.INITIAL + +# Load screenshot assets +try: + screenshots = load_screenshot_assets() + print("Successfully loaded screenshot assets") +except FileNotFoundError: + print("Failed to load required screenshot assets. Please ensure the asset files exist in ../assets/") + exit(1) # pylint: disable=consider-using-sys-exit + +tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - # Initialize state machine - current_state = SearchState.INITIAL - - # Load screenshot assets - try: - screenshots = load_screenshot_assets() - print("Successfully loaded screenshot assets") - except FileNotFoundError: - print("Failed to load required screenshot assets. Please ensure the asset files exist in ../assets/") - exit(1) # pylint: disable=consider-using-sys-exit - - tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), - instructions=""" - You are a computer automation assistant. - - Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. - """, - tools=[tool], - ), - description="Computer automation agent with screen interaction capabilities.", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), + instructions=""" + You are a computer automation assistant. + + Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. + """, + tools=[tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Initial request with screenshot - start with Bing search page - print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") - response = openai_client.responses.create( - input=[ - { - "role": "user", - "content": [ - { - "type": "input_text", - "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", - }, - { - "type": "input_image", - "image_url": screenshots["browser_search"]["url"], - "detail": "high", - }, - ], - } - ], - truncation="auto", - ) + description="Computer automation agent with screen interaction capabilities.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Initial request with screenshot - start with Bing search page + print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") + response = openai_client.responses.create( + input=[ + { + "role": "user", + "content": [ + { + "type": "input_text", + "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", + }, + { + "type": "input_image", + "image_url": screenshots["browser_search"]["url"], + "detail": "high", + }, + ], + } + ], + truncation="auto", + ) - print(f"Initial response received (ID: {response.id})") + print(f"Initial response received (ID: {response.id})") - # Main interaction loop with deterministic completion - max_iterations = 10 # Allow enough iterations for completion - iteration = 0 + # Main interaction loop with deterministic completion + max_iterations = 10 # Allow enough iterations for completion + iteration = 0 - while True: - if iteration >= max_iterations: - print(f"\nReached maximum iterations ({max_iterations}). Stopping.") - break + while True: + if iteration >= max_iterations: + print(f"\nReached maximum iterations ({max_iterations}). Stopping.") + break - iteration += 1 - print(f"\n--- Iteration {iteration} ---") + iteration += 1 + print(f"\n--- Iteration {iteration} ---") - # Check for computer calls in the response - computer_calls = [item for item in response.output if item.type == "computer_call"] + # Check for computer calls in the response + computer_calls = [item for item in response.output if item.type == "computer_call"] - if not computer_calls: - print_final_output(response) - break + if not computer_calls: + print_final_output(response) + break - # Process the first computer call - computer_call = computer_calls[0] - action = computer_call.action - call_id = computer_call.call_id + # Process the first computer call + computer_call = computer_calls[0] + action = computer_call.action + call_id = computer_call.call_id - print(f"Processing computer call (ID: {call_id})") + print(f"Processing computer call (ID: {call_id})") - # Handle the action and get the screenshot info - screenshot_info, current_state = handle_computer_action_and_take_screenshot( - action, current_state, screenshots - ) + # Handle the action and get the screenshot info + screenshot_info, current_state = handle_computer_action_and_take_screenshot(action, current_state, screenshots) - print(f"Sending action result back to agent (using {screenshot_info['filename']})...") + print(f"Sending action result back to agent (using {screenshot_info['filename']})...") - # Regular response with just the screenshot - response = openai_client.responses.create( - previous_response_id=response.id, - input=[ - { - "call_id": call_id, - "type": "computer_call_output", - "output": { - "type": "computer_screenshot", - "image_url": screenshot_info["url"], - }, - } - ], - truncation="auto", - ) + # Regular response with just the screenshot + response = openai_client.responses.create( + previous_response_id=response.id, + input=[ + { + "call_id": call_id, + "type": "computer_call_output", + "output": { + "type": "computer_screenshot", + "image_url": screenshot_info["url"], + }, + } + ], + truncation="auto", + ) - print(f"Follow-up response received (ID: {response.id})") + print(f"Follow-up response received (ID: {response.id})") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py index d37c6365df31..3ac457361d7a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py @@ -48,126 +48,122 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): + """Main async function to demonstrate Computer Use Agent functionality.""" + # Initialize state machine + current_state = SearchState.INITIAL + + # Load screenshot assets + try: + screenshots = load_screenshot_assets() + print("Successfully loaded screenshot assets") + except FileNotFoundError: + print("Failed to load required screenshot assets. Please ensure the asset files exist in ../assets/") + return + + computer_use_tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - ): - - """Main async function to demonstrate Computer Use Agent functionality.""" - # Initialize state machine - current_state = SearchState.INITIAL - - # Load screenshot assets - try: - screenshots = load_screenshot_assets() - print("Successfully loaded screenshot assets") - except FileNotFoundError: - print("Failed to load required screenshot assets. Please ensure the asset files exist in ../assets/") - return - - computer_use_tool = ComputerUsePreviewTool(display_width=1026, display_height=769, environment="windows") - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), - instructions=""" - You are a computer automation assistant. - - Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. - """, - tools=[computer_use_tool], - ), - description="Computer automation agent with screen interaction capabilities.", + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ.get("COMPUTER_USE_MODEL_DEPLOYMENT_NAME", "computer-use-preview"), + instructions=""" + You are a computer automation assistant. + + Be direct and efficient. When you reach the search results page, read and describe the actual search result titles and descriptions you can see. + """, + tools=[computer_use_tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Initial request with screenshot - start with Bing search page - print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") - response = await openai_client.responses.create( - input=[ - { - "role": "user", - "content": [ - { - "type": "input_text", - "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", - }, - { - "type": "input_image", - "image_url": screenshots["browser_search"]["url"], - "detail": "high", - }, - ], - } - ], - truncation="auto", - ) + description="Computer automation agent with screen interaction capabilities.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Initial request with screenshot - start with Bing search page + print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") + response = await openai_client.responses.create( + input=[ + { + "role": "user", + "content": [ + { + "type": "input_text", + "text": "I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete.", + }, + { + "type": "input_image", + "image_url": screenshots["browser_search"]["url"], + "detail": "high", + }, + ], + } + ], + truncation="auto", + ) - print(f"Initial response received (ID: {response.id})") + print(f"Initial response received (ID: {response.id})") - # Main interaction loop with deterministic completion - max_iterations = 10 # Allow enough iterations for completion - iteration = 0 + # Main interaction loop with deterministic completion + max_iterations = 10 # Allow enough iterations for completion + iteration = 0 - while True: - if iteration >= max_iterations: - print(f"\nReached maximum iterations ({max_iterations}). Stopping.") - break + while True: + if iteration >= max_iterations: + print(f"\nReached maximum iterations ({max_iterations}). Stopping.") + break - iteration += 1 - print(f"\n--- Iteration {iteration} ---") + iteration += 1 + print(f"\n--- Iteration {iteration} ---") - # Check for computer calls in the response - computer_calls = [item for item in response.output if item.type == "computer_call"] + # Check for computer calls in the response + computer_calls = [item for item in response.output if item.type == "computer_call"] - if not computer_calls: - print_final_output(response) - break + if not computer_calls: + print_final_output(response) + break - # Process the first computer call - computer_call = computer_calls[0] - action = computer_call.action - call_id = computer_call.call_id + # Process the first computer call + computer_call = computer_calls[0] + action = computer_call.action + call_id = computer_call.call_id - print(f"Processing computer call (ID: {call_id})") + print(f"Processing computer call (ID: {call_id})") - # Handle the action and get the screenshot info - screenshot_info, current_state = handle_computer_action_and_take_screenshot( - action, current_state, screenshots - ) + # Handle the action and get the screenshot info + screenshot_info, current_state = handle_computer_action_and_take_screenshot( + action, current_state, screenshots + ) - print(f"Sending action result back to agent (using {screenshot_info['filename']})...") + print(f"Sending action result back to agent (using {screenshot_info['filename']})...") - # Regular response with just the screenshot - response = await openai_client.responses.create( - previous_response_id=response.id, - input=[ - { - "call_id": call_id, - "type": "computer_call_output", - "output": { - "type": "computer_screenshot", - "image_url": screenshot_info["url"], - }, - } - ], - truncation="auto", - ) + # Regular response with just the screenshot + response = await openai_client.responses.create( + previous_response_id=response.id, + input=[ + { + "call_id": call_id, + "type": "computer_call_output", + "output": { + "type": "computer_screenshot", + "image_url": screenshot_info["url"], + }, + } + ], + truncation="auto", + ) - print(f"Follow-up response received (ID: {response.id})") + print(f"Follow-up response received (ID: {response.id})") - print("\nCleaning up...") + print("\nCleaning up...") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py index be07408214c1..9ba09bfe62d0 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py @@ -44,62 +44,58 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool = MicrosoftFabricPreviewTool( + fabric_dataagent_preview=FabricDataAgentToolParameters( + project_connections=[ToolProjectConnection(project_connection_id=os.environ["FABRIC_PROJECT_CONNECTION_ID"])] + ) +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = MicrosoftFabricPreviewTool( - fabric_dataagent_preview=FabricDataAgentToolParameters( - project_connections=[ - ToolProjectConnection(project_connection_id=os.environ["FABRIC_PROJECT_CONNECTION_ID"]) - ] - ) - ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_USER_INPUT") or input("Enter your question: \n") + user_input = os.environ.get("FABRIC_USER_INPUT") or input("Enter your question: \n") - stream_response = openai_client.responses.create( - tool_choice="required", - stream=True, - input=user_input, - ) + stream_response = openai_client.responses.create( + tool_choice="required", + stream=True, + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py index 35742a0b9295..5b09dd6eede5 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py @@ -38,36 +38,34 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool_payload = FabricIQPreviewTool( + project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], + require_approval="never", +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool_payload = FabricIQPreviewTool( - project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], - require_approval="never", - ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", - tools=[tool_payload], - ), + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", + tools=[tool_payload], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") - response = openai_client.responses.create( - input=user_input, - ) + response = openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # The helper restores the endpoint and deletes the temporary version automatically. + # The helper restores the endpoint and deletes the temporary version automatically. diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py index b81fcc1c5e05..a0c85a5246c1 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq_async.py @@ -41,37 +41,35 @@ async def main(): + tool_payload = FabricIQPreviewTool( + project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], + require_approval="never", + ) + async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - ): - tool_payload = FabricIQPreviewTool( - project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], - require_approval="never", - ) - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", - tools=[tool_payload], - ), + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available Fabric IQ tools to answer questions and perform tasks.", + tools=[tool_payload], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = await project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") - response = await openai_client.responses.create( - input=user_input, - ) + response = await openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py index 4daf16887f71..df5ade86b1cb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py @@ -36,7 +36,7 @@ load_dotenv() -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") def get_horoscope(sign: str) -> str: @@ -46,74 +46,72 @@ def get_horoscope(sign: str) -> str: endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] + +tool = FunctionTool( + name="get_horoscope", + parameters={ + "type": "object", + "properties": { + "sign": { + "type": "string", + "description": "An astrological sign like Taurus or Aquarius", + }, + }, + "required": ["sign"], + "additionalProperties": False, + }, + description="Get today's horoscope for an astrological sign.", + strict=True, +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can use function tools.", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - tool = FunctionTool( - name="get_horoscope", - parameters={ - "type": "object", - "properties": { - "sign": { - "type": "string", - "description": "An astrological sign like Taurus or Aquarius", - }, - }, - "required": ["sign"], - "additionalProperties": False, - }, - description="Get today's horoscope for an astrological sign.", - strict=True, + # Prompt the model with tools defined + response = openai_client.responses.create( + input="What is my horoscope? I am an Aquarius.", ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can use function tools.", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Prompt the model with tools defined - response = openai_client.responses.create( - input="What is my horoscope? I am an Aquarius.", - ) - print(f"Response output: {response.output_text}") - - input_list: ResponseInputParam = [] - # Process function calls - for item in response.output: - if item.type == "function_call": - if item.name == "get_horoscope": - # Execute the function logic for get_horoscope - horoscope = get_horoscope(**json.loads(item.arguments)) - - # Provide function call results to the model - input_list.append( - FunctionCallOutput( - type="function_call_output", - call_id=item.call_id, - output=json.dumps({"horoscope": horoscope}), - ) + print(f"Response output: {response.output_text}") + + input_list: ResponseInputParam = [] + # Process function calls + for item in response.output: + if item.type == "function_call": + if item.name == "get_horoscope": + # Execute the function logic for get_horoscope + horoscope = get_horoscope(**json.loads(item.arguments)) + + # Provide function call results to the model + input_list.append( + FunctionCallOutput( + type="function_call_output", + call_id=item.call_id, + output=json.dumps({"horoscope": horoscope}), ) + ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py index 2dc522f426ec..55d1d574cc09 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool_async.py @@ -39,7 +39,7 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def get_horoscope(sign: str) -> str: @@ -48,75 +48,73 @@ async def get_horoscope(sign: str) -> str: async def main(): + # Define a function tool for the model to use + func_tool = FunctionTool( + name="get_horoscope", + parameters={ + "type": "object", + "properties": { + "sign": { + "type": "string", + "description": "An astrological sign like Taurus or Aquarius", + }, + }, + "required": ["sign"], + "additionalProperties": False, + }, + description="Get today's horoscope for an astrological sign.", + strict=True, + ) + async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can use function tools.", + tools=[func_tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - # Define a function tool for the model to use - func_tool = FunctionTool( - name="get_horoscope", - parameters={ - "type": "object", - "properties": { - "sign": { - "type": "string", - "description": "An astrological sign like Taurus or Aquarius", - }, - }, - "required": ["sign"], - "additionalProperties": False, - }, - description="Get today's horoscope for an astrological sign.", - strict=True, - ) + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can use function tools.", - tools=[func_tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Prompt the model with tools defined - response = await openai_client.responses.create( - input="What is my horoscope? I am an Aquarius.", - ) - print(f"Response output: {response.output_text}") - - input_list: ResponseInputParam = [] - # Process function calls - for item in response.output: - if item.type == "function_call": - if item.name == "get_horoscope": - # Execute the function logic for get_horoscope - horoscope = await get_horoscope(**json.loads(item.arguments)) - - # Provide function call results to the model - input_list.append( - FunctionCallOutput( - type="function_call_output", - call_id=item.call_id, - output=json.dumps({"horoscope": horoscope}), - ) + # Prompt the model with tools defined + response = await openai_client.responses.create( + input="What is my horoscope? I am an Aquarius.", + ) + print(f"Response output: {response.output_text}") + + input_list: ResponseInputParam = [] + # Process function calls + for item in response.output: + if item.type == "function_call": + if item.name == "get_horoscope": + # Execute the function logic for get_horoscope + horoscope = await get_horoscope(**json.loads(item.arguments)) + + # Provide function call results to the model + input_list.append( + FunctionCallOutput( + type="function_call_output", + call_id=item.call_id, + output=json.dumps({"horoscope": horoscope}), ) + ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py index b62359b8b725..e96509dc8e51 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py @@ -46,6 +46,7 @@ import base64 import os import tempfile +from pathlib import Path from dotenv import load_dotenv from util import create_version_with_endpoint @@ -57,52 +58,46 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] + +tool = ImageGenTool( + model=image_generation_model, # Model such as "gpt-image-1" + quality="low", + size="1024x1024", +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Generate images based on user prompts", + tools=[tool], + ), + description="Agent for image generation.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] - - tool = ImageGenTool( - model=image_generation_model, # Model such as "gpt-image-1" - quality="low", - size="1024x1024", + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + response = openai_client.responses.create( + input="Generate an image of Microsoft logo.", + extra_headers={ + "x-ms-oai-image-generation-deployment": image_generation_model + }, # this is required at the moment for image generation ) + print(f"Response created: {response.id}") - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Generate images based on user prompts", - tools=[tool], - ), - description="Agent for image generation.", - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - response = openai_client.responses.create( - input="Generate an image of Microsoft logo.", - extra_headers={ - "x-ms-oai-image-generation-deployment": image_generation_model - }, # this is required at the moment for image generation - ) - print(f"Response created: {response.id}") - - print("\nCleaning up...") - - image_data = [output.result for output in response.output if output.type == "image_generation_call"] - if image_data and image_data[0]: - print("Downloading generated image...") - filename = "microsoft.png" - file_path = os.path.join(tempfile.gettempdir(), filename) - - with open(file_path, "wb") as f: - f.write(base64.b64decode(image_data[0])) - - print(f"Image saved to: {file_path}") + print("\nCleaning up...") + + image_data = [output.result for output in response.output if output.type == "image_generation_call"] + if image_data and image_data[0]: + print("Downloading generated image...") + filename = "microsoft.png" + file_path = Path(tempfile.gettempdir()) / filename + file_path.write_bytes(base64.b64decode(image_data[0])) + print(f"Image saved to: {file_path}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py index c5263d9ef407..cd6444fdcdf3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation_async.py @@ -47,6 +47,7 @@ import base64 import os import tempfile +from pathlib import Path from dotenv import load_dotenv from util import create_version_with_endpoint_async @@ -57,53 +58,46 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - ): - - image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Generate images based on user prompts", - tools=[ImageGenTool(model=image_generation_model, quality="low", size="1024x1024")], - ), - description="Agent for image generation.", + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Generate images based on user prompts", + tools=[ImageGenTool(model=image_generation_model, quality="low", size="1024x1024")], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = await project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - response = await openai_client.responses.create( - input="Generate an image of Microsoft logo.", - extra_headers={ - "x-ms-oai-image-generation-deployment": image_generation_model - }, # this is required at the moment for image generation - ) - print(f"Response created: {response.id}") - - print("\nCleaning up...") - - # Save the image to a file - image_data = [output.result for output in response.output if output.type == "image_generation_call"] - if image_data and image_data[0]: - print("Downloading generated image...") - filename = "microsoft.png" - file_path = os.path.join(tempfile.gettempdir(), filename) - - with open(file_path, "wb") as f: - f.write(base64.b64decode(image_data[0])) - - print(f"Image saved to: {file_path}") + description="Agent for image generation.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + response = await openai_client.responses.create( + input="Generate an image of Microsoft logo.", + extra_headers={ + "x-ms-oai-image-generation-deployment": image_generation_model + }, # this is required at the moment for image generation + ) + print(f"Response created: {response.id}") + + print("\nCleaning up...") + + # Save the image to a file + image_data = [output.result for output in response.output if output.type == "image_generation_call"] + if image_data and image_data[0]: + print("Downloading generated image...") + filename = "microsoft.png" + file_path = Path(tempfile.gettempdir()) / filename + file_path.write_bytes(base64.b64decode(image_data[0])) + print(f"Image saved to: {file_path}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index 802f94006e6b..7c9c0422376b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -35,66 +35,64 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + +mcp_tool = MCPTool( + server_label="api-specs", + server_url="https://gitmcp.io/Azure/azure-rest-api-specs", + require_approval="always", +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", + tools=[mcp_tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - mcp_tool = MCPTool( - server_label="api-specs", - server_url="https://gitmcp.io/Azure/azure-rest-api-specs", - require_approval="always", + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation thread to maintain context across multiple interactions + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = openai_client.responses.create( + conversation=conversation.id, + input="Please summarize the Azure REST API specifications Readme", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", - tools=[mcp_tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = openai_client.responses.create( - conversation=conversation.id, - input="Please summarize the Azure REST API specifications Readme", - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, - ) + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, ) + ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py index bdaad16a6a4a..83eb878eb648 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_async.py @@ -36,74 +36,72 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): + mcp_tool = MCPTool( + server_label="api-specs", + server_url="https://gitmcp.io/Azure/azure-rest-api-specs", + require_approval="always", + ) + + # Create tools list with proper typing for the agent definition + tools: list[Tool] = [mcp_tool] + async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", + tools=tools, + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - mcp_tool = MCPTool( - server_label="api-specs", - server_url="https://gitmcp.io/Azure/azure-rest-api-specs", - require_approval="always", + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation thread to maintain context across multiple interactions + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = await openai_client.responses.create( + conversation=conversation.id, + input="Please summarize the Azure REST API specifications Readme", ) - # Create tools list with proper typing for the agent definition - tools: list[Tool] = [mcp_tool] - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful agent that can use MCP tools to assist users. Use the available MCP tools to answer questions and perform tasks.", - tools=tools, - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = await openai_client.responses.create( - conversation=conversation.id, - input="Please summarize the Azure REST API specifications Readme", - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, - ) + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, ) + ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index aa7b3805ec00..cd1778d579d9 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -37,68 +37,66 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + + +tool = MCPTool( + server_label="api-specs", + server_url="https://api.githubcopilot.com/mcp", + require_approval="always", + project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use MCP tools as needed", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - tool = MCPTool( - server_label="api-specs", - server_url="https://api.githubcopilot.com/mcp", - require_approval="always", - project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], + # Create a conversation thread to maintain context across multiple interactions + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = openai_client.responses.create( + conversation=conversation.id, + input="What is my username in Github profile?", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use MCP tools as needed", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = openai_client.responses.create( - conversation=conversation.id, - input="What is my username in Github profile?", - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, - ) + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, ) + ) - print("Final input:") - print(input_list) + print("Final input:") + print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print(f"Response: {response.output_text}") + print(f"Response: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py index cd1cf90b3dcc..d9dbcd020214 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection_async.py @@ -38,74 +38,72 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main(): + mcp_tool = MCPTool( + server_label="api-specs", + server_url="https://api.githubcopilot.com/mcp", + require_approval="always", + project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], + ) + + # Create tools list with proper typing for the agent definition + tools: list[Tool] = [mcp_tool] + async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use MCP tools as needed", + tools=tools, + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - mcp_tool = MCPTool( - server_label="api-specs", - server_url="https://api.githubcopilot.com/mcp", - require_approval="always", - project_connection_id=os.environ["MCP_PROJECT_CONNECTION_ID"], + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation thread to maintain context across multiple interactions + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send initial request that will trigger the MCP tool + response = await openai_client.responses.create( + conversation=conversation.id, + input="What is my username in GitHub profile?", ) - # Create tools list with proper typing for the agent definition - tools: list[Tool] = [mcp_tool] - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use MCP tools as needed", - tools=tools, - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation thread to maintain context across multiple interactions - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send initial request that will trigger the MCP tool - response = await openai_client.responses.create( - conversation=conversation.id, - input="What is my username in GitHub profile?", - ) - - # Process any MCP approval requests that were generated - input_list: ResponseInputParam = [] - for item in response.output: - if item.type == "mcp_approval_request": - if item.server_label == "api-specs" and item.id: - # Automatically approve the MCP request to allow the agent to proceed - # In production, you might want to implement more sophisticated approval logic - input_list.append( - McpApprovalResponse( - type="mcp_approval_response", - approve=True, - approval_request_id=item.id, - ) + # Process any MCP approval requests that were generated + input_list: ResponseInputParam = [] + for item in response.output: + if item.type == "mcp_approval_request": + if item.server_label == "api-specs" and item.id: + # Automatically approve the MCP request to allow the agent to proceed + # In production, you might want to implement more sophisticated approval logic + input_list.append( + McpApprovalResponse( + type="mcp_approval_response", + approve=True, + approval_request_id=item.id, ) + ) + + print("Final input:") + print(input_list) + # Send the approval response back to continue the agent's work + # This allows the MCP tool to access the GitHub repository and complete the original request + response = await openai_client.responses.create( + input=input_list, + previous_response_id=response.id, + ) - print("Final input:") - print(input_list) - # Send the approval response back to continue the agent's work - # This allows the MCP tool to access the GitHub repository and complete the original request - response = await openai_client.responses.create( - input=input_list, - previous_response_id=response.id, - ) - - print(f"Response: {response.output_text}") + print(f"Response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py index 490e4f7394a3..da339d10d3bd 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search.py @@ -52,87 +52,87 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +credential = DefaultAzureCredential() +project_client = AIProjectClient(endpoint=endpoint, credential=credential) + +# Delete memory store, if it already exists +memory_store_name = "my_memory_store" +try: + project_client.beta.memory_stores.delete(memory_store_name) + print(f"Memory store `{memory_store_name}` deleted") +except ResourceNotFoundError: + pass + +# Create a memory store +definition = MemoryStoreDefaultDefinition( + chat_model=os.environ["MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME"], + embedding_model=os.environ["MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME"], +) +memory_store = project_client.beta.memory_stores.create( + name=memory_store_name, + description="Example memory store for conversations", + definition=definition, +) +print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}") + +# Set scope to associate the memories with +# You can also use "{{$userId}}" to take the oid of the request authentication header +scope = "user_123" + +tool = MemorySearchPreviewTool( + memory_store_name=memory_store.name, + scope=scope, + update_delay=1, # Wait 1 second of inactivity before updating memories + # In a real application, set this to a higher value like 300 (5 minutes, default) +) + with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + credential, + project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): + agent = project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Delete memory store, if it already exists - memory_store_name = "my_memory_store" - try: - project_client.beta.memory_stores.delete(memory_store_name) - print(f"Memory store `{memory_store_name}` deleted") - except ResourceNotFoundError: - pass - - # Create a memory store - definition = MemoryStoreDefaultDefinition( - chat_model=os.environ["MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME"], - embedding_model=os.environ["MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME"], - ) - memory_store = project_client.beta.memory_stores.create( - name=memory_store_name, - description="Example memory store for conversations", - definition=definition, + # Create a conversation with the agent with memory tool enabled + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Create an agent response to initial user message + response = openai_client.responses.create( + input="I prefer dark roast coffee", + conversation=conversation.id, ) - print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}") + print(f"Response output: {response.output_text}") - # Set scope to associate the memories with - # You can also use "{{$userId}}" to take the oid of the request authentication header - scope = "user_123" + # After an inactivity in the conversation, memories will be extracted from the conversation and stored + print("Waiting for memories to be stored...") + time.sleep(60) - tool = MemorySearchPreviewTool( - memory_store_name=memory_store.name, - scope=scope, - update_delay=1, # Wait 1 second of inactivity before updating memories - # In a real application, set this to a higher value like 300 (5 minutes, default) + # Create a new conversation + new_conversation = openai_client.conversations.create() + print(f"Created new conversation (id: {new_conversation.id})") + + # Create an agent response with stored memories + new_response = openai_client.responses.create( + input="Please order my usual coffee", + conversation=new_conversation.id, ) + print(f"Response output: {new_response.output_text}") - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation with the agent with memory tool enabled - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Create an agent response to initial user message - response = openai_client.responses.create( - input="I prefer dark roast coffee", - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - # After an inactivity in the conversation, memories will be extracted from the conversation and stored - print("Waiting for memories to be stored...") - time.sleep(60) - - # Create a new conversation - new_conversation = openai_client.conversations.create() - print(f"Created new conversation (id: {new_conversation.id})") - - # Create an agent response with stored memories - new_response = openai_client.responses.create( - input="Please order my usual coffee", - conversation=new_conversation.id, - ) - print(f"Response output: {new_response.output_text}") - - # Clean up - openai_client.conversations.delete(conversation.id) - openai_client.conversations.delete(new_conversation.id) - print("Conversations deleted") - - project_client.beta.memory_stores.delete(memory_store.name) - print("Memory store deleted") + # Clean up + openai_client.conversations.delete(conversation.id) + openai_client.conversations.delete(new_conversation.id) + print("Conversations deleted") + +project_client.beta.memory_stores.delete(memory_store.name) +print("Memory store deleted") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py index 18425071c3df..7f151e983e4c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_memory_search_async.py @@ -56,90 +56,90 @@ async def main() -> None: endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] + credential = DefaultAzureCredential() + project_client = AIProjectClient(endpoint=endpoint, credential=credential) + + # Delete memory store, if it already exists + memory_store_name = "my_memory_store" + try: + await project_client.beta.memory_stores.delete(memory_store_name) + print(f"Memory store `{memory_store_name}` deleted") + except ResourceNotFoundError: + pass + + # Create a memory store + definition = MemoryStoreDefaultDefinition( + chat_model=os.environ["MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME"], + embedding_model=os.environ["MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME"], + ) + memory_store = await project_client.beta.memory_stores.create( + name=memory_store_name, + description="Example memory store for conversations", + definition=definition, + ) + print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}") + + # Set scope to associate the memories with + # You can also use "{{$userId}}" to take the oid of the request authentication header + scope = "user_123" + async with ( - DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + credential, + project_client, + create_version_with_endpoint_async( + project_client=project_client, + agent_name=AGENT_NAME, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that answers general questions", + tools=[ + MemorySearchPreviewTool( + memory_store_name=memory_store.name, + scope=scope, + update_delay=1, # Wait 1 second of inactivity before updating memories + # In a real application, set this to a higher value like 300 (5 minutes, default) + ) + ], + ), + ), + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): + agent = await project_client.agents.get(agent_name=AGENT_NAME) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation with the agent with memory tool enabled + conversation = await openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") - # Delete memory store, if it already exists - memory_store_name = "my_memory_store" - try: - await project_client.beta.memory_stores.delete(memory_store_name) - print(f"Memory store `{memory_store_name}` deleted") - except ResourceNotFoundError: - pass - - # Create a memory store - definition = MemoryStoreDefaultDefinition( - chat_model=os.environ["MEMORY_STORE_CHAT_MODEL_DEPLOYMENT_NAME"], - embedding_model=os.environ["MEMORY_STORE_EMBEDDING_MODEL_DEPLOYMENT_NAME"], + # Create an agent response to initial user message + response = await openai_client.responses.create( + input="I prefer dark roast coffee", + conversation=conversation.id, ) - memory_store = await project_client.beta.memory_stores.create( - name=memory_store_name, - description="Example memory store for conversations", - definition=definition, + print(f"Response output: {response.output_text}") + + # After an inactivity in the conversation, memories will be extracted from the conversation and stored + print("Waiting for memories to be stored...") + await asyncio.sleep(60) + + # Create a new conversation + new_conversation = await openai_client.conversations.create() + print(f"Created new conversation (id: {new_conversation.id})") + + # Create an agent response with stored memories + new_response = await openai_client.responses.create( + input="Please order my usual coffee", + conversation=new_conversation.id, ) - print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}") - - # Set scope to associate the memories with - # You can also use "{{$userId}}" to take the oid of the request authentication header - scope = "user_123" - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that answers general questions", - tools=[ - MemorySearchPreviewTool( - memory_store_name=memory_store.name, - scope=scope, - update_delay=1, # Wait 1 second of inactivity before updating memories - # In a real application, set this to a higher value like 300 (5 minutes, default) - ) - ], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation with the agent with memory tool enabled - conversation = await openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Create an agent response to initial user message - response = await openai_client.responses.create( - input="I prefer dark roast coffee", - conversation=conversation.id, - ) - print(f"Response output: {response.output_text}") - - # After an inactivity in the conversation, memories will be extracted from the conversation and stored - print("Waiting for memories to be stored...") - await asyncio.sleep(60) - - # Create a new conversation - new_conversation = await openai_client.conversations.create() - print(f"Created new conversation (id: {new_conversation.id})") - - # Create an agent response with stored memories - new_response = await openai_client.responses.create( - input="Please order my usual coffee", - conversation=new_conversation.id, - ) - print(f"Response output: {new_response.output_text}") - - # Clean up - await openai_client.conversations.delete(conversation.id) - await openai_client.conversations.delete(new_conversation.id) - print("Conversations deleted") - - await project_client.beta.memory_stores.delete(memory_store.name) - print("Memory store deleted") + print(f"Response output: {new_response.output_text}") + + # Clean up + await openai_client.conversations.delete(conversation.id) + await openai_client.conversations.delete(new_conversation.id) + print("Conversations deleted") + + await project_client.beta.memory_stores.delete(memory_store.name) + print("Memory store deleted") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py index 432fb2c623f2..88043057aab2 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py @@ -26,6 +26,7 @@ import os from typing import Any, cast +from pathlib import Path import jsonref from dotenv import load_dotenv from util import create_version_with_endpoint @@ -42,41 +43,36 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +weather_asset_file_path = Path(__file__).resolve().parent / "../assets/weather_openapi.json" +openapi_weather = cast(dict[str, Any], jsonref.loads(weather_asset_file_path.read_text(encoding="utf-8"))) + +tool = OpenApiTool( + openapi=OpenApiFunctionDefinition( + name="get_weather", + spec=openapi_weather, + description="Retrieve weather information for a location.", + auth=OpenApiAnonymousAuthDetails(), + ) +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - weather_asset_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/weather_openapi.json")) + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - with open(weather_asset_file_path, "r", encoding="utf-8") as f: - openapi_weather = cast(dict[str, Any], jsonref.loads(f.read())) - - tool = OpenApiTool( - openapi=OpenApiFunctionDefinition( - name="get_weather", - spec=openapi_weather, - description="Retrieve weather information for a location.", - auth=OpenApiAnonymousAuthDetails(), - ) + response = openai_client.responses.create( + input="Use the OpenAPI tool to print out, what is the weather in Seattle today.", ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - response = openai_client.responses.create( - input="Use the OpenAPI tool to print out, what is the weather in Seattle today.", - ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py index 625cd76fa5eb..948e3a399365 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py @@ -29,6 +29,7 @@ import os from typing import Any, cast +from pathlib import Path import jsonref from dotenv import load_dotenv from util import create_version_with_endpoint @@ -46,48 +47,41 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tripadvisor_asset_file_path = Path(__file__).resolve().parent / "../assets/tripadvisor_openapi.json" +openapi_tripadvisor = cast(dict[str, Any], jsonref.loads(tripadvisor_asset_file_path.read_text(encoding="utf-8"))) + +tool = OpenApiTool( + openapi=OpenApiFunctionDefinition( + name="tripadvisor", + spec=openapi_tripadvisor, + description="Trip Advisor API to get travel information", + auth=OpenApiProjectConnectionAuthDetails( + security_scheme=OpenApiProjectConnectionSecurityScheme( + project_connection_id=os.environ["OPENAPI_PROJECT_CONNECTION_ID"] + ) + ), + ) +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - tripadvisor_asset_file_path = os.path.abspath( - os.path.join(os.path.dirname(__file__), "../assets/tripadvisor_openapi.json") - ) - - with open(tripadvisor_asset_file_path, "r", encoding="utf-8") as f: - openapi_tripadvisor = cast(dict[str, Any], jsonref.loads(f.read())) + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - tool = OpenApiTool( - openapi=OpenApiFunctionDefinition( - name="tripadvisor", - spec=openapi_tripadvisor, - description="Trip Advisor API to get travel information", - auth=OpenApiProjectConnectionAuthDetails( - security_scheme=OpenApiProjectConnectionSecurityScheme( - project_connection_id=os.environ["OPENAPI_PROJECT_CONNECTION_ID"] - ) - ), - ) + response = openai_client.responses.create( + input="Recommend me 5 top hotels in the United States", ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - response = openai_client.responses.create( - input="Recommend me 5 top hotels in the United States", - ) - # The response to the question may contain non ASCII letters. To avoid error, encode and re decode them. - print(f"Response created: {response.output_text.encode().decode('ascii', errors='ignore')}") + # The response to the question may contain non ASCII letters. To avoid error, encode and re decode them. + print(f"Response created: {response.output_text.encode().decode('ascii', errors='ignore')}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py index facd205cda9e..8e5e69979adb 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py @@ -44,66 +44,64 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool = SharepointPreviewTool( + sharepoint_grounding_preview=SharepointGroundingToolParameters( + project_connections=[ + ToolProjectConnection(project_connection_id=os.environ["SHAREPOINT_PROJECT_CONNECTION_ID"]) + ] + ) +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = SharepointPreviewTool( - sharepoint_grounding_preview=SharepointGroundingToolParameters( - project_connections=[ - ToolProjectConnection(project_connection_id=os.environ["SHAREPOINT_PROJECT_CONNECTION_ID"]) - ] - ) - ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="""You are a helpful agent that can use SharePoint tools to assist users. - Use the available SharePoint tools to answer questions and perform tasks.""", - tools=[tool], - ), + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="""You are a helpful agent that can use SharePoint tools to assist users. + Use the available SharePoint tools to answer questions and perform tasks.""", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Get user input from environment variable or prompt - user_input = os.environ.get("SHAREPOINT_USER_INPUT") - if not user_input: - user_input = input("Enter your question corresponded to the documents in SharePoint:\n") + # Get user input from environment variable or prompt + user_input = os.environ.get("SHAREPOINT_USER_INPUT") + if not user_input: + user_input = input("Enter your question corresponded to the documents in SharePoint:\n") - # Send initial request that will trigger the SharePoint tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - ) + # Send initial request that will trigger the SharePoint tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Agent response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Agent response: {event.response.output_text}") - print("Cleaning up...") + print("Cleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py index a67eca13799c..533c72188e9c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py @@ -44,64 +44,61 @@ load_dotenv() endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") + +tool = A2APreviewTool( + project_connection_id=os.environ["A2A_PROJECT_CONNECTION_ID"], +) +# If the connection is missing target, we need to set the A2A endpoint URL. +if os.environ.get("A2A_ENDPOINT"): + tool.base_url = os.environ["A2A_ENDPOINT"] with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant.", + tools=[tool], + ), + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - tool = A2APreviewTool( - project_connection_id=os.environ["A2A_PROJECT_CONNECTION_ID"], + user_input = os.environ.get("A2A_USER_INPUT") or input( + "Enter your question (e.g., 'What can the secondary agent do?'): \n" ) - # If the connection is missing target, we need to set the A2A endpoint URL. - if os.environ.get("A2A_ENDPOINT"): - tool.base_url = os.environ["A2A_ENDPOINT"] - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant.", - tools=[tool], - ), - ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - user_input = os.environ.get("A2A_USER_INPUT") or input( - "Enter your question (e.g., 'What can the secondary agent do?'): \n" - ) - - stream_response = openai_client.responses.create( - stream=True, - tool_choice="required", - input=user_input, - ) + stream_response = openai_client.responses.create( + stream=True, + tool_choice="required", + input=user_input, + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - item = event.item - if item.type == "a2a_preview_call": - print(f"Request ID: {getattr(item, 'id')}") - if hasattr(item, "model_extra"): - extra = getattr(item, "model_extra") - if isinstance(extra, dict): - print(f"Arguments: {extra['arguments']}") - elif item.type == "a2a_preview_call_output": - print(f"Response ID: {getattr(item, 'id')}") - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + item = event.item + if item.type == "a2a_preview_call": + print(f"Request ID: {getattr(item, 'id')}") + if hasattr(item, "model_extra"): + extra = getattr(item, "model_extra") + if isinstance(extra, dict): + print(f"Arguments: {extra['arguments']}") + elif item.type == "a2a_preview_call_output": + print(f"Response ID: {getattr(item, 'id')}") + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py index 847b725548be..f4e0e7de9e38 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_toolbox_skill.py @@ -33,12 +33,12 @@ 2) FOUNDRY_MODEL_NAME - The deployment name of the AI model, as found under the "Name" column in the "Models + endpoints" tab in your Microsoft Foundry project. + 3) FOUNDRY_AGENT_NAME - Optional. The name of the AI agent. If not set, defaults to "MyAgent". """ import os from dotenv import load_dotenv -from util import create_version_with_endpoint from azure.ai.projects.models._models import ToolboxSearchPreviewToolboxTool from azure.core.exceptions import ResourceNotFoundError @@ -52,6 +52,7 @@ ToolboxSearchPreviewToolboxTool, ToolboxSkillReference, ) +from util import create_version_with_endpoint load_dotenv() @@ -59,12 +60,13 @@ SKILL_NAME = "shipping-cost-skill" TOOLBOX_NAME = "toolbox_with_skill" -AGENT_NAME = "SkillToolboxAgent" +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): try: @@ -110,27 +112,22 @@ require_approval="never", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Answer the user using the `shipping-cost-skill` instructions " - "available in your context. Do not call `tool_search`; the " - "skill rules are already part of your knowledge. Apply the " - "skill's formula exactly as given and state the formula in " - "your answer." - ), - temperature=0, - tools=[toolbox_mcp_tool], + with create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Answer the user using the `shipping-cost-skill` instructions " + "available in your context. Do not call `tool_search`; the " + "skill rules are already part of your knowledge. Apply the " + "skill's formula exactly as given and state the formula in " + "your answer." ), + temperature=0, + tools=[toolbox_mcp_tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id={agent.id}, name={agent.name}, version={agent.versions.latest.version})") + ) as agent: user_input = "Compute the shipping cost for a 3 kg package shipped domestically." print(f"User: {user_input}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py index eb4147378004..c72f74ca2b81 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py @@ -51,60 +51,58 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool = WebSearchTool(user_location=WebSearchApproximateLocation(country="GB", city="London", region="London")) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = WebSearchTool(user_location=WebSearchApproximateLocation(country="GB", city="London", region="London")) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web", - tools=[tool], - ), - description="Agent for web search.", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - # Create Agent with web search tool - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + description="Agent for web search.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + # Create Agent with web search tool + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") - # Send a query to search the web - user_input = "Show me the latest London Underground service updates" - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - ) + # Send a query to search the web + user_input = "Show me the latest London Underground service updates" + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", + ) - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - print("\nCleaning up...") + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py index d178395ea52b..8315c168ae2c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py @@ -47,60 +47,58 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool = WebSearchPreviewTool(user_location=ApproximateLocation(country="GB", city="London", region="London")) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool = WebSearchPreviewTool(user_location=ApproximateLocation(country="GB", city="London", region="London")) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web", - tools=[tool], - ), - description="Agent for web search.", + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web", + tools=[tool], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - # Send a query to search the web - user_input = "Show me the latest London Underground service updates" - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - ) - - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") + description="Agent for web search.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + # Send a query to search the web + user_input = "Show me the latest London Underground service updates" + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", + ) + + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py index 4a1d57efd7b5..3afa6088b344 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py @@ -56,67 +56,65 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool = WebSearchTool( + custom_search_configuration=WebSearchConfiguration( + project_connection_id=os.environ["BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID"], + instance_name=os.environ["BING_CUSTOM_SEARCH_INSTANCE_NAME"], + ) +) with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="You are a helpful assistant that can search the web and bing", + tools=[tool], + ), + description="Agent for web search.", + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - tool = WebSearchTool( - custom_search_configuration=WebSearchConfiguration( - project_connection_id=os.environ["BING_CUSTOM_SEARCH_PROJECT_CONNECTION_ID"], - instance_name=os.environ["BING_CUSTOM_SEARCH_INSTANCE_NAME"], - ) + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + + # Create a conversation for the agent interaction + conversation = openai_client.conversations.create() + print(f"Created conversation (id: {conversation.id})") + + user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") + + # Send a query to search the web + # Send initial request that will trigger the Bing Custom Search tool + stream_response = openai_client.responses.create( + stream=True, + input=user_input, + tool_choice="required", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="You are a helpful assistant that can search the web and bing", - tools=[tool], - ), - description="Agent for web search.", - ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - - # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() - print(f"Created conversation (id: {conversation.id})") - - user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") - - # Send a query to search the web - # Send initial request that will trigger the Bing Custom Search tool - stream_response = openai_client.responses.create( - stream=True, - input=user_input, - tool_choice="required", - ) - - for event in stream_response: - if event.type == "response.created": - print(f"Follow-up response created with ID: {event.response.id}") - elif event.type == "response.output_text.delta": - print(f"Delta: {event.delta}") - elif event.type == "response.text.done": - print("\nFollow-up response done!") - elif event.type == "response.output_item.done": - if event.item.type == "message": - item = event.item - if item.content[-1].type == "output_text": - text_content = item.content[-1] - for annotation in text_content.annotations: - if annotation.type == "url_citation": - print( - f"URL Citation: {annotation.url}, " - f"Start index: {annotation.start_index}, " - f"End index: {annotation.end_index}" - ) - elif event.type == "response.completed": - print("\nFollow-up completed!") - print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") + + for event in stream_response: + if event.type == "response.created": + print(f"Follow-up response created with ID: {event.response.id}") + elif event.type == "response.output_text.delta": + print(f"Delta: {event.delta}") + elif event.type == "response.text.done": + print("\nFollow-up response done!") + elif event.type == "response.output_item.done": + if event.item.type == "message": + item = event.item + if item.content[-1].type == "output_text": + text_content = item.content[-1] + for annotation in text_content.annotations: + if annotation.type == "url_citation": + print( + f"URL Citation: {annotation.url}, " + f"Start index: {annotation.start_index}, " + f"End index: {annotation.end_index}" + ) + elif event.type == "response.completed": + print("\nFollow-up completed!") + print(f"Full response: {event.response.output_text}") + + print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py index 09e6e2c7c6ca..b3e4aa676591 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py @@ -38,35 +38,33 @@ endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"] agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +tool_payload = WorkIQPreviewTool( + project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], +) + with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, -): - tool_payload = WorkIQPreviewTool( - project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], - ) - - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available WorkIQ tools to answer questions and perform tasks.", - tools=[tool_payload], - ), + create_version_with_endpoint( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available WorkIQ tools to answer questions and perform tasks.", + tools=[tool_payload], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, +): + agent = project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") - response = openai_client.responses.create( - input=user_input, - ) + response = openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") - # The helper restores the endpoint and deletes the temporary version automatically. + # The helper restores the endpoint and deletes the temporary version automatically. diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py index d0e74c3bb195..ee64be8153ea 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq_async.py @@ -41,36 +41,34 @@ async def main(): + tool_payload = WorkIQPreviewTool( + project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], + ) + async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - ): - tool_payload = WorkIQPreviewTool( - project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], - ) - - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=agent_name, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions="Use the available WorkIQ tools to answer questions and perform tasks.", - tools=[tool_payload], - ), + create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions="Use the available WorkIQ tools to answer questions and perform tasks.", + tools=[tool_payload], ), - project_client.get_openai_client(agent_name=agent_name) as openai_client, - ): - agent = await project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") + ), + project_client.get_openai_client(agent_name=agent_name) as openai_client, + ): + agent = await project_client.agents.get(agent_name=agent_name) + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") + user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") - response = await openai_client.responses.create( - input=user_input, - ) + response = await openai_client.responses.create( + input=user_input, + ) - print(f"Agent response: {response.output_text}") + print(f"Agent response: {response.output_text}") if __name__ == "__main__": diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py index d9c9d45a3ea9..9b922afbba66 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py @@ -56,12 +56,13 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): inner_mcp_tool = MCPToolboxTool( @@ -88,24 +89,19 @@ require_approval="never", ) - with ( - create_version_with_endpoint( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Always use the toolbox search tool to answer questions and perform tasks. " - "Use `tool_search` to discover a relevant tool, then `call_tool` " - "with the tool name returned by the search." - ), - tools=[toolbox_mcp_tool], + with create_version_with_endpoint( + project_client=project_client, + agent_name="MyAgent", + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Always use the toolbox search tool to answer questions and perform tasks. " + "Use `tool_search` to discover a relevant tool, then `call_tool` " + "with the tool name returned by the search." ), + tools=[toolbox_mcp_tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version}).") + ) as agent: response = openai_client.responses.create( input="What is my username in Github profile?", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py index 71af3ee3bd1a..34dc5af711de 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview_async.py @@ -57,13 +57,14 @@ INNER_MCP_LABEL = "github" INNER_MCP_URL = "https://api.githubcopilot.com/mcp" TOOLBOX_MCP_LABEL = "search-tool" -AGENT_NAME = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") +agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "MyAgent") async def main() -> None: async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): inner_mcp_tool = MCPToolboxTool( @@ -90,24 +91,20 @@ async def main() -> None: require_approval="never", ) - async with ( - create_version_with_endpoint_async( - project_client=project_client, - agent_name=AGENT_NAME, - definition=PromptAgentDefinition( - model=os.environ["FOUNDRY_MODEL_NAME"], - instructions=( - "Always use the toolbox search tool to answer questions and perform tasks. " - "Use `tool_search` to discover a relevant tool, then `call_tool` " - "with the tool name returned by the search." - ), - tools=[toolbox_mcp_tool], + async with create_version_with_endpoint_async( + project_client=project_client, + agent_name=agent_name, + definition=PromptAgentDefinition( + model=os.environ["FOUNDRY_MODEL_NAME"], + instructions=( + "Always use the toolbox search tool to answer questions and perform tasks. " + "Use `tool_search` to discover a relevant tool, then `call_tool` " + "with the tool name returned by the search." ), + tools=[toolbox_mcp_tool], ), - project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, - ): - agent = await project_client.agents.get(agent_name=AGENT_NAME) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version}).") + ) as agent: + print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version}).") response = await openai_client.responses.create( input="What is my username in Github profile?", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py index a6159e1c1dcb..bc55b40b1291 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py @@ -6,18 +6,22 @@ from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path import sys +from typing import TYPE_CHECKING -_AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" -_PKG_ROOT = Path(__file__).resolve().parents[3] -if str(_PKG_ROOT) not in sys.path: - sys.path.insert(0, str(_PKG_ROOT)) +if TYPE_CHECKING: + from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async +else: + _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" + _PKG_ROOT = Path(__file__).resolve().parents[3] + if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) -_SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) -if _SPEC is None or _SPEC.loader is None: - raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") + _SPEC = spec_from_file_location("samples_agents_util", _AGENTS_UTIL_PATH) + if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load agent samples util from {_AGENTS_UTIL_PATH}") -_MODULE = module_from_spec(_SPEC) -_SPEC.loader.exec_module(_MODULE) + _MODULE = module_from_spec(_SPEC) + _SPEC.loader.exec_module(_MODULE) -create_version_with_endpoint = _MODULE.create_version_with_endpoint -create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async + create_version_with_endpoint = _MODULE.create_version_with_endpoint + create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async diff --git a/sdk/ai/azure-ai-projects/samples/agents/util.py b/sdk/ai/azure-ai-projects/samples/agents/util.py index 34fefb49c2cb..6dd3e9c176d7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/util.py @@ -6,18 +6,22 @@ from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path import sys +from typing import TYPE_CHECKING -_SAMPLES_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" -_PKG_ROOT = Path(__file__).resolve().parents[2] -if str(_PKG_ROOT) not in sys.path: - sys.path.insert(0, str(_PKG_ROOT)) +if TYPE_CHECKING: + from samples.util import create_version_with_endpoint, create_version_with_endpoint_async +else: + _SAMPLES_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" + _PKG_ROOT = Path(__file__).resolve().parents[2] + if str(_PKG_ROOT) not in sys.path: + sys.path.insert(0, str(_PKG_ROOT)) -_SPEC = spec_from_file_location("samples_shared_util", _SAMPLES_UTIL_PATH) -if _SPEC is None or _SPEC.loader is None: - raise ImportError(f"Unable to load shared samples util from {_SAMPLES_UTIL_PATH}") + _SPEC = spec_from_file_location("samples_shared_util", _SAMPLES_UTIL_PATH) + if _SPEC is None or _SPEC.loader is None: + raise ImportError(f"Unable to load shared samples util from {_SAMPLES_UTIL_PATH}") -_MODULE = module_from_spec(_SPEC) -_SPEC.loader.exec_module(_MODULE) + _MODULE = module_from_spec(_SPEC) + _SPEC.loader.exec_module(_MODULE) -create_version_with_endpoint = _MODULE.create_version_with_endpoint -create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async + create_version_with_endpoint = _MODULE.create_version_with_endpoint + create_version_with_endpoint_async = _MODULE.create_version_with_endpoint_async From 580e7c055eb667e3f044d3a19c8ea4c7f25a9260 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 16:03:19 -0700 Subject: [PATCH 16/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index fcec788463a1..d533c68f921d 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_44c5336f0c" + "Tag": "python/ai/azure-ai-projects_15ebf60ffe" } From 5e19732cdbfaec2592224c199e21e4160824a34b Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 17:02:45 -0700 Subject: [PATCH 17/24] recording --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index d533c68f921d..6dec45edf7b4 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_15ebf60ffe" + "Tag": "python/ai/azure-ai-projects_f3cdb78ac6" } From 330825a9f2853d8d12968c92498914b44fe36f8c Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 17:05:37 -0700 Subject: [PATCH 18/24] fix mypy --- sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py | 2 +- sdk/ai/azure-ai-projects/samples/agents/tools/util.py | 2 +- sdk/ai/azure-ai-projects/samples/agents/util.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py index bc55b40b1291..00a2b080c67c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async + from agents.util import create_version_with_endpoint, create_version_with_endpoint_async else: _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[3] diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py index bc55b40b1291..00a2b080c67c 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async + from agents.util import create_version_with_endpoint, create_version_with_endpoint_async else: _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[3] diff --git a/sdk/ai/azure-ai-projects/samples/agents/util.py b/sdk/ai/azure-ai-projects/samples/agents/util.py index 6dd3e9c176d7..f546041f49e7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from samples.util import create_version_with_endpoint, create_version_with_endpoint_async + from util import create_version_with_endpoint, create_version_with_endpoint_async else: _SAMPLES_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[2] From be147e559cc861ab249e9bef4e9e58a2b5119686 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 18:43:31 -0700 Subject: [PATCH 19/24] fix sample --- .../agents/tools/sample_toolboxes_with_search_preview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py index 9b922afbba66..44b4a41296d2 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_toolboxes_with_search_preview.py @@ -91,7 +91,7 @@ with create_version_with_endpoint( project_client=project_client, - agent_name="MyAgent", + agent_name=agent_name, definition=PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions=( From 33d21d0ad3c91fb87d3725aefec33d0c57628cd7 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 19:36:14 -0700 Subject: [PATCH 20/24] mypy --- sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py | 2 +- sdk/ai/azure-ai-projects/samples/agents/tools/util.py | 2 +- sdk/ai/azure-ai-projects/samples/agents/util.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py index 00a2b080c67c..bc55b40b1291 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from agents.util import create_version_with_endpoint, create_version_with_endpoint_async + from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async else: _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[3] diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py index 00a2b080c67c..bc55b40b1291 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from agents.util import create_version_with_endpoint, create_version_with_endpoint_async + from samples.agents.util import create_version_with_endpoint, create_version_with_endpoint_async else: _AGENTS_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[3] diff --git a/sdk/ai/azure-ai-projects/samples/agents/util.py b/sdk/ai/azure-ai-projects/samples/agents/util.py index f546041f49e7..6dd3e9c176d7 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/util.py +++ b/sdk/ai/azure-ai-projects/samples/agents/util.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from util import create_version_with_endpoint, create_version_with_endpoint_async + from samples.util import create_version_with_endpoint, create_version_with_endpoint_async else: _SAMPLES_UTIL_PATH = Path(__file__).resolve().parents[1] / "util.py" _PKG_ROOT = Path(__file__).resolve().parents[2] From 29a45d17f6076128115d01b624856559e1c972c7 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 19:48:45 -0700 Subject: [PATCH 21/24] fix mypy --- sdk/ai/azure-ai-projects/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/pyproject.toml b/sdk/ai/azure-ai-projects/pyproject.toml index 3cc1de11d7af..fe2948c218ac 100644 --- a/sdk/ai/azure-ai-projects/pyproject.toml +++ b/sdk/ai/azure-ai-projects/pyproject.toml @@ -68,7 +68,7 @@ pytyped = ["py.typed"] verifytypes = false [tool.mypy] -exclude = '.*samples[\\/]hosted_agents[\\/]assets[\\/].*main\.py$' +exclude = '(^|.*[\\/])samples[\\/]hosted_agents[\\/]assets[\\/].*main\.py$|(^|.*[\\/])samples[\\/]agents[\\/]util\.py$|(^|.*[\\/])samples[\\/]agents[\\/]tools[\\/]util\.py$|(^|.*[\\/])samples[\\/]agents[\\/]telemetry[\\/]util\.py$' [tool.azure-sdk-conda] in_bundle = false From 0b639d31b5b6ca982dd8919c293fe4221ba0d2c3 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 20:59:43 -0700 Subject: [PATCH 22/24] remove get agent call --- sdk/ai/azure-ai-projects/assets.json | 2 +- .../azure-ai-projects/samples/agents/sample_agent_basic.py | 5 +++-- .../samples/agents/sample_agent_stream_events.py | 3 --- .../samples/agents/sample_agent_structured_output.py | 2 -- .../sample_agent_basic_with_azure_monitor_tracing.py | 3 --- .../telemetry/sample_agent_basic_with_console_tracing.py | 3 --- .../samples/agents/tools/sample_agent_ai_search.py | 3 --- .../samples/agents/tools/sample_agent_azure_function.py | 5 ----- .../samples/agents/tools/sample_agent_bing_custom_search.py | 5 ----- .../samples/agents/tools/sample_agent_bing_grounding.py | 5 ----- .../samples/agents/tools/sample_agent_browser_automation.py | 5 ----- .../samples/agents/tools/sample_agent_code_interpreter.py | 3 --- .../agents/tools/sample_agent_code_interpreter_async.py | 5 ----- .../samples/agents/tools/sample_agent_computer_use.py | 3 --- .../samples/agents/tools/sample_agent_fabric.py | 3 --- .../samples/agents/tools/sample_agent_fabric_iq.py | 3 --- .../samples/agents/tools/sample_agent_function_tool.py | 3 --- .../samples/agents/tools/sample_agent_image_generation.py | 3 --- .../samples/agents/tools/sample_agent_mcp.py | 3 --- .../agents/tools/sample_agent_mcp_with_project_connection.py | 3 --- .../samples/agents/tools/sample_agent_openapi.py | 3 --- .../tools/sample_agent_openapi_with_project_connection.py | 3 --- .../samples/agents/tools/sample_agent_sharepoint.py | 3 --- .../samples/agents/tools/sample_agent_to_agent.py | 3 --- .../samples/agents/tools/sample_agent_web_search.py | 4 ---- .../samples/agents/tools/sample_agent_web_search_preview.py | 3 --- .../tools/sample_agent_web_search_with_custom_search.py | 3 --- .../samples/agents/tools/sample_agent_work_iq.py | 3 --- 28 files changed, 4 insertions(+), 91 deletions(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 6dec45edf7b4..4b4fb6e23831 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_f3cdb78ac6" + "Tag": "python/ai/azure-ai-projects_d6f536b85d" } diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py index 4534b5d7f27e..467b3f89aa56 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic.py @@ -61,6 +61,9 @@ instructions="You are a helpful assistant that answers general questions", ), ) + print( + f"Agent created (id: {created_version.id}, name: {created_version.name}, version: {created_version.version})" + ) original_agent_endpoint = project_client.agents.get(agent_name=agent_name).agent_endpoint endpoint_config = AgentEndpointConfig( @@ -75,8 +78,6 @@ print(f"Agent endpoint configured for version {created_version.version}") with project_client.get_openai_client(agent_name=agent_name) as openai_client: - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create( items=[{"type": "message", "role": "user", "content": "What is the size of France in square miles?"}], diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py index 30fe2d135aa1..f62263413ad6 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_stream_events.py @@ -53,9 +53,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - conversation = openai_client.conversations.create( items=[{"type": "message", "role": "user", "content": "Tell me about the capital city of France"}], ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py index 5eca564668b4..ed7f5cb01917 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_structured_output.py @@ -75,8 +75,6 @@ class CalendarEvent(BaseModel): ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") conversation = openai_client.conversations.create( items=[ diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py index 1623b63f0c42..251bd4a8fe0e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_azure_monitor_tracing.py @@ -68,9 +68,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - conversation = openai_client.conversations.create() print(f"Created conversation with initial user message (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py index 29b08bc6bfd1..f63a41d07352 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py +++ b/sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py @@ -99,9 +99,6 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - conversation = openai_client.conversations.create() request = "Hello, tell me a joke." diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py index 6252dc7b3793..6eb6cbc49694 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_ai_search.py @@ -75,9 +75,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Get user input from environment variable or prompt user_input = os.environ.get("AI_SEARCH_USER_INPUT") if not user_input: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py index 4c47280ff889..5a7729dbf78f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_azure_function.py @@ -89,9 +89,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = "What is the weather in Seattle?" response = openai_client.responses.create( @@ -100,5 +97,3 @@ ) print(f"Response output: {response.output_text}") - - print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index d8ed36141e37..1ba8ddba0f8f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py @@ -82,9 +82,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("BING_CUSTOM_USER_INPUT") or input("Enter your question: \n") # Send initial request that will trigger the Bing Custom Search tool @@ -115,5 +112,3 @@ elif event.type == "response.completed": print("\nFollow-up completed!") print(f"Full response: {event.response.output_text}") - - print("Cleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py index ade6847db10a..8fbf96112bfc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_grounding.py @@ -84,9 +84,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - stream_response = openai_client.responses.create( stream=True, tool_choice="required", @@ -111,5 +108,3 @@ elif event.type == "response.completed": print("\nFollow-up completed!") print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py index 4fcd57fbe084..57645de43e4e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_browser_automation.py @@ -69,9 +69,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - stream_response = openai_client.responses.create( stream=True, tool_choice="required", @@ -105,5 +102,3 @@ elif event.type == "response.completed": print("\nFollow-up completed!") print(f"Full response: {event.response.output_text}") - - print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py index b8c3c893bb27..bc25886352e3 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter.py @@ -51,9 +51,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py index deb49bf3b063..0c54d31371fd 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_code_interpreter_async.py @@ -54,9 +54,6 @@ async def main() -> None: ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = await project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction conversation = await openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") @@ -77,8 +74,6 @@ async def main() -> None: # Print final assistant text output. print(f"Agent response: {response.output_text}") - print("\nCleaning up...") - if __name__ == "__main__": asyncio.run(main()) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py index 00975014798a..2c6cab4d70ab 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py @@ -82,9 +82,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Initial request with screenshot - start with Bing search page print("Starting computer automation session (initial screenshot: cua_browser_search.png)...") response = openai_client.responses.create( diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py index 9ba09bfe62d0..620609ccc664 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric.py @@ -64,9 +64,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_USER_INPUT") or input("Enter your question: \n") stream_response = openai_client.responses.create( diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py index 5b09dd6eede5..98eb521f9968 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_fabric_iq.py @@ -57,9 +57,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("FABRIC_IQ_USER_INPUT") or input("Enter your question:\n") response = openai_client.responses.create( diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py index df5ade86b1cb..09a096784dfc 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_function_tool.py @@ -78,9 +78,6 @@ def get_horoscope(sign: str) -> str: ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Prompt the model with tools defined response = openai_client.responses.create( input="What is my horoscope? I am an Aquarius.", diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py index e96509dc8e51..82c3e75d6839 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_image_generation.py @@ -81,9 +81,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = openai_client.responses.create( input="Generate an image of Microsoft logo.", extra_headers={ diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py index 7c9c0422376b..03ba643cf794 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp.py @@ -57,9 +57,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation thread to maintain context across multiple interactions conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py index cd1778d579d9..69816267de85 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_mcp_with_project_connection.py @@ -61,9 +61,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation thread to maintain context across multiple interactions conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py index 88043057aab2..068205c2c0e9 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi.py @@ -69,9 +69,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = openai_client.responses.create( input="Use the OpenAPI tool to print out, what is the weather in Seattle today.", ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py index 948e3a399365..03e3cb47836e 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_openapi_with_project_connection.py @@ -77,9 +77,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - response = openai_client.responses.create( input="Recommend me 5 top hotels in the United States", ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py index 8e5e69979adb..77027e023598 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_sharepoint.py @@ -67,9 +67,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Get user input from environment variable or prompt user_input = os.environ.get("SHAREPOINT_USER_INPUT") if not user_input: diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py index 533c72188e9c..b31d434ff910 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_to_agent.py @@ -67,9 +67,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("A2A_USER_INPUT") or input( "Enter your question (e.g., 'What can the secondary agent do?'): \n" ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py index c72f74ca2b81..c3075924be2b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search.py @@ -67,10 +67,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - # Create Agent with web search tool - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py index 8315c168ae2c..b7b67ff7cf9b 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_preview.py @@ -63,9 +63,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py index 3afa6088b344..ee49edc5d545 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_web_search_with_custom_search.py @@ -77,9 +77,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - # Create a conversation for the agent interaction conversation = openai_client.conversations.create() print(f"Created conversation (id: {conversation.id})") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py index b3e4aa676591..c5b48b80932f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_work_iq.py @@ -56,9 +56,6 @@ ), project_client.get_openai_client(agent_name=agent_name) as openai_client, ): - agent = project_client.agents.get(agent_name=agent_name) - print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.versions.latest.version})") - user_input = os.environ.get("WORK_IQ_USER_INPUT") or input("Enter your question:\n") response = openai_client.responses.create( From 20c0e036a57793dca4ce4f2ecfc0ea6e6bf4b44e Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 21:27:31 -0700 Subject: [PATCH 23/24] update asset tag in assets.json --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 4b4fb6e23831..5e674b8c6573 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_d6f536b85d" + "Tag": "python/ai/azure-ai-projects_f0b623902e" } From d5a84769c626e31686d1547e149261968aaf3c40 Mon Sep 17 00:00:00 2001 From: Howie Leung Date: Fri, 10 Jul 2026 22:05:14 -0700 Subject: [PATCH 24/24] update asset tag in assets.json --- sdk/ai/azure-ai-projects/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ai/azure-ai-projects/assets.json b/sdk/ai/azure-ai-projects/assets.json index 5e674b8c6573..19f1f7e5f9d3 100644 --- a/sdk/ai/azure-ai-projects/assets.json +++ b/sdk/ai/azure-ai-projects/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/ai/azure-ai-projects", - "Tag": "python/ai/azure-ai-projects_f0b623902e" + "Tag": "python/ai/azure-ai-projects_875c4f833f" }