From db28c0f8cb861196851114991ee4d988a51f2a13 Mon Sep 17 00:00:00 2001 From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Date: Thu, 4 Dec 2025 16:47:02 -0800 Subject: [PATCH] Renamed async_credential to credential --- .../agent_framework_azure_ai/_chat_client.py | 16 +- .../agent_framework_azure_ai/_client.py | 16 +- .../tests/test_azure_ai_agent_client.py | 42 +-- .../azure-ai/tests/test_azure_ai_client.py | 10 +- .../lab/gaia/samples/azure_ai_agent.py | 2 +- .../workflow_evaluation/create_workflow.py | 252 +++++++++--------- .../agents/azure_ai/azure_ai_basic.py | 4 +- .../azure_ai/azure_ai_use_latest_version.py | 4 +- .../azure_ai/azure_ai_with_agent_to_agent.py | 2 +- .../azure_ai/azure_ai_with_azure_ai_search.py | 2 +- .../azure_ai_with_bing_custom_search.py | 2 +- .../azure_ai/azure_ai_with_bing_grounding.py | 2 +- .../azure_ai_with_browser_automation.py | 2 +- .../azure_ai_with_code_interpreter.py | 2 +- .../azure_ai_with_explicit_settings.py | 2 +- .../azure_ai/azure_ai_with_file_search.py | 2 +- .../azure_ai/azure_ai_with_hosted_mcp.py | 4 +- .../azure_ai_with_image_generation.py | 2 +- .../azure_ai/azure_ai_with_local_mcp.py | 2 +- .../azure_ai/azure_ai_with_memory_search.py | 2 +- .../azure_ai_with_microsoft_fabric.py | 2 +- .../agents/azure_ai/azure_ai_with_openapi.py | 2 +- .../azure_ai/azure_ai_with_response_format.py | 2 +- .../azure_ai_with_runtime_json_schema.py | 2 +- .../azure_ai/azure_ai_with_sharepoint.py | 2 +- .../agents/azure_ai/azure_ai_with_thread.py | 8 +- .../azure_ai/azure_ai_with_web_search.py | 2 +- .../agents/azure_ai_agent/azure_ai_basic.py | 4 +- .../azure_ai_with_bing_custom_search.py | 2 +- .../azure_ai_with_bing_grounding.py | 2 +- .../azure_ai_with_code_interpreter.py | 2 +- .../azure_ai_with_explicit_settings.py | 2 +- .../azure_ai_with_file_search.py | 4 +- .../azure_ai_with_function_tools.py | 6 +- .../azure_ai_with_hosted_mcp.py | 2 +- .../azure_ai_agent/azure_ai_with_local_mcp.py | 4 +- .../azure_ai_with_multiple_tools.py | 2 +- .../azure_ai_with_openapi_tools.py | 2 +- .../azure_ai_agent/azure_ai_with_thread.py | 8 +- .../chat_client/azure_ai_chat_client.py | 2 +- .../azure_ai_search/README.md | 2 +- .../azure_ai_with_search_context_agentic.py | 2 +- .../azure_ai_with_search_context_semantic.py | 2 +- .../context_providers/mem0/mem0_basic.py | 2 +- .../context_providers/mem0/mem0_oss.py | 2 +- .../context_providers/mem0/mem0_threads.py | 8 +- .../simple_context_provider.py | 2 +- .../declarative/inline_yaml.py | 2 +- .../declarative/microsoft_learn_agent.py | 2 +- .../devui/foundry_agent/agent.py | 2 +- .../agent_and_run_level_middleware.py | 2 +- .../middleware/chat_middleware.py | 6 +- .../middleware/class_based_middleware.py | 2 +- .../middleware/decorator_middleware.py | 2 +- .../exception_handling_with_middleware.py | 2 +- .../middleware/function_based_middleware.py | 2 +- .../middleware/middleware_termination.py | 4 +- .../override_result_with_middleware.py | 2 +- .../middleware/shared_state_middleware.py | 2 +- .../threads/suspend_resume_thread.py | 2 +- .../agents/azure_ai_agents_streaming.py | 9 +- .../agents/mixed_agents_and_executors.py | 2 +- .../azure_ai_agent/01_basic_azure_ai_agent.py | 11 +- ...02_azure_ai_agent_with_code_interpreter.py | 13 +- ...03_azure_ai_agent_threads_and_followups.py | 11 +- 65 files changed, 262 insertions(+), 270 deletions(-) diff --git a/python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py b/python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py index a9c01fb066..b4c55f0e55 100644 --- a/python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py +++ b/python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py @@ -122,7 +122,7 @@ def __init__( thread_id: str | None = None, project_endpoint: str | None = None, model_deployment_name: str | None = None, - async_credential: AsyncTokenCredential | None = None, + credential: AsyncTokenCredential | None = None, should_cleanup_agent: bool = True, env_file_path: str | None = None, env_file_encoding: str | None = None, @@ -144,7 +144,7 @@ def __init__( Ignored when a agents_client is passed. model_deployment_name: The model deployment name to use for agent creation. Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME. - async_credential: Azure async credential to use for authentication. + credential: Azure async credential to use for authentication. should_cleanup_agent: Whether to cleanup (delete) agents created by this client when the client is closed or context is exited. Defaults to True. Only affects agents created by this client instance; existing agents passed via agent_id are never deleted. @@ -162,17 +162,17 @@ def __init__( # Set AZURE_AI_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com # Set AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4 credential = DefaultAzureCredential() - client = AzureAIAgentClient(async_credential=credential) + client = AzureAIAgentClient(credential=credential) # Or passing parameters directly client = AzureAIAgentClient( project_endpoint="https://your-project.cognitiveservices.azure.com", model_deployment_name="gpt-4", - async_credential=credential, + credential=credential, ) # Or loading from a .env file - client = AzureAIAgentClient(async_credential=credential, env_file_path="path/to/.env") + client = AzureAIAgentClient(credential=credential, env_file_path="path/to/.env") """ try: azure_ai_settings = AzureAISettings( @@ -200,11 +200,11 @@ def __init__( ) # Use provided credential - if not async_credential: + if not credential: raise ServiceInitializationError("Azure credential is required when agents_client is not provided.") agents_client = AgentsClient( endpoint=azure_ai_settings.project_endpoint, - credential=async_credential, + credential=credential, user_agent=AGENT_FRAMEWORK_USER_AGENT, ) should_close_client = True @@ -214,7 +214,7 @@ def __init__( # Initialize instance variables self.agents_client = agents_client - self.credential = async_credential + self.credential = credential self.agent_id = agent_id self.agent_name = agent_name self.agent_description = agent_description diff --git a/python/packages/azure-ai/agent_framework_azure_ai/_client.py b/python/packages/azure-ai/agent_framework_azure_ai/_client.py index ad0e3ac961..63bd2b27df 100644 --- a/python/packages/azure-ai/agent_framework_azure_ai/_client.py +++ b/python/packages/azure-ai/agent_framework_azure_ai/_client.py @@ -66,7 +66,7 @@ def __init__( conversation_id: str | None = None, project_endpoint: str | None = None, model_deployment_name: str | None = None, - async_credential: AsyncTokenCredential | None = None, + credential: AsyncTokenCredential | None = None, use_latest_version: bool | None = None, env_file_path: str | None = None, env_file_encoding: str | None = None, @@ -86,7 +86,7 @@ def __init__( Ignored when a project_client is passed. model_deployment_name: The model deployment name to use for agent creation. Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME. - async_credential: Azure async credential to use for authentication. + credential: Azure async credential to use for authentication. use_latest_version: Boolean flag that indicates whether to use latest agent version if it exists in the service. env_file_path: Path to environment file for loading settings. @@ -103,17 +103,17 @@ def __init__( # Set AZURE_AI_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com # Set AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4 credential = DefaultAzureCredential() - client = AzureAIClient(async_credential=credential) + client = AzureAIClient(credential=credential) # Or passing parameters directly client = AzureAIClient( project_endpoint="https://your-project.cognitiveservices.azure.com", model_deployment_name="gpt-4", - async_credential=credential, + credential=credential, ) # Or loading from a .env file - client = AzureAIClient(async_credential=credential, env_file_path="path/to/.env") + client = AzureAIClient(credential=credential, env_file_path="path/to/.env") """ try: azure_ai_settings = AzureAISettings( @@ -135,11 +135,11 @@ def __init__( ) # Use provided credential - if not async_credential: + if not credential: raise ServiceInitializationError("Azure credential is required when project_client is not provided.") project_client = AIProjectClient( endpoint=azure_ai_settings.project_endpoint, - credential=async_credential, + credential=credential, user_agent=AGENT_FRAMEWORK_USER_AGENT, ) should_close_client = True @@ -155,7 +155,7 @@ def __init__( self.agent_description = agent_description self.use_latest_version = use_latest_version self.project_client = project_client - self.credential = async_credential + self.credential = credential self.model_id = azure_ai_settings.model_deployment_name self.conversation_id = conversation_id diff --git a/python/packages/azure-ai/tests/test_azure_ai_agent_client.py b/python/packages/azure-ai/tests/test_azure_ai_agent_client.py index 98c9097072..80b2cebdb3 100644 --- a/python/packages/azure-ai/tests/test_azure_ai_agent_client.py +++ b/python/packages/azure-ai/tests/test_azure_ai_agent_client.py @@ -170,7 +170,7 @@ def test_azure_ai_chat_client_init_missing_project_endpoint() -> None: agent_id=None, project_endpoint=None, # Missing endpoint model_deployment_name="test-model", - async_credential=AsyncMock(spec=AsyncTokenCredential), + credential=AsyncMock(spec=AsyncTokenCredential), ) @@ -190,7 +190,7 @@ def test_azure_ai_chat_client_init_missing_model_deployment_for_agent_creation() agent_id=None, # No existing agent project_endpoint="https://test.com", model_deployment_name=None, # Missing for agent creation - async_credential=AsyncMock(spec=AsyncTokenCredential), + credential=AsyncMock(spec=AsyncTokenCredential), ) @@ -223,7 +223,7 @@ def test_azure_ai_chat_client_from_dict(mock_agents_client: MagicMock) -> None: def test_azure_ai_chat_client_init_missing_credential(azure_ai_unit_test_env: dict[str, str]) -> None: - """Test AzureAIAgentClient.__init__ when async_credential is missing and no agents_client provided.""" + """Test AzureAIAgentClient.__init__ when credential is missing and no agents_client provided.""" with pytest.raises( ServiceInitializationError, match="Azure credential is required when agents_client is not provided" ): @@ -232,7 +232,7 @@ def test_azure_ai_chat_client_init_missing_credential(azure_ai_unit_test_env: di agent_id="existing-agent", project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"], model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"], - async_credential=None, # Missing credential + credential=None, # Missing credential ) @@ -246,7 +246,7 @@ def test_azure_ai_chat_client_init_validation_error(mock_azure_credential: Magic AzureAIAgentClient( project_endpoint="https://test.com", model_deployment_name="test-model", - async_credential=mock_azure_credential, + credential=mock_azure_credential, ) @@ -1373,7 +1373,7 @@ def get_weather( @skip_if_azure_ai_integration_tests_disabled async def test_azure_ai_chat_client_get_response() -> None: """Test Azure AI Chat Client response.""" - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client: assert isinstance(azure_ai_chat_client, ChatClientProtocol) messages: list[ChatMessage] = [] @@ -1398,7 +1398,7 @@ async def test_azure_ai_chat_client_get_response() -> None: @skip_if_azure_ai_integration_tests_disabled async def test_azure_ai_chat_client_get_response_tools() -> None: """Test Azure AI Chat Client response with tools.""" - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client: assert isinstance(azure_ai_chat_client, ChatClientProtocol) messages: list[ChatMessage] = [] @@ -1420,7 +1420,7 @@ async def test_azure_ai_chat_client_get_response_tools() -> None: @skip_if_azure_ai_integration_tests_disabled async def test_azure_ai_chat_client_streaming() -> None: """Test Azure AI Chat Client streaming response.""" - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client: assert isinstance(azure_ai_chat_client, ChatClientProtocol) messages: list[ChatMessage] = [] @@ -1451,7 +1451,7 @@ async def test_azure_ai_chat_client_streaming() -> None: @skip_if_azure_ai_integration_tests_disabled async def test_azure_ai_chat_client_streaming_tools() -> None: """Test Azure AI Chat Client streaming response with tools.""" - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client: assert isinstance(azure_ai_chat_client, ChatClientProtocol) messages: list[ChatMessage] = [] @@ -1479,7 +1479,7 @@ async def test_azure_ai_chat_client_streaming_tools() -> None: async def test_azure_ai_chat_client_agent_basic_run() -> None: """Test ChatAgent basic run functionality with AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), ) as agent: # Run a simple query response = await agent.run("Hello! Please respond with 'Hello World' exactly.") @@ -1496,7 +1496,7 @@ async def test_azure_ai_chat_client_agent_basic_run() -> None: async def test_azure_ai_chat_client_agent_basic_run_streaming() -> None: """Test ChatAgent basic streaming functionality with AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), ) as agent: # Run streaming query full_message: str = "" @@ -1516,7 +1516,7 @@ async def test_azure_ai_chat_client_agent_basic_run_streaming() -> None: async def test_azure_ai_chat_client_agent_thread_persistence() -> None: """Test ChatAgent thread persistence across runs with AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant with good memory.", ) as agent: # Create a new thread that will be reused @@ -1542,7 +1542,7 @@ async def test_azure_ai_chat_client_agent_thread_persistence() -> None: async def test_azure_ai_chat_client_agent_existing_thread_id() -> None: """Test ChatAgent existing thread ID functionality with AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant with good memory.", ) as first_agent: # Start a conversation and get the thread ID @@ -1559,7 +1559,7 @@ async def test_azure_ai_chat_client_agent_existing_thread_id() -> None: # Now continue with the same thread ID in a new agent instance async with ChatAgent( - chat_client=AzureAIAgentClient(thread_id=existing_thread_id, async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(thread_id=existing_thread_id, credential=AzureCliCredential()), instructions="You are a helpful assistant with good memory.", ) as second_agent: # Create a thread with the existing ID @@ -1581,7 +1581,7 @@ async def test_azure_ai_chat_client_agent_code_interpreter(): """Test ChatAgent with code interpreter through AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can write and execute Python code.", tools=[HostedCodeInterpreterTool()], ) as agent: @@ -1600,7 +1600,7 @@ async def test_azure_ai_chat_client_agent_code_interpreter(): async def test_azure_ai_chat_client_agent_file_search(): """Test ChatAgent with file search through AzureAIAgentClient.""" - client = AzureAIAgentClient(async_credential=AzureCliCredential()) + client = AzureAIAgentClient(credential=AzureCliCredential()) file: FileInfo | None = None vector_store: VectorStore | None = None @@ -1655,7 +1655,7 @@ async def test_azure_ai_chat_client_agent_hosted_mcp_tool() -> None: ) async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that can help with microsoft documentation questions.", tools=[mcp_tool], ) as agent: @@ -1682,7 +1682,7 @@ async def test_azure_ai_chat_client_agent_hosted_mcp_tool() -> None: async def test_azure_ai_chat_client_agent_level_tool_persistence(): """Test that agent-level tools persist across multiple runs with AzureAIAgentClient.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant that uses available tools.", tools=[get_weather], ) as agent: @@ -1707,7 +1707,7 @@ async def test_azure_ai_chat_client_agent_level_tool_persistence(): async def test_azure_ai_chat_client_agent_chat_options_run_level() -> None: """Test ChatOptions parameter coverage at run level.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant.", ) as agent: response = await agent.run( @@ -1737,7 +1737,7 @@ async def test_azure_ai_chat_client_agent_chat_options_run_level() -> None: async def test_azure_ai_chat_client_agent_chat_options_agent_level() -> None: """Test ChatOptions parameter coverage agent level.""" async with ChatAgent( - chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()), + chat_client=AzureAIAgentClient(credential=AzureCliCredential()), instructions="You are a helpful assistant.", max_tokens=100, temperature=0.7, @@ -1963,7 +1963,7 @@ def test_azure_ai_chat_client_init_with_auto_created_agents_client( agent_id="test-agent", project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"], model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"], - async_credential=mock_azure_credential, + credential=mock_azure_credential, ) # Verify AgentsClient was created with correct parameters diff --git a/python/packages/azure-ai/tests/test_azure_ai_client.py b/python/packages/azure-ai/tests/test_azure_ai_client.py index 151ab62041..2167c1340a 100644 --- a/python/packages/azure-ai/tests/test_azure_ai_client.py +++ b/python/packages/azure-ai/tests/test_azure_ai_client.py @@ -152,7 +152,7 @@ def test_azure_ai_client_init_auto_create_client( client = AzureAIClient( project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"], model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"], - async_credential=mock_azure_credential, + credential=mock_azure_credential, agent_name="test-agent", ) @@ -171,11 +171,11 @@ def test_azure_ai_client_init_missing_project_endpoint() -> None: mock_settings.return_value.model_deployment_name = "test-model" with pytest.raises(ServiceInitializationError, match="Azure AI project endpoint is required"): - AzureAIClient(async_credential=MagicMock()) + AzureAIClient(credential=MagicMock()) def test_azure_ai_client_init_missing_credential(azure_ai_unit_test_env: dict[str, str]) -> None: - """Test AzureAIClient.__init__ when async_credential is missing and no project_client provided.""" + """Test AzureAIClient.__init__ when credential is missing and no project_client provided.""" with pytest.raises( ServiceInitializationError, match="Azure credential is required when project_client is not provided" ): @@ -191,7 +191,7 @@ def test_azure_ai_client_init_validation_error(mock_azure_credential: MagicMock) mock_settings.side_effect = ValidationError.from_exception_data("test", []) with pytest.raises(ServiceInitializationError, match="Failed to create Azure AI settings"): - AzureAIClient(async_credential=mock_azure_credential) + AzureAIClient(credential=mock_azure_credential) async def test_azure_ai_client_get_agent_reference_or_create_existing_version( @@ -320,7 +320,7 @@ async def test_azure_ai_client_prepare_options_with_application_endpoint( client = AzureAIClient( project_endpoint=endpoint, model_deployment_name="test-model", - async_credential=mock_azure_credential, + credential=mock_azure_credential, agent_name="test-agent", agent_version="1", ) diff --git a/python/packages/lab/gaia/samples/azure_ai_agent.py b/python/packages/lab/gaia/samples/azure_ai_agent.py index 78b9c49327..ef87695d99 100644 --- a/python/packages/lab/gaia/samples/azure_ai_agent.py +++ b/python/packages/lab/gaia/samples/azure_ai_agent.py @@ -49,7 +49,7 @@ async def create_gaia_agent() -> AsyncIterator[ChatAgent]: """ async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="GaiaAgent", instructions="Solve tasks to your best ability. Use Bing Search to find " "information and Code Interpreter to perform calculations and data analysis.", diff --git a/python/samples/demos/workflow_evaluation/create_workflow.py b/python/samples/demos/workflow_evaluation/create_workflow.py index ca8b62e2ef..a150b7274f 100644 --- a/python/samples/demos/workflow_evaluation/create_workflow.py +++ b/python/samples/demos/workflow_evaluation/create_workflow.py @@ -21,7 +21,7 @@ Agents: 1. Travel Agent - Main coordinator (no tools to avoid thread conflicts) 2. Hotel Search - Searches hotels with tools -3. Flight Search - Searches flights with tools +3. Flight Search - Searches flights with tools 4. Activity Search - Searches activities with tools 5. Booking Information Aggregation - Aggregates hotel & flight booking info 6. Booking Confirmation - Confirms bookings with tools @@ -32,40 +32,37 @@ import os from collections import defaultdict -from dotenv import load_dotenv - +from _tools import ( + check_flight_availability, + check_hotel_availability, + confirm_booking, + get_flight_details, + get_hotel_details, + process_payment, + search_activities, + search_flights, + # Travel planning tools + search_hotels, + validate_payment_method, +) from agent_framework import ( AgentExecutorResponse, - AgentRunUpdateEvent, AgentRunResponseUpdate, + AgentRunUpdateEvent, ChatMessage, Executor, - executor, - handler, Role, - WorkflowContext, WorkflowBuilder, + WorkflowContext, WorkflowOutputEvent, + executor, + handler, ) -from typing_extensions import Never - from agent_framework.azure import AzureAIClient -from azure.identity.aio import DefaultAzureCredential from azure.ai.projects.aio import AIProjectClient - -from _tools import ( - # Travel planning tools - search_hotels, - get_hotel_details, - search_flights, - get_flight_details, - search_activities, - confirm_booking, - check_hotel_availability, - check_flight_availability, - process_payment, - validate_payment_method, -) +from azure.identity.aio import DefaultAzureCredential +from dotenv import load_dotenv +from typing_extensions import Never load_dotenv() @@ -78,7 +75,7 @@ async def start_executor(input: str, ctx: WorkflowContext[list[ChatMessage]]) -> class ResearchLead(Executor): """Aggregates and summarizes travel planning findings from all specialized agents.""" - + def __init__(self, chat_client: AzureAIClient, id: str = "travel-planning-coordinator"): # store=True to preserve conversation history for evaluation self.agent = chat_client.create_agent( @@ -92,58 +89,69 @@ def __init__(self, chat_client: AzureAIClient, id: str = "travel-planning-coordi "Clearly indicate which information came from which agent. Do not use tools." ), name="travel-planning-coordinator", - store=True + store=True, ) super().__init__(id=id) @handler async def fan_in_handle(self, responses: list[AgentExecutorResponse], ctx: WorkflowContext[Never, str]) -> None: user_query = responses[0].full_conversation[0].text - + # Extract findings from all agent responses agent_findings = self._extract_agent_findings(responses) - summary_text = "\n".join(agent_findings) if agent_findings else "No specific findings were provided by the agents." - + summary_text = ( + "\n".join(agent_findings) if agent_findings else "No specific findings were provided by the agents." + ) + # Generate comprehensive travel plan summary messages = [ - ChatMessage(role=Role.SYSTEM, text="You are a travel planning coordinator. Summarize findings from multiple specialized travel agents and provide a clear, comprehensive travel plan based on the user's query."), - ChatMessage(role=Role.USER, text=f"Original query: {user_query}\n\nFindings from specialized travel agents:\n{summary_text}\n\nPlease provide a comprehensive travel plan based on these findings.") + ChatMessage( + role=Role.SYSTEM, + text="You are a travel planning coordinator. Summarize findings from multiple specialized travel agents and provide a clear, comprehensive travel plan based on the user's query.", + ), + ChatMessage( + role=Role.USER, + text=f"Original query: {user_query}\n\nFindings from specialized travel agents:\n{summary_text}\n\nPlease provide a comprehensive travel plan based on these findings.", + ), ] - + try: final_response = await self.agent.run(messages) - output_text = (final_response.messages[-1].text if final_response.messages and final_response.messages[-1].text - else f"Based on the available findings, here's your travel plan for '{user_query}': {summary_text}") + output_text = ( + final_response.messages[-1].text + if final_response.messages and final_response.messages[-1].text + else f"Based on the available findings, here's your travel plan for '{user_query}': {summary_text}" + ) except Exception: output_text = f"Based on the available findings, here's your travel plan for '{user_query}': {summary_text}" - + await ctx.yield_output(output_text) - + def _extract_agent_findings(self, responses: list[AgentExecutorResponse]) -> list[str]: """Extract findings from agent responses.""" agent_findings = [] - + for response in responses: findings = [] if response.agent_run_response and response.agent_run_response.messages: for msg in response.agent_run_response.messages: if msg.role == Role.ASSISTANT and msg.text and msg.text.strip(): findings.append(msg.text.strip()) - + if findings: combined_findings = " ".join(findings) agent_findings.append(f"[{response.executor_id}]: {combined_findings}") - + return agent_findings async def run_workflow_with_response_tracking(query: str, chat_client: AzureAIClient | None = None) -> dict: """Run multi-agent workflow and track conversation IDs, response IDs, and interaction sequence. - + Args: query: The user query to process through the multi-agent workflow chat_client: Optional AzureAIClient instance - + Returns: Dictionary containing interaction sequence, conversation/response IDs, and conversation analysis """ @@ -155,11 +163,11 @@ async def run_workflow_with_response_tracking(query: str, chat_client: AzureAICl credential=credential, api_version="2025-11-15-preview", ) - + async with ( DefaultAzureCredential() as credential, project_client, - AzureAIClient(project_client=project_client, async_credential=credential) as client + AzureAIClient(project_client=project_client, credential=credential) as client, ): return await _run_workflow_with_client(query, client) except Exception as e: @@ -171,53 +179,46 @@ async def run_workflow_with_response_tracking(query: str, chat_client: AzureAICl async def _run_workflow_with_client(query: str, chat_client: AzureAIClient) -> dict: """Execute workflow with given client and track all interactions.""" - + # Initialize tracking variables - use lists to track multiple responses per agent conversation_ids = defaultdict(list) response_ids = defaultdict(list) workflow_output = None - + # Create workflow components and keep agent references # Pass project_client and credential to create separate client instances per agent - workflow, agent_map = await _create_workflow( - chat_client.project_client, - chat_client.credential - ) - + workflow, agent_map = await _create_workflow(chat_client.project_client, chat_client.credential) + # Process workflow events events = workflow.run_stream(query) workflow_output = await _process_workflow_events(events, conversation_ids, response_ids) - + return { "conversation_ids": dict(conversation_ids), "response_ids": dict(response_ids), "output": workflow_output, - "query": query + "query": query, } async def _create_workflow(project_client, credential): """Create the multi-agent travel planning workflow with specialized agents. - + IMPORTANT: Each agent needs its own client instance because the V2 client stores agent_name and agent_version as instance variables, causing all agents to share the same agent identity if they share a client. """ - + # Create separate client for Final Coordinator final_coordinator_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="final-coordinator" + project_client=project_client, credential=credential, agent_name="final-coordinator" ) final_coordinator = ResearchLead(chat_client=final_coordinator_client, id="final-coordinator") - + # Agent 1: Travel Request Handler (initial coordinator) # Create separate client with unique agent_name travel_request_handler_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="travel-request-handler" + project_client=project_client, credential=credential, agent_name="travel-request-handler" ) travel_request_handler = travel_request_handler_client.create_agent( id="travel-request-handler", @@ -225,14 +226,12 @@ async def _create_workflow(project_client, credential): "You receive user travel queries and relay them to specialized agents. Extract key information: destination, dates, budget, and preferences. Pass this information forward clearly to the next agents." ), name="travel-request-handler", - store=True + store=True, ) - + # Agent 2: Hotel Search Executor hotel_search_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="hotel-search-agent" + project_client=project_client, credential=credential, agent_name="hotel-search-agent" ) hotel_search_agent = hotel_search_client.create_agent( id="hotel-search-agent", @@ -241,14 +240,12 @@ async def _create_workflow(project_client, credential): ), name="hotel-search-agent", tools=[search_hotels, get_hotel_details, check_hotel_availability], - store=True + store=True, ) - + # Agent 3: Flight Search Executor flight_search_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="flight-search-agent" + project_client=project_client, credential=credential, agent_name="flight-search-agent" ) flight_search_agent = flight_search_client.create_agent( id="flight-search-agent", @@ -257,14 +254,12 @@ async def _create_workflow(project_client, credential): ), name="flight-search-agent", tools=[search_flights, get_flight_details, check_flight_availability], - store=True + store=True, ) - + # Agent 4: Activity Search Executor activity_search_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="activity-search-agent" + project_client=project_client, credential=credential, agent_name="activity-search-agent" ) activity_search_agent = activity_search_client.create_agent( id="activity-search-agent", @@ -273,14 +268,12 @@ async def _create_workflow(project_client, credential): ), name="activity-search-agent", tools=[search_activities], - store=True + store=True, ) - + # Agent 5: Booking Confirmation Executor booking_confirmation_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="booking-confirmation-agent" + project_client=project_client, credential=credential, agent_name="booking-confirmation-agent" ) booking_confirmation_agent = booking_confirmation_client.create_agent( id="booking-confirmation-agent", @@ -289,14 +282,12 @@ async def _create_workflow(project_client, credential): ), name="booking-confirmation-agent", tools=[confirm_booking, check_hotel_availability, check_flight_availability], - store=True + store=True, ) - + # Agent 6: Booking Payment Executor booking_payment_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="booking-payment-agent" + project_client=project_client, credential=credential, agent_name="booking-payment-agent" ) booking_payment_agent = booking_payment_client.create_agent( id="booking-payment-agent", @@ -305,14 +296,12 @@ async def _create_workflow(project_client, credential): ), name="booking-payment-agent", tools=[process_payment, validate_payment_method], - store=True + store=True, ) - + # Agent 7: Booking Information Aggregation Executor booking_info_client = AzureAIClient( - project_client=project_client, - async_credential=credential, - agent_name="booking-info-aggregation-agent" + project_client=project_client, credential=credential, agent_name="booking-info-aggregation-agent" ) booking_info_aggregation_agent = booking_info_client.create_agent( id="booking-info-aggregation-agent", @@ -320,9 +309,9 @@ async def _create_workflow(project_client, credential): "You aggregate hotel and flight search results. Receive options from search agents and organize them. Provide: top 2-3 hotel options with prices and top 2-3 flight options with prices in a structured format." ), name="booking-info-aggregation-agent", - store=True + store=True, ) - + # Build workflow with logical booking flow: # 1. start_executor → travel_request_handler # 2. travel_request_handler → hotel_search, flight_search, activity_search (fan-out) @@ -331,19 +320,22 @@ async def _create_workflow(project_client, credential): # 5. booking_info_aggregation → booking_confirmation # 6. booking_confirmation → booking_payment # 7. booking_info_aggregation, booking_payment, activity_search → final_coordinator (final aggregation, fan-in) - - workflow = (WorkflowBuilder(name='Travel Planning Workflow') - .set_start_executor(start_executor) - .add_edge(start_executor, travel_request_handler) - .add_fan_out_edges(travel_request_handler, [hotel_search_agent, flight_search_agent, activity_search_agent]) - .add_edge(hotel_search_agent, booking_info_aggregation_agent) - .add_edge(flight_search_agent, booking_info_aggregation_agent) - .add_edge(booking_info_aggregation_agent, booking_confirmation_agent) - .add_edge(booking_confirmation_agent, booking_payment_agent) - .add_fan_in_edges([booking_info_aggregation_agent, booking_payment_agent, activity_search_agent], - final_coordinator) - .build()) - + + workflow = ( + WorkflowBuilder(name="Travel Planning Workflow") + .set_start_executor(start_executor) + .add_edge(start_executor, travel_request_handler) + .add_fan_out_edges(travel_request_handler, [hotel_search_agent, flight_search_agent, activity_search_agent]) + .add_edge(hotel_search_agent, booking_info_aggregation_agent) + .add_edge(flight_search_agent, booking_info_aggregation_agent) + .add_edge(booking_info_aggregation_agent, booking_confirmation_agent) + .add_edge(booking_confirmation_agent, booking_payment_agent) + .add_fan_in_edges( + [booking_info_aggregation_agent, booking_payment_agent, activity_search_agent], final_coordinator + ) + .build() + ) + # Return workflow and agent map for thread ID extraction agent_map = { "travel_request_handler": travel_request_handler, @@ -355,14 +347,14 @@ async def _create_workflow(project_client, credential): "booking-info-aggregation-agent": booking_info_aggregation_agent, "final-coordinator": final_coordinator.agent, } - + return workflow, agent_map async def _process_workflow_events(events, conversation_ids, response_ids): """Process workflow events and track interactions.""" workflow_output = None - + async for event in events: if isinstance(event, WorkflowOutputEvent): workflow_output = event.data @@ -370,12 +362,12 @@ async def _process_workflow_events(events, conversation_ids, response_ids): try: print(f"\nWorkflow Output: {event.data}\n") except UnicodeEncodeError: - output_str = str(event.data).encode('ascii', 'replace').decode('ascii') + output_str = str(event.data).encode("ascii", "replace").decode("ascii") print(f"\nWorkflow Output: {output_str}\n") - + elif isinstance(event, AgentRunUpdateEvent): _track_agent_ids(event, event.executor_id, response_ids, conversation_ids) - + return workflow_output @@ -384,21 +376,21 @@ def _track_agent_ids(event, agent, response_ids, conversation_ids): if isinstance(event.data, AgentRunResponseUpdate): # Check for conversation_id and response_id from raw_representation # V2 API stores conversation_id directly on raw_representation (ChatResponseUpdate) - if hasattr(event.data, 'raw_representation') and event.data.raw_representation: + if hasattr(event.data, "raw_representation") and event.data.raw_representation: raw = event.data.raw_representation - + # Try conversation_id directly on raw representation - if hasattr(raw, 'conversation_id') and raw.conversation_id: + if hasattr(raw, "conversation_id") and raw.conversation_id: # Only add if not already in the list if raw.conversation_id not in conversation_ids[agent]: conversation_ids[agent].append(raw.conversation_id) - + # Extract response_id from the OpenAI event (available from first event) - if hasattr(raw, 'raw_representation') and raw.raw_representation: + if hasattr(raw, "raw_representation") and raw.raw_representation: openai_event = raw.raw_representation - + # Check if event has response object with id - if hasattr(openai_event, 'response') and hasattr(openai_event.response, 'id'): + if hasattr(openai_event, "response") and hasattr(openai_event.response, "id"): # Only add if not already in the list if openai_event.response.id not in response_ids[agent]: response_ids[agent].append(openai_event.response.id) @@ -406,7 +398,7 @@ def _track_agent_ids(event, agent, response_ids, conversation_ids): async def create_and_run_workflow(): """Run the workflow evaluation and display results. - + Returns: Dictionary containing agents data with conversation IDs, response IDs, and query information """ @@ -415,36 +407,32 @@ async def create_and_run_workflow(): "Find a budget hotel in Tokyo for January 5-10, 2026 under $150/night near Shibuya station, book activities including a sushi making class", "Search for round-trip flights from Los Angeles to London departing March 20, 2026, returning March 27, 2026. Economy class, 2 passengers. Recommend tourist attractions and museums.", ] - + query = example_queries[0] print(f"Query: {query}\n") - + result = await run_workflow_with_response_tracking(query) - + # Create output data structure - output_data = { - "agents": {}, - "query": result["query"], - "output": result.get("output", "") - } - + output_data = {"agents": {}, "query": result["query"], "output": result.get("output", "")} + # Create agent-specific mappings - now with lists of IDs all_agents = set(result["conversation_ids"].keys()) | set(result["response_ids"].keys()) for agent_name in all_agents: output_data["agents"][agent_name] = { "conversation_ids": result["conversation_ids"].get(agent_name, []), "response_ids": result["response_ids"].get(agent_name, []), - "response_count": len(result["response_ids"].get(agent_name, [])) + "response_count": len(result["response_ids"].get(agent_name, [])), } - + print(f"\nTotal agents tracked: {len(output_data['agents'])}") - + # Print summary of multiple responses print("\n=== Multi-Response Summary ===") for agent_name, agent_data in output_data["agents"].items(): response_count = agent_data["response_count"] print(f"{agent_name}: {response_count} response(s)") - + return output_data diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_basic.py b/python/samples/getting_started/agents/azure_ai/azure_ai_basic.py index 87a121d015..86aa603892 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_basic.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_basic.py @@ -33,7 +33,7 @@ async def non_streaming_example() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -54,7 +54,7 @@ async def streaming_example() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_use_latest_version.py b/python/samples/getting_started/agents/azure_ai/azure_ai_use_latest_version.py index 1875936183..1a2a152821 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_use_latest_version.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_use_latest_version.py @@ -31,7 +31,7 @@ async def main() -> None: async with AzureCliCredential() as credential: async with ( AzureAIClient( - async_credential=credential, + credential=credential, ).create_agent( name="MyWeatherAgent", instructions="You are a helpful weather agent.", @@ -47,7 +47,7 @@ async def main() -> None: # Create a new agent instance async with ( AzureAIClient( - async_credential=credential, + credential=credential, # This parameter will allow to re-use latest agent version # instead of creating a new one use_latest_version=True, diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_to_agent.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_to_agent.py index 8efb3d9473..93bd445e28 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_to_agent.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_to_agent.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyA2AAgent", instructions="""You are a helpful assistant that can communicate with other agents. Use the A2A tool when you need to interact with other agents to complete tasks diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_azure_ai_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_azure_ai_search.py index 47dd026c89..057c2b5ff7 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_azure_ai_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_azure_ai_search.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MySearchAgent", instructions="""You are a helpful assistant. You must always provide citations for answers using the tool and render them as: `[message_idx:search_idx†source]`.""", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py index 7db42e9f21..682e2fc38e 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_custom_search.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyCustomSearchAgent", 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.""", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_grounding.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_grounding.py index 4619f70284..810962ab24 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_grounding.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_bing_grounding.py @@ -27,7 +27,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyBingGroundingAgent", instructions="""You are a helpful assistant that can search the web for current information. Use the Bing search tool to find up-to-date information and provide accurate, well-sourced answers. diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py index f614228d39..72ee2cd5b0 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_browser_automation.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyBrowserAutomationAgent", instructions="""You are an Agent helping with browser automation tasks. You can answer questions, provide information, and assist with various tasks diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter.py index b81a2add85..2622e273e8 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyCodeInterpreterAgent", instructions="You are a helpful assistant that can write and execute Python code to solve problems.", tools=HostedCodeInterpreterTool(), diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_explicit_settings.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_explicit_settings.py index 7d6c91f731..d5860a64f2 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_explicit_settings.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_explicit_settings.py @@ -36,7 +36,7 @@ async def main() -> None: chat_client=AzureAIClient( project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], model_deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], - async_credential=credential, + credential=credential, agent_name="WeatherAgent", ), instructions="You are a helpful weather agent.", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_file_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_file_search.py index 28c47de5ca..de8c3b22b1 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_file_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_file_search.py @@ -32,7 +32,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, AgentsClient(endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential) as agents_client, - AzureAIClient(async_credential=credential) as client, + AzureAIClient(credential=credential) as client, ): try: # 1. Upload file and create vector store diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_hosted_mcp.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_hosted_mcp.py index bf9d162a2d..dd72108c05 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_hosted_mcp.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_hosted_mcp.py @@ -64,7 +64,7 @@ async def run_hosted_mcp_without_approval() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyLearnDocsAgent", instructions="You are a helpful assistant that can help with Microsoft documentation questions.", tools=HostedMCPTool( @@ -89,7 +89,7 @@ async def run_hosted_mcp_with_approval_and_thread() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyApiSpecsAgent", instructions="You are a helpful agent that can use MCP tools to assist users.", tools=HostedMCPTool( diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_image_generation.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_image_generation.py index 9cf631bd4e..849e44761a 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_image_generation.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_image_generation.py @@ -27,7 +27,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="ImageGenAgent", instructions="Generate images based on user requirements.", tools=[ImageGenTool(quality="low", size="1024x1024")], diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_local_mcp.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_local_mcp.py index dd8cb0abab..5f97116707 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_local_mcp.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_local_mcp.py @@ -24,7 +24,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="DocsAgent", instructions="You are a helpful assistant that can help with Microsoft documentation questions.", tools=MCPStreamableHTTPTool( diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_memory_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_memory_search.py index 481bf2f151..2996840489 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_memory_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_memory_search.py @@ -47,7 +47,7 @@ async def main() -> None: print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}") # Then, create the agent using Agent Framework - async with AzureAIClient(async_credential=credential).create_agent( + async with AzureAIClient(credential=credential).create_agent( name="MyMemoryAgent", instructions="""You are a helpful assistant that remembers past conversations. Use the memory search tool to recall relevant information from previous interactions.""", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py index 8b77d9221d..e19837f99b 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_microsoft_fabric.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyFabricAgent", instructions="You are a helpful assistant.", tools={ diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_openapi.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_openapi.py index 8ef165e838..8824106656 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_openapi.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_openapi.py @@ -29,7 +29,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MyOpenAPIAgent", instructions="""You are a helpful assistant that can use country APIs to provide information. Use the available OpenAPI tools to answer questions about countries, currencies, and demographics.""", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_response_format.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_response_format.py index 2ffc8a8bad..dfb4ce6a21 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_response_format.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_response_format.py @@ -29,7 +29,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="ProductMarketerAgent", instructions="Return launch briefs as structured JSON.", ) as agent, diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_runtime_json_schema.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_runtime_json_schema.py index 593a70054b..17bf359afe 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_runtime_json_schema.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_runtime_json_schema.py @@ -36,7 +36,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="ProductMarketerAgent", instructions="Return launch briefs as structured JSON.", ) as agent, diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_sharepoint.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_sharepoint.py index cdd81a33af..a724bda2d2 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_sharepoint.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_sharepoint.py @@ -21,7 +21,7 @@ async def main() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="MySharePointAgent", 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.""", diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py index e1cbe8c5e4..fe8c7f5370 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py @@ -30,7 +30,7 @@ async def example_with_automatic_thread_creation() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -59,7 +59,7 @@ async def example_with_thread_persistence_in_memory() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -100,7 +100,7 @@ async def example_with_existing_thread_id() -> None: async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -122,7 +122,7 @@ async def example_with_existing_thread_id() -> None: print("\n--- Continuing with the same thread ID in a new agent instance ---") async with ( - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="BasicWeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_web_search.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_web_search.py index 7a73cf0ac8..ef788e4f5e 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_web_search.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_web_search.py @@ -24,7 +24,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIClient(async_credential=credential).create_agent( + AzureAIClient(credential=credential).create_agent( name="WebsearchAgent", instructions="You are a helpful assistant that can search the web", tools=[HostedWebSearchTool()], diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_basic.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_basic.py index 633b5b9daa..216425cc40 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_basic.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_basic.py @@ -34,7 +34,7 @@ async def non_streaming_example() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, @@ -56,7 +56,7 @@ async def streaming_example() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather agent.", tools=get_weather, diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py index 0474d6c5bc..1ef8d6bcb1 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_custom_search.py @@ -39,7 +39,7 @@ async def main() -> None: # 2. Use AzureAIAgentClient as async context manager for automatic cleanup async with ( - AzureAIAgentClient(async_credential=AzureCliCredential()) as client, + AzureAIAgentClient(credential=AzureCliCredential()) as client, ChatAgent( chat_client=client, name="BingSearchAgent", diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_grounding.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_grounding.py index 462bf26f7b..a83f5bb1f4 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_grounding.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_bing_grounding.py @@ -34,7 +34,7 @@ async def main() -> None: # 2. Use AzureAIAgentClient as async context manager for automatic cleanup async with ( - AzureAIAgentClient(async_credential=AzureCliCredential()) as client, + AzureAIAgentClient(credential=AzureCliCredential()) as client, ChatAgent( chat_client=client, name="BingSearchAgent", diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_code_interpreter.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_code_interpreter.py index f4bf48bd59..0136512373 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_code_interpreter.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_code_interpreter.py @@ -39,7 +39,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential) as chat_client, + AzureAIAgentClient(credential=credential) as chat_client, ): agent = chat_client.create_agent( name="CodingAgent", diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_explicit_settings.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_explicit_settings.py index 0ac2ee620c..14bb063149 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_explicit_settings.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_explicit_settings.py @@ -39,7 +39,7 @@ async def main() -> None: chat_client=AzureAIAgentClient( project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], model_deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], - async_credential=credential, + credential=credential, agent_name="WeatherAgent", should_cleanup_agent=True, # Set to False if you want to disable automatic agent cleanup ), diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_file_search.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_file_search.py index b00bfc1f26..8be9b79423 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_file_search.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_file_search.py @@ -24,7 +24,7 @@ async def main() -> None: """Main function demonstrating Azure AI agent with file search capabilities.""" - client = AzureAIAgentClient(async_credential=AzureCliCredential()) + client = AzureAIAgentClient(credential=AzureCliCredential()) file: FileInfo | None = None vector_store: VectorStore | None = None @@ -74,7 +74,7 @@ async def main() -> None: # 6. Cleanup: Delete the vector store and file in case of earlier failure to prevent orphaned resources. # Refreshing the client is required since chat agent closes it - client = AzureAIAgentClient(async_credential=AzureCliCredential()) + client = AzureAIAgentClient(credential=AzureCliCredential()) try: if vector_store: await client.agents_client.vector_stores.delete(vector_store.id) diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_function_tools.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_function_tools.py index 36c40dbd93..a301557612 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_function_tools.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_function_tools.py @@ -43,7 +43,7 @@ async def tools_on_agent_level() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a helpful assistant that can provide weather and time information.", tools=[get_weather, get_time], # Tools defined at agent creation ) as agent, @@ -77,7 +77,7 @@ async def tools_on_run_level() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a helpful assistant.", # No tools defined here ) as agent, @@ -111,7 +111,7 @@ async def mixed_tools_example() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a comprehensive assistant that can help with various information requests.", tools=[get_weather], # Base tool available for all queries ) as agent, diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_hosted_mcp.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_hosted_mcp.py index 6bed30dd21..10a5a68031 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_hosted_mcp.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_hosted_mcp.py @@ -42,7 +42,7 @@ async def main() -> None: """Example showing Hosted MCP tools for a Azure AI Agent.""" async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential) as chat_client, + AzureAIAgentClient(credential=credential) as chat_client, ): agent = chat_client.create_agent( name="DocsAgent", diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_local_mcp.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_local_mcp.py index b5fbc0053f..fb4f49e47e 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_local_mcp.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_local_mcp.py @@ -28,7 +28,7 @@ async def mcp_tools_on_run_level() -> None: url="https://learn.microsoft.com/api/mcp", ) as mcp_server, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), name="DocsAgent", instructions="You are a helpful assistant that can help with microsoft documentation questions.", ) as agent, @@ -55,7 +55,7 @@ async def mcp_tools_on_agent_level() -> None: # The agent will connect to the MCP server through its context manager. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="DocsAgent", instructions="You are a helpful assistant that can help with microsoft documentation questions.", tools=MCPStreamableHTTPTool( # Tools defined at agent creation diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_multiple_tools.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_multiple_tools.py index 7d8a226f80..ab29d85971 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_multiple_tools.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_multiple_tools.py @@ -67,7 +67,7 @@ async def main() -> None: """Example showing Hosted MCP tools for a Azure AI Agent.""" async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential) as chat_client, + AzureAIAgentClient(credential=credential) as chat_client, ): agent = chat_client.create_agent( name="DocsAgent", diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_openapi_tools.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_openapi_tools.py index c909c73f84..4b4db76f6b 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_openapi_tools.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_openapi_tools.py @@ -41,7 +41,7 @@ async def main() -> None: weather_openapi_spec, countries_openapi_spec = load_openapi_specs() # 2. Use AzureAIAgentClient as async context manager for automatic cleanup - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as client: # 3. Create OpenAPI tools using Azure AI's OpenApiTool auth = OpenApiAnonymousAuthDetails() diff --git a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_thread.py b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_thread.py index e2dd175657..fbc34e52df 100644 --- a/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_thread.py +++ b/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_thread.py @@ -34,7 +34,7 @@ async def example_with_automatic_thread_creation() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -63,7 +63,7 @@ async def example_with_thread_persistence() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -104,7 +104,7 @@ async def example_with_existing_thread_id() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(async_credential=credential), + chat_client=AzureAIAgentClient(credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, @@ -127,7 +127,7 @@ async def example_with_existing_thread_id() -> None: async with ( AzureCliCredential() as credential, ChatAgent( - chat_client=AzureAIAgentClient(thread_id=existing_thread_id, async_credential=credential), + chat_client=AzureAIAgentClient(thread_id=existing_thread_id, credential=credential), instructions="You are a helpful weather agent.", tools=get_weather, ) as agent, diff --git a/python/samples/getting_started/chat_client/azure_ai_chat_client.py b/python/samples/getting_started/chat_client/azure_ai_chat_client.py index 2cf8d9815e..22b1324565 100644 --- a/python/samples/getting_started/chat_client/azure_ai_chat_client.py +++ b/python/samples/getting_started/chat_client/azure_ai_chat_client.py @@ -27,7 +27,7 @@ def get_weather( async def main() -> None: # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred # authentication option. - async with AzureAIAgentClient(async_credential=AzureCliCredential()) as client: + async with AzureAIAgentClient(credential=AzureCliCredential()) as client: message = "What's the weather in Amsterdam and in Paris?" stream = False print(f"User: {message}") diff --git a/python/samples/getting_started/context_providers/azure_ai_search/README.md b/python/samples/getting_started/context_providers/azure_ai_search/README.md index 67f2ead963..3233d3af88 100644 --- a/python/samples/getting_started/context_providers/azure_ai_search/README.md +++ b/python/samples/getting_started/context_providers/azure_ai_search/README.md @@ -140,7 +140,7 @@ search_provider = AzureAISearchContextProvider( ) # Create agent with search context -async with AzureAIAgentClient(async_credential=DefaultAzureCredential()) as client: +async with AzureAIAgentClient(credential=DefaultAzureCredential()) as client: async with ChatAgent( chat_client=client, model=model_deployment, diff --git a/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py b/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py index f8e1123b8f..132298c0b2 100644 --- a/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py +++ b/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py @@ -110,7 +110,7 @@ async def main() -> None: AzureAIAgentClient( project_endpoint=project_endpoint, model_deployment_name=model_deployment, - async_credential=AzureCliCredential(), + credential=AzureCliCredential(), ) as client, ChatAgent( chat_client=client, diff --git a/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_semantic.py b/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_semantic.py index c37862ae3f..90ea4bbe4a 100644 --- a/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_semantic.py +++ b/python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_semantic.py @@ -67,7 +67,7 @@ async def main() -> None: AzureAIAgentClient( project_endpoint=project_endpoint, model_deployment_name=model_deployment, - async_credential=AzureCliCredential(), + credential=AzureCliCredential(), ) as client, ChatAgent( chat_client=client, diff --git a/python/samples/getting_started/context_providers/mem0/mem0_basic.py b/python/samples/getting_started/context_providers/mem0/mem0_basic.py index 70a70a4c35..0c2252d66a 100644 --- a/python/samples/getting_started/context_providers/mem0/mem0_basic.py +++ b/python/samples/getting_started/context_providers/mem0/mem0_basic.py @@ -32,7 +32,7 @@ async def main() -> None: # For Mem0 authentication, set Mem0 API key via "api_key" parameter or MEM0_API_KEY environment variable. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="FriendlyAssistant", instructions="You are a friendly assistant.", tools=retrieve_company_report, diff --git a/python/samples/getting_started/context_providers/mem0/mem0_oss.py b/python/samples/getting_started/context_providers/mem0/mem0_oss.py index e4aa976fb3..dcf92e8024 100644 --- a/python/samples/getting_started/context_providers/mem0/mem0_oss.py +++ b/python/samples/getting_started/context_providers/mem0/mem0_oss.py @@ -35,7 +35,7 @@ async def main() -> None: local_mem0_client = AsyncMemory() async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="FriendlyAssistant", instructions="You are a friendly assistant.", tools=retrieve_company_report, diff --git a/python/samples/getting_started/context_providers/mem0/mem0_threads.py b/python/samples/getting_started/context_providers/mem0/mem0_threads.py index 0cbc7b59be..d014384394 100644 --- a/python/samples/getting_started/context_providers/mem0/mem0_threads.py +++ b/python/samples/getting_started/context_providers/mem0/mem0_threads.py @@ -27,7 +27,7 @@ async def example_global_thread_scope() -> None: async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="GlobalMemoryAssistant", instructions="You are an assistant that remembers user preferences across conversations.", tools=get_user_preferences, @@ -65,7 +65,7 @@ async def example_per_operation_thread_scope() -> None: async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="ScopedMemoryAssistant", instructions="You are an assistant with thread-scoped memory.", tools=get_user_preferences, @@ -113,14 +113,14 @@ async def example_multiple_agents() -> None: async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="PersonalAssistant", instructions="You are a personal assistant that helps with personal tasks.", context_providers=Mem0Provider( agent_id=agent_id_1, ), ) as personal_agent, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WorkAssistant", instructions="You are a work assistant that helps with professional tasks.", context_providers=Mem0Provider( diff --git a/python/samples/getting_started/context_providers/simple_context_provider.py b/python/samples/getting_started/context_providers/simple_context_provider.py index b3330570e1..38e5d4dd52 100644 --- a/python/samples/getting_started/context_providers/simple_context_provider.py +++ b/python/samples/getting_started/context_providers/simple_context_provider.py @@ -91,7 +91,7 @@ def serialize(self) -> str: async def main(): async with AzureCliCredential() as credential: - chat_client = AzureAIClient(async_credential=credential) + chat_client = AzureAIClient(credential=credential) # Create the memory provider memory_provider = UserInfoMemory(chat_client) diff --git a/python/samples/getting_started/declarative/inline_yaml.py b/python/samples/getting_started/declarative/inline_yaml.py index 96a3bd7b18..7c2bfa6dbf 100644 --- a/python/samples/getting_started/declarative/inline_yaml.py +++ b/python/samples/getting_started/declarative/inline_yaml.py @@ -34,7 +34,7 @@ async def main(): # create the agent from the yaml async with ( AzureCliCredential() as credential, - AgentFactory(client_kwargs={"async_credential": credential}).create_agent_from_yaml(yaml_definition) as agent, + AgentFactory(client_kwargs={"credential": credential}).create_agent_from_yaml(yaml_definition) as agent, ): response = await agent.run("What can you do for me?") print("Agent response:", response.text) diff --git a/python/samples/getting_started/declarative/microsoft_learn_agent.py b/python/samples/getting_started/declarative/microsoft_learn_agent.py index bdbda4f76f..7a346096ea 100644 --- a/python/samples/getting_started/declarative/microsoft_learn_agent.py +++ b/python/samples/getting_started/declarative/microsoft_learn_agent.py @@ -15,7 +15,7 @@ async def main(): # create the agent from the yaml async with ( AzureCliCredential() as credential, - AgentFactory(client_kwargs={"async_credential": credential}).create_agent_from_yaml_path(yaml_path) as agent, + AgentFactory(client_kwargs={"credential": credential}).create_agent_from_yaml_path(yaml_path) as agent, ): response = await agent.run("How do I create a storage account with private endpoint using bicep?") print("Agent response:", response.text) diff --git a/python/samples/getting_started/devui/foundry_agent/agent.py b/python/samples/getting_started/devui/foundry_agent/agent.py index 97e49b339c..58f5fd41f5 100644 --- a/python/samples/getting_started/devui/foundry_agent/agent.py +++ b/python/samples/getting_started/devui/foundry_agent/agent.py @@ -45,7 +45,7 @@ def get_forecast( chat_client=AzureAIAgentClient( project_endpoint=os.environ.get("AZURE_AI_PROJECT_ENDPOINT"), model_deployment_name=os.environ.get("FOUNDRY_MODEL_DEPLOYMENT_NAME"), - async_credential=AzureCliCredential(), + credential=AzureCliCredential(), ), instructions=""" You are a weather assistant using Azure AI Foundry models. You can provide diff --git a/python/samples/getting_started/middleware/agent_and_run_level_middleware.py b/python/samples/getting_started/middleware/agent_and_run_level_middleware.py index c0ba169680..fce26d2a71 100644 --- a/python/samples/getting_started/middleware/agent_and_run_level_middleware.py +++ b/python/samples/getting_started/middleware/agent_and_run_level_middleware.py @@ -166,7 +166,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/chat_middleware.py b/python/samples/getting_started/middleware/chat_middleware.py index 37674a86d9..9573e6e666 100644 --- a/python/samples/getting_started/middleware/chat_middleware.py +++ b/python/samples/getting_started/middleware/chat_middleware.py @@ -142,7 +142,7 @@ async def class_based_chat_middleware() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="EnhancedChatAgent", instructions="You are a helpful AI assistant.", # Register class-based middleware at agent level (applies to all runs) @@ -164,7 +164,7 @@ async def function_based_chat_middleware() -> None: async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="FunctionMiddlewareAgent", instructions="You are a helpful AI assistant.", # Register function-based middleware at agent level @@ -194,7 +194,7 @@ async def run_level_middleware() -> None: async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="RunLevelAgent", instructions="You are a helpful AI assistant.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/class_based_middleware.py b/python/samples/getting_started/middleware/class_based_middleware.py index d446bf29c2..0bf990a1f4 100644 --- a/python/samples/getting_started/middleware/class_based_middleware.py +++ b/python/samples/getting_started/middleware/class_based_middleware.py @@ -99,7 +99,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/decorator_middleware.py b/python/samples/getting_started/middleware/decorator_middleware.py index 5d9a979176..26930430ac 100644 --- a/python/samples/getting_started/middleware/decorator_middleware.py +++ b/python/samples/getting_started/middleware/decorator_middleware.py @@ -70,7 +70,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="TimeAgent", instructions="You are a helpful time assistant. Call get_current_time when asked about time.", tools=get_current_time, diff --git a/python/samples/getting_started/middleware/exception_handling_with_middleware.py b/python/samples/getting_started/middleware/exception_handling_with_middleware.py index 4644ae888c..07cfdb0854 100644 --- a/python/samples/getting_started/middleware/exception_handling_with_middleware.py +++ b/python/samples/getting_started/middleware/exception_handling_with_middleware.py @@ -58,7 +58,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="DataAgent", instructions="You are a helpful data assistant. Use the data service tool to fetch information for users.", tools=unstable_data_service, diff --git a/python/samples/getting_started/middleware/function_based_middleware.py b/python/samples/getting_started/middleware/function_based_middleware.py index de962a12ad..5b320c57f2 100644 --- a/python/samples/getting_started/middleware/function_based_middleware.py +++ b/python/samples/getting_started/middleware/function_based_middleware.py @@ -83,7 +83,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/middleware_termination.py b/python/samples/getting_started/middleware/middleware_termination.py index e13bcdd54a..7803b14ca5 100644 --- a/python/samples/getting_started/middleware/middleware_termination.py +++ b/python/samples/getting_started/middleware/middleware_termination.py @@ -110,7 +110,7 @@ async def pre_termination_middleware() -> None: print("\n--- Example 1: Pre-termination Middleware ---") async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=get_weather, @@ -137,7 +137,7 @@ async def post_termination_middleware() -> None: print("\n--- Example 2: Post-termination Middleware ---") async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/override_result_with_middleware.py b/python/samples/getting_started/middleware/override_result_with_middleware.py index cc7a349e0b..686dceea9e 100644 --- a/python/samples/getting_started/middleware/override_result_with_middleware.py +++ b/python/samples/getting_started/middleware/override_result_with_middleware.py @@ -83,7 +83,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="WeatherAgent", instructions="You are a helpful weather assistant. Use the weather tool to get current conditions.", tools=get_weather, diff --git a/python/samples/getting_started/middleware/shared_state_middleware.py b/python/samples/getting_started/middleware/shared_state_middleware.py index e4ce077038..066886f3b0 100644 --- a/python/samples/getting_started/middleware/shared_state_middleware.py +++ b/python/samples/getting_started/middleware/shared_state_middleware.py @@ -93,7 +93,7 @@ async def main() -> None: # authentication option. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="UtilityAgent", instructions="You are a helpful assistant that can provide weather information and current time.", tools=[get_weather, get_time], diff --git a/python/samples/getting_started/threads/suspend_resume_thread.py b/python/samples/getting_started/threads/suspend_resume_thread.py index 99880fe8ab..c2d612c2ef 100644 --- a/python/samples/getting_started/threads/suspend_resume_thread.py +++ b/python/samples/getting_started/threads/suspend_resume_thread.py @@ -22,7 +22,7 @@ async def suspend_resume_service_managed_thread() -> None: # AzureAIAgentClient supports service-managed threads. async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential).create_agent( + AzureAIAgentClient(credential=credential).create_agent( name="MemoryBot", instructions="You are a helpful assistant that remembers our conversation." ) as agent, ): diff --git a/python/samples/getting_started/workflows/agents/azure_ai_agents_streaming.py b/python/samples/getting_started/workflows/agents/azure_ai_agents_streaming.py index 12b4cda4c1..5c4e994b22 100644 --- a/python/samples/getting_started/workflows/agents/azure_ai_agents_streaming.py +++ b/python/samples/getting_started/workflows/agents/azure_ai_agents_streaming.py @@ -37,7 +37,7 @@ async def create_azure_ai_agent() -> tuple[Callable[..., Awaitable[Any]], Callab stack = AsyncExitStack() cred = await stack.enter_async_context(AzureCliCredential()) - client = await stack.enter_async_context(AzureAIAgentClient(async_credential=cred)) + client = await stack.enter_async_context(AzureAIAgentClient(credential=cred)) async def agent(**kwargs: Any) -> Any: return await stack.enter_async_context(client.create_agent(**kwargs)) @@ -67,12 +67,7 @@ async def main() -> None: ) # Build the workflow by adding agents directly as edges. # Agents adapt to workflow mode: run_stream() for incremental updates, run() for complete responses. - workflow = ( - WorkflowBuilder() - .set_start_executor(writer) - .add_edge(writer, reviewer) - .build() - ) + workflow = WorkflowBuilder().set_start_executor(writer).add_edge(writer, reviewer).build() last_executor_id: str | None = None diff --git a/python/samples/getting_started/workflows/agents/mixed_agents_and_executors.py b/python/samples/getting_started/workflows/agents/mixed_agents_and_executors.py index cb71ba72e6..5ec4b3e5fb 100644 --- a/python/samples/getting_started/workflows/agents/mixed_agents_and_executors.py +++ b/python/samples/getting_started/workflows/agents/mixed_agents_and_executors.py @@ -73,7 +73,7 @@ async def handle(self, message: AgentExecutorResponse, ctx: WorkflowContext[Neve async def main(): async with ( AzureCliCredential() as credential, - AzureAIAgentClient(async_credential=credential) as chat_client, + AzureAIAgentClient(credential=credential) as chat_client, ): # Create an agent with code interpretation capabilities agent = chat_client.create_agent( diff --git a/python/samples/semantic-kernel-migration/azure_ai_agent/01_basic_azure_ai_agent.py b/python/samples/semantic-kernel-migration/azure_ai_agent/01_basic_azure_ai_agent.py index c9b1fb50ee..3a776601e9 100644 --- a/python/samples/semantic-kernel-migration/azure_ai_agent/01_basic_azure_ai_agent.py +++ b/python/samples/semantic-kernel-migration/azure_ai_agent/01_basic_azure_ai_agent.py @@ -30,10 +30,13 @@ async def run_agent_framework() -> None: from agent_framework.azure import AzureAIAgentClient from azure.identity.aio import AzureCliCredential - async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent( - name="Support", - instructions="Answer customer questions in one paragraph.", - ) as agent: + async with ( + AzureCliCredential() as credential, + AzureAIAgentClient(credential=credential).create_agent( + name="Support", + instructions="Answer customer questions in one paragraph.", + ) as agent, + ): # AF client returns an asynchronous context manager for remote agents. reply = await agent.run("How do I upgrade my plan?") print("[AF]", reply.text) diff --git a/python/samples/semantic-kernel-migration/azure_ai_agent/02_azure_ai_agent_with_code_interpreter.py b/python/samples/semantic-kernel-migration/azure_ai_agent/02_azure_ai_agent_with_code_interpreter.py index 76cbb3e47b..526f9e1eab 100644 --- a/python/samples/semantic-kernel-migration/azure_ai_agent/02_azure_ai_agent_with_code_interpreter.py +++ b/python/samples/semantic-kernel-migration/azure_ai_agent/02_azure_ai_agent_with_code_interpreter.py @@ -33,11 +33,14 @@ async def run_agent_framework() -> None: from agent_framework.azure import AzureAIAgentClient, HostedCodeInterpreterTool from azure.identity.aio import AzureCliCredential - async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent( - name="Analyst", - instructions="Use the code interpreter for numeric work.", - tools=[HostedCodeInterpreterTool()], - ) as agent: + async with ( + AzureCliCredential() as credential, + AzureAIAgentClient(credential=credential).create_agent( + name="Analyst", + instructions="Use the code interpreter for numeric work.", + tools=[HostedCodeInterpreterTool()], + ) as agent, + ): # HostedCodeInterpreterTool mirrors the built-in Azure AI capability. reply = await agent.run( "Use Python to compute 42 ** 2 and explain the result.", diff --git a/python/samples/semantic-kernel-migration/azure_ai_agent/03_azure_ai_agent_threads_and_followups.py b/python/samples/semantic-kernel-migration/azure_ai_agent/03_azure_ai_agent_threads_and_followups.py index d96215d319..a5055fa5ee 100644 --- a/python/samples/semantic-kernel-migration/azure_ai_agent/03_azure_ai_agent_threads_and_followups.py +++ b/python/samples/semantic-kernel-migration/azure_ai_agent/03_azure_ai_agent_threads_and_followups.py @@ -36,10 +36,13 @@ async def run_agent_framework() -> None: from agent_framework.azure import AzureAIAgentClient from azure.identity.aio import AzureCliCredential - async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent( - name="Planner", - instructions="Track follow-up questions within the same thread.", - ) as agent: + async with ( + AzureCliCredential() as credential, + AzureAIAgentClient(credential=credential).create_agent( + name="Planner", + instructions="Track follow-up questions within the same thread.", + ) as agent, + ): thread = agent.get_new_thread() # AF threads are explicit and can be serialized for external storage. first = await agent.run("Outline the onboarding checklist.", thread=thread)