diff --git a/python/samples/getting_started/agents/azure_openai/azure_responses_client_with_local_mcp.py b/python/samples/getting_started/agents/azure_openai/azure_responses_client_with_local_mcp.py index 8999fab566..3726263719 100644 --- a/python/samples/getting_started/agents/azure_openai/azure_responses_client_with_local_mcp.py +++ b/python/samples/getting_started/agents/azure_openai/azure_responses_client_with_local_mcp.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft. All rights reserved. -import os import asyncio +import os from agent_framework import ChatAgent, MCPStreamableHTTPTool from agent_framework.azure import AzureOpenAIResponsesClient @@ -18,13 +18,14 @@ # --- Below code uses Microsoft Learn MCP server over Streamable HTTP --- # --- Users can set these environment variables, or just edit the values below to their desired local MCP server MCP_NAME = os.environ.get("MCP_NAME", "Microsoft Learn MCP") # example name -MCP_URL = os.environ.get("MCP_URL", "https://learn.microsoft.com/api/mcp") # example endpoint +MCP_URL = os.environ.get("MCP_URL", "https://learn.microsoft.com/api/mcp") # example endpoint # Environment variables for Azure OpenAI Responses authentication # AZURE_OPENAI_ENDPOINT="" # AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="" # AZURE_OPENAI_API_VERSION="" # e.g. "2025-03-01-preview" + async def main(): """Example showing local MCP tools for a Azure OpenAI Responses Agent.""" # AuthN: use Azure CLI @@ -38,16 +39,13 @@ async def main(): agent: ChatAgent = responses_client.create_agent( name="DocsAgent", - instructions=( - "You are a helpful assistant that can help with Microsoft documentation questions." - ), + instructions=("You are a helpful assistant that can help with Microsoft documentation questions."), ) # Connect to the MCP server (Streamable HTTP) async with MCPStreamableHTTPTool( name=MCP_NAME, url=MCP_URL, - ) as mcp_tool: # First query — expect the agent to use the MCP tool if it helps q1 = "How to create an Azure storage account using az cli?" diff --git a/python/samples/getting_started/agents/openai/openai_chat_client_with_web_search.py b/python/samples/getting_started/agents/openai/openai_chat_client_with_web_search.py index c5859297bf..c317e163ad 100644 --- a/python/samples/getting_started/agents/openai/openai_chat_client_with_web_search.py +++ b/python/samples/getting_started/agents/openai/openai_chat_client_with_web_search.py @@ -2,7 +2,7 @@ import asyncio -from agent_framework import HostedWebSearchTool +from agent_framework import ChatAgent, HostedWebSearchTool from agent_framework.openai import OpenAIChatClient """ @@ -14,34 +14,32 @@ async def main() -> None: - client = OpenAIChatClient(model_id="gpt-4o-search-preview") - - message = "What is the current weather? Do not ask for my current location." - # Test that the client will use the web search tool with location + # Test that the agent will use the web search tool with location additional_properties = { "user_location": { "country": "US", "city": "Seattle", } } + + agent = ChatAgent( + chat_client=OpenAIChatClient(model_id="gpt-4o-search-preview"), + instructions="You are a helpful assistant that can search the web for current information.", + tools=[HostedWebSearchTool(additional_properties=additional_properties)], + ) + + message = "What is the current weather? Do not ask for my current location." stream = False print(f"User: {message}") + if stream: print("Assistant: ", end="") - async for chunk in client.get_streaming_response( - message, - tools=[HostedWebSearchTool(additional_properties=additional_properties)], - tool_choice="auto", - ): + async for chunk in agent.run_stream(message): if chunk.text: print(chunk.text, end="") print("") else: - response = await client.get_response( - message, - tools=[HostedWebSearchTool(additional_properties=additional_properties)], - tool_choice="auto", - ) + response = await agent.run(message) print(f"Assistant: {response}") diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_with_file_search.py b/python/samples/getting_started/agents/openai/openai_responses_client_with_file_search.py index 097fa28fee..3bac4d2cab 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_with_file_search.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_with_file_search.py @@ -2,7 +2,7 @@ import asyncio -from agent_framework import HostedFileSearchTool, HostedVectorStoreContent +from agent_framework import ChatAgent, HostedFileSearchTool, HostedVectorStoreContent from agent_framework.openai import OpenAIResponsesClient """ @@ -46,22 +46,21 @@ async def main() -> None: stream = False print(f"User: {message}") file_id, vector_store = await create_vector_store(client) + + agent = ChatAgent( + chat_client=client, + instructions="You are a helpful assistant that can search through files to find information.", + tools=[HostedFileSearchTool(inputs=vector_store)], + ) + if stream: print("Assistant: ", end="") - async for chunk in client.get_streaming_response( - message, - tools=[HostedFileSearchTool(inputs=vector_store)], - tool_choice="auto", - ): + async for chunk in agent.run_stream(message): if chunk.text: print(chunk.text, end="") print("") else: - response = await client.get_response( - message, - tools=[HostedFileSearchTool(inputs=vector_store)], - tool_choice="auto", - ) + response = await agent.run(message) print(f"Assistant: {response}") await delete_vector_store(client, file_id, vector_store.vector_store_id) diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_with_web_search.py b/python/samples/getting_started/agents/openai/openai_responses_client_with_web_search.py index f9f0141cc4..03ee48015f 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_with_web_search.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_with_web_search.py @@ -2,7 +2,7 @@ import asyncio -from agent_framework import HostedWebSearchTool +from agent_framework import ChatAgent, HostedWebSearchTool from agent_framework.openai import OpenAIResponsesClient """ @@ -14,34 +14,32 @@ async def main() -> None: - client = OpenAIResponsesClient() - - message = "What is the current weather? Do not ask for my current location." - # Test that the client will use the web search tool with location + # Test that the agent will use the web search tool with location additional_properties = { "user_location": { "country": "US", "city": "Seattle", } } + + agent = ChatAgent( + chat_client=OpenAIResponsesClient(), + instructions="You are a helpful assistant that can search the web for current information.", + tools=[HostedWebSearchTool(additional_properties=additional_properties)], + ) + + message = "What is the current weather? Do not ask for my current location." stream = False print(f"User: {message}") + if stream: print("Assistant: ", end="") - async for chunk in client.get_streaming_response( - message, - tools=[HostedWebSearchTool(additional_properties=additional_properties)], - tool_choice="auto", - ): + async for chunk in agent.run_stream(message): if chunk.text: print(chunk.text, end="") print("") else: - response = await client.get_response( - message, - tools=[HostedWebSearchTool(additional_properties=additional_properties)], - tool_choice="auto", - ) + response = await agent.run(message) print(f"Assistant: {response}")