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 93bd445e28..b361bd9ac8 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 @@ -14,11 +14,23 @@ Prerequisites: 1. Set AZURE_AI_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME environment variables. 2. Ensure you have an A2A connection configured in your Azure AI project - and set A2A_PROJECT_CONNECTION_ID environment variable. + and set A2A_PROJECT_CONNECTION_ID environment variable. +3. (Optional) A2A_ENDPOINT - If the connection is missing target (e.g., "Custom keys" type), + set the A2A endpoint URL directly. """ async def main() -> None: + # Configure A2A tool with connection ID + a2a_tool = { + "type": "a2a_preview", + "project_connection_id": os.environ["A2A_PROJECT_CONNECTION_ID"], + } + + # If the connection is missing a target, we need to set the A2A endpoint URL + if os.environ.get("A2A_ENDPOINT"): + a2a_tool["base_url"] = os.environ["A2A_ENDPOINT"] + async with ( AzureCliCredential() as credential, AzureAIClient(credential=credential).create_agent( @@ -26,10 +38,7 @@ async def main() -> None: 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 or gather information from specialized agents.""", - tools={ - "type": "a2a_preview", - "project_connection_id": os.environ["A2A_PROJECT_CONNECTION_ID"], - }, + tools=a2a_tool, ) as agent, ): query = "What can the secondary agent do?"