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..7952b4cadddc 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 @@ -39,10 +39,10 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, ): - with project_client.get_openai_client() as openai_client: + with project_client.get_openai_client(agent_name="MyAgent") as openai_client: agent = project_client.agents.create_version( agent_name="MyAgent", definition=PromptAgentDefinition( @@ -59,7 +59,6 @@ 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}") @@ -71,7 +70,6 @@ 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_basic_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_agent_basic_async.py index 3936a1aec2e6..bca479a6bf9d 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 @@ -42,8 +42,8 @@ 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): agent = await project_client.agents.create_version( @@ -62,7 +62,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,7 +73,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}") 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..03b47e535578 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 @@ -41,14 +41,14 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) 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, ), - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): # Retrieve latest version for the prerequisite agent. @@ -68,6 +68,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..b8794b9ec96a 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 @@ -44,14 +44,14 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) 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, ), - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): # Retrieve latest version for the prerequisite agent. @@ -71,7 +71,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..d0cb40fc6d05 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 @@ -39,8 +39,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): agent = project_client.agents.create_version( @@ -59,7 +59,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: 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..1af90e15e0a5 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 @@ -55,8 +55,8 @@ class CalendarEvent(BaseModel): with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): agent = project_client.agents.create_version( @@ -87,7 +87,6 @@ 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}") 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..d711c44fa67f 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 @@ -57,8 +57,8 @@ class CalendarEvent(BaseModel): 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): agent = await project_client.agents.create_version( agent_name="MyAgent", @@ -88,7 +88,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}") diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent.py b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent.py index f2ce47c55b7c..52ffd484721d 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent.py @@ -40,7 +40,7 @@ with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name="student-teacher-workflow") as openai_client, ): # Create Teacher Agent teacher_agent = project_client.agents.create_version( @@ -150,7 +150,6 @@ stream = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}}, input="1 + 1 = ?", stream=True, ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_async.py b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_async.py index 8673b7ac284d..e1b894eadb9f 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_async.py @@ -44,7 +44,7 @@ async def main(): async with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name="student-teacher-workflow-async") as openai_client, ): teacher_agent = await project_client.agents.create_version( @@ -152,7 +152,6 @@ async def main(): stream = await openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}}, input="1 + 1 = ?", stream=True, ) diff --git a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_with_mcp_approval.py b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_with_mcp_approval.py index 2ef0109250c5..214a36fb6b14 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_with_mcp_approval.py +++ b/sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_with_mcp_approval.py @@ -46,7 +46,7 @@ with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name="student-teacher-workflow") as openai_client, ): # Define MCP tool for accessing external resources (optional - can be removed for simpler demo) # Note: MCP tools in workflows may require special handling depending on the use case @@ -168,7 +168,6 @@ stream = openai_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}}, input="Please summarize the Azure REST API specifications Readme", stream=True, ) @@ -233,7 +232,6 @@ response = openai_client.responses.create( input=input_list, previous_response_id=response.id, - extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}}, ) print(f"Agent response after approval: {response.output_text}") 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..d3e0f0d3c2fe 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 @@ -44,7 +44,9 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client, + AIProjectClient( + endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential, allow_preview=True + ) as project_client, ): # Enable Azure Monitor tracing application_insights_connection_string = project_client.telemetry.get_application_insights_connection_string() @@ -54,7 +56,7 @@ scenario = os.path.basename(__file__) with tracer.start_as_current_span(scenario): - with project_client.get_openai_client() as openai_client: + with project_client.get_openai_client(agent_name="MyAgent") as openai_client: agent_definition = PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], instructions="You are a helpful assistant that answers general questions", @@ -68,7 +70,6 @@ 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}") 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..ce27094e58b9 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,8 +85,10 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o 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, + AIProjectClient( + endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential, allow_preview=True + ) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): agent_definition = PromptAgentDefinition( model=os.environ["FOUNDRY_MODEL_NAME"], @@ -101,7 +103,6 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o 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 +110,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}") 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..16ff1992afee 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 @@ -45,8 +45,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = AzureAISearchTool( @@ -82,7 +82,6 @@ stream=True, tool_choice="required", input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..0881c2ac864e 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 @@ -48,8 +48,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = AzureFunctionTool( @@ -92,7 +92,6 @@ response = openai_client.responses.create( tool_choice="required", input=user_input, - 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/tools/sample_agent_bing_custom_search.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_bing_custom_search.py index 0f52fbfa8e47..2ea2e81559e1 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 @@ -54,8 +54,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = BingCustomSearchPreviewTool( @@ -86,7 +86,6 @@ stream_response = openai_client.responses.create( stream=True, input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..0ad05b780bd1 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 @@ -59,8 +59,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = BingGroundingTool( @@ -86,7 +86,6 @@ 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"}}, ) for event in stream_response: 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..14789e613329 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 @@ -43,8 +43,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = BrowserAutomationPreviewTool( @@ -77,7 +77,6 @@ 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: 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..cbecfa7b4a06 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 @@ -35,8 +35,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = CodeInterpreterTool() @@ -61,7 +61,6 @@ 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})") 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..59ae14b236f6 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 @@ -38,8 +38,8 @@ 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): # Create agent with code interpreter tool @@ -62,7 +62,6 @@ async def main() -> None: 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})") 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..281723c953d6 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 @@ -46,7 +46,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): @@ -80,19 +80,21 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() + conversation = agent_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( + response = agent_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)? Also, using the code interpreter, read numbers.csv and return the sum of x." ), extra_body={ - "agent_reference": {"name": agent.name, "type": "agent_reference"}, "structured_inputs": {"analysis_file_id": uploaded.id}, }, tool_choice="required", 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..855bb8821d7f 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 @@ -36,7 +36,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): @@ -65,15 +65,17 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() + conversation = agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") # Send request to create a chart and generate a file - response = openai_client.responses.create( + response = agent_client.responses.create( conversation=conversation.id, input="Could you please create bar chart in TRANSPORTATION sector for the operating profit from the uploaded csv file and provide file to me?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response completed (id: {response.id})") 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..66f9ef6d4e43 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 @@ -41,7 +41,7 @@ async def main() -> None: async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): try: @@ -67,15 +67,17 @@ async def main() -> None: ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = await openai_client.conversations.create() + conversation = await agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") # Send request to create a chart and generate a file - response = await openai_client.responses.create( + response = await agent_client.responses.create( conversation=conversation.id, input="Could you please create bar chart in TRANSPORTATION sector for the operating profit from the uploaded csv file and provide file to me?", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response completed (id: {response.id})") 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..8d18bbc65e81 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 @@ -49,8 +49,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): # Initialize state machine current_state = SearchState.INITIAL @@ -99,7 +99,6 @@ ], } ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, truncation="auto", ) @@ -149,7 +148,6 @@ }, } ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, truncation="auto", ) 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..9cbb3f34ee69 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 @@ -52,8 +52,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): """Main async function to demonstrate Computer Use Agent functionality.""" @@ -104,7 +104,6 @@ async def main(): ], } ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, truncation="auto", ) @@ -156,7 +155,6 @@ async def main(): }, } ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, truncation="auto", ) 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..7f27d9788d02 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 @@ -43,8 +43,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = MicrosoftFabricPreviewTool( fabric_dataagent_preview=FabricDataAgentToolParameters( @@ -70,7 +70,6 @@ tool_choice="required", stream=True, input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..6664ed347e9f 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 @@ -37,8 +37,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool_payload = FabricIQPreviewTool( project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], @@ -59,7 +59,6 @@ response = openai_client.responses.create( input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") 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..c9215dbae3a2 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 @@ -40,8 +40,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool_payload = FabricIQPreviewTool( project_connection_id=os.environ["FABRIC_IQ_PROJECT_CONNECTION_ID"], @@ -62,7 +62,6 @@ async def main(): response = await openai_client.responses.create( input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") 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..718ae40ac7d2 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 @@ -36,7 +36,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): # Create vector store for file search @@ -65,15 +65,17 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() + conversation = agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") # Send a query to search through the uploaded file - response = openai_client.responses.create( + response = agent_client.responses.create( conversation=conversation.id, input="Tell me about Contoso products", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") print("\nCleaning up...") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream.py index 49501c4a05b7..27c8326b1d6a 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream.py @@ -36,7 +36,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): # Load the file to be indexed for search @@ -69,8 +69,11 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() + conversation = agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") print("\n" + "=" * 60) @@ -78,7 +81,7 @@ print("=" * 60) # Create a streaming response with file search capabilities - stream_response = openai_client.responses.create( + stream_response = agent_client.responses.create( stream=True, conversation=conversation.id, input=[ @@ -87,7 +90,6 @@ "content": "Tell me about Contoso products and their features in detail. Please search through the available documentation.", }, ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print("Processing streaming file search results...\n") @@ -109,13 +111,12 @@ print("=" * 60) # Demonstrate a follow-up query in the same conversation - stream_response = openai_client.responses.create( + stream_response = agent_client.responses.create( stream=True, conversation=conversation.id, input=[ {"role": "user", "content": "Tell me about Smart Eyewear and its features."}, ], - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print("Processing follow-up streaming response...\n") diff --git a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream_async.py b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream_async.py index 889d8a6b24b8..a80dee496826 100644 --- a/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream_async.py +++ b/sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_file_search_in_stream_async.py @@ -39,7 +39,7 @@ async def main() -> None: # pylint: disable=too-many-statements async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): # Load the file to be indexed for search @@ -70,8 +70,11 @@ async def main() -> None: # pylint: disable=too-many-statements ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = await openai_client.conversations.create() + conversation = await agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") print("\n" + "=" * 60) @@ -79,7 +82,7 @@ async def main() -> None: # pylint: disable=too-many-statements print("=" * 60) # Create a streaming response with file search capabilities - stream_response = await openai_client.responses.create( + stream_response = await agent_client.responses.create( stream=True, conversation=conversation.id, input=[ @@ -89,7 +92,6 @@ async def main() -> None: # pylint: disable=too-many-statements }, ], tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print("Processing streaming file search results...\n") @@ -111,7 +113,7 @@ async def main() -> None: # pylint: disable=too-many-statements print("=" * 60) # Demonstrate a follow-up query in the same conversation - stream_response = await openai_client.responses.create( + stream_response = await agent_client.responses.create( stream=True, conversation=conversation.id, input=[ @@ -121,7 +123,6 @@ async def main() -> None: # pylint: disable=too-many-statements }, ], tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print("Processing follow-up streaming response...\n") 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..b221aa017e2a 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 @@ -42,7 +42,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): # Create vector store for file search @@ -90,16 +90,18 @@ print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Create a conversation for the agent interaction - conversation = openai_client.conversations.create() + conversation = agent_client.conversations.create() print(f"Created conversation (id: {conversation.id})") # Send a query to search through the uploaded file - response = openai_client.responses.create( + response = agent_client.responses.create( conversation=conversation.id, input="Tell me about Contoso products", extra_body={ - "agent_reference": {"name": agent.name, "type": "agent_reference"}, "structured_inputs": {"vector_store_id": vector_store.id, "vector_store_file_id": file.id}, }, ) 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..c84873302e91 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 @@ -44,8 +44,8 @@ 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = FunctionTool( @@ -77,7 +77,6 @@ def get_horoscope(sign: str) -> str: # 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}") @@ -104,7 +103,6 @@ def get_horoscope(sign: str) -> str: response = openai_client.responses.create( input=input_list, previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") 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..53671e17bba9 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 @@ -47,8 +47,8 @@ async def get_horoscope(sign: str) -> str: async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): # Define a function tool for the model to use func_tool = FunctionTool( @@ -80,7 +80,6 @@ async def main(): # 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}") @@ -107,7 +106,6 @@ async def main(): 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"Agent response: {response.output_text}") 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..13882a932c88 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 @@ -57,8 +57,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] @@ -84,7 +84,6 @@ 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}") 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..d20dc1355506 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 @@ -59,8 +59,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): image_generation_model = os.environ["IMAGE_GENERATION_MODEL_DEPLOYMENT_NAME"] @@ -81,7 +81,6 @@ async def main(): 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}") 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..0fd5a209f781 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 @@ -36,8 +36,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -63,7 +63,6 @@ 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 @@ -89,7 +88,6 @@ response = openai_client.responses.create( input=input_list, previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) 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 55c32cd0602c..c01a73dfbcb4 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 @@ -39,8 +39,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -70,7 +70,6 @@ async def main(): 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 @@ -96,7 +95,6 @@ async def main(): 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"Agent response: {response.output_text}") 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..d84d1e7534f1 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 @@ -38,8 +38,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent7") as openai_client, ): tool = MCPTool( @@ -68,7 +68,6 @@ 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 @@ -94,7 +93,6 @@ response = 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}") 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..208afbf31d17 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 @@ -41,8 +41,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): mcp_tool = MCPTool( server_label="api-specs", @@ -73,7 +73,6 @@ async def main(): 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 @@ -98,7 +97,6 @@ async def main(): 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}") 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..f5627dd0be45 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 @@ -51,8 +51,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): # Delete memory store, if it already exists @@ -105,7 +105,6 @@ 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}") @@ -121,7 +120,6 @@ 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}") 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..bd2e78e45394 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 @@ -54,8 +54,8 @@ 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): # Delete memory store, if it already exists @@ -108,7 +108,6 @@ async def main() -> None: 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}") @@ -124,7 +123,6 @@ async def main() -> None: 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}") 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..52f4e034ccf9 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 @@ -42,8 +42,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): weather_asset_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/weather_openapi.json")) @@ -72,7 +72,6 @@ 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}") 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..842b9fd59cd6 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 @@ -46,8 +46,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tripadvisor_asset_file_path = os.path.abspath( @@ -82,7 +82,6 @@ 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')}") 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..58c0747e33fd 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 @@ -43,8 +43,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = SharepointPreviewTool( sharepoint_grounding_preview=SharepointGroundingToolParameters( @@ -74,7 +74,6 @@ stream_response = openai_client.responses.create( stream=True, input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..521d5cfc91f5 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 @@ -45,8 +45,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = A2APreviewTool( @@ -74,7 +74,6 @@ stream=True, tool_choice="required", input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..cab68a03bc3a 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 @@ -50,8 +50,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = WebSearchTool(user_location=WebSearchApproximateLocation(country="GB", city="London", region="London")) # Create Agent with web search tool @@ -76,7 +76,6 @@ stream=True, input=user_input, tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..d6539cd818a9 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 @@ -46,8 +46,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent105") as openai_client, ): tool = WebSearchPreviewTool(user_location=ApproximateLocation(country="GB", city="London", region="London")) # Create Agent with web search tool @@ -72,7 +72,6 @@ stream=True, input=user_input, tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..d4206c73cfde 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 @@ -55,8 +55,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool = WebSearchTool( custom_search_configuration=WebSearchConfiguration( @@ -88,7 +88,6 @@ stream=True, input=user_input, tool_choice="required", - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) for event in stream_response: 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..274973b5876b 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 @@ -37,8 +37,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool_payload = WorkIQPreviewTool( project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], @@ -58,7 +58,6 @@ response = openai_client.responses.create( input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") 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..6945b1f715f0 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 @@ -40,8 +40,8 @@ async def main(): async with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): tool_payload = WorkIQPreviewTool( project_connection_id=os.environ["WORK_IQ_PROJECT_CONNECTION_ID"], @@ -61,7 +61,6 @@ async def main(): response = await openai_client.responses.create( input=user_input, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Agent response: {response.output_text}") 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 63bdc57e0ee8..85fd2e89f32d 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 @@ -61,8 +61,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): inner_mcp_tool = MCPTool( @@ -106,7 +106,6 @@ 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: 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 bfd43071c2f3..5b146b2f15de 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 @@ -62,8 +62,8 @@ 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, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name="MyAgent") as openai_client, ): inner_mcp_tool = MCPTool( @@ -107,7 +107,6 @@ async def main() -> None: 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: diff --git a/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_evaluation.py b/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_evaluation.py index 1b79603e559d..0ca19996bc6d 100644 --- a/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_evaluation.py +++ b/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_evaluation.py @@ -98,8 +98,8 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, - project_client.get_openai_client() as openai_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, + project_client.get_openai_client(agent_name=agent_name) as openai_client, ): created_agent = None @@ -125,7 +125,6 @@ openai_client.responses.create( conversation=conversation.id, input=prompt, - extra_body={"agent_reference": {"name": created_agent.name, "type": "agent_reference"}}, ) print(f"Wait {INITIAL_INGEST_WAIT_SECONDS}s for Application Insights to ingest the spans.", flush=True) diff --git a/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_finetuning.py b/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_finetuning.py index beb48c225d94..c1f45a6f85b7 100644 --- a/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_finetuning.py +++ b/sdk/ai/azure-ai-projects/samples/datasets/sample_dataset_generation_job_traces_for_finetuning.py @@ -100,8 +100,9 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=agent_name) as agent_client, ): created_agent = None @@ -121,13 +122,12 @@ seed_start = datetime.now(tz=timezone.utc) print(f"Seed {len(SEED_PROMPTS)} conversation(s) against the agent.") for prompt in SEED_PROMPTS: - conversation = openai_client.conversations.create() + conversation = agent_client.conversations.create() created_conversation_ids.append(conversation.id) print(f" - conversation id: {conversation.id} (prompt: {prompt!r})") - openai_client.responses.create( + agent_client.responses.create( conversation=conversation.id, input=prompt, - extra_body={"agent_reference": {"name": created_agent.name, "type": "agent_reference"}}, ) print(f"Wait {INITIAL_INGEST_WAIT_SECONDS}s for Application Insights to ingest the spans.", flush=True) @@ -225,7 +225,7 @@ if created_conversation_ids: for cid in created_conversation_ids: try: - openai_client.conversations.delete(conversation_id=cid) + agent_client.conversations.delete(conversation_id=cid) print(f"Deleted seeded conversation `{cid}`.") except Exception as exc: # pylint: disable=broad-exception-caught print(f" (warning) could not delete conversation `{cid}`: {exc}") 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..021e53ec806c 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 @@ -50,7 +50,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): @@ -63,14 +63,16 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") - conversation = openai_client.conversations.create( + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + + conversation = agent_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( + response = agent_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text} (id: {response.id})") 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..a059ace77e23 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 @@ -81,7 +81,7 @@ def get_horoscope(sign: str) -> str: with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): agent = project_client.agents.create_version( @@ -94,10 +94,12 @@ def get_horoscope(sign: str) -> str: ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Prompt the model with tools defined - response = openai_client.responses.create( + response = agent_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}") @@ -121,10 +123,9 @@ def get_horoscope(sign: str) -> str: print("Final input:") print(input_list) - response = openai_client.responses.create( + response = agent_client.responses.create( input=input_list, previous_response_id=response.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text} (id: {response.id})") 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..e6f58a04561c 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 @@ -56,7 +56,7 @@ with ( DefaultAzureCredential() as credential, - AIProjectClient(endpoint=endpoint, credential=credential) as project_client, + AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, project_client.get_openai_client() as openai_client, ): @@ -71,6 +71,9 @@ ) print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})") + # Use an agent-scoped client for Responses and Conversations calls + agent_client = project_client.get_openai_client(agent_name=agent.name) + # Setup agent continuous evaluation data_source_config = AzureAIDataSourceConfig(type="azure_ai_source", scenario="responses") @@ -103,14 +106,13 @@ # Run agent - conversation = openai_client.conversations.create( + conversation = agent_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( + response = agent_client.responses.create( conversation=conversation.id, - extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}}, ) print(f"Response output: {response.output_text}") @@ -118,15 +120,14 @@ MAX_QUESTIONS = 10 for i in range(0, MAX_QUESTIONS): - openai_client.conversations.items.create( + agent_client.conversations.items.create( conversation_id=conversation.id, items=[{"type": "message", "role": "user", "content": f"Question {i}: What is the capital city?"}], ) print("Added a user message to the conversation") - response = openai_client.responses.create( + response = agent_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/hosted_agents/sample_skill_in_toolbox.py b/sdk/ai/azure-ai-projects/samples/hosted_agents/sample_skill_in_toolbox.py index af07a47bae37..437c4f0293b4 100644 --- a/sdk/ai/azure-ai-projects/samples/hosted_agents/sample_skill_in_toolbox.py +++ b/sdk/ai/azure-ai-projects/samples/hosted_agents/sample_skill_in_toolbox.py @@ -64,7 +64,7 @@ with ( DefaultAzureCredential() as credential, AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client, - project_client.get_openai_client() as openai_client, + project_client.get_openai_client(agent_name=AGENT_NAME) as openai_client, ): try: @@ -132,7 +132,6 @@ 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: