From fbd8eb51bfdc7885c1c8735877fb9111a4dd1587 Mon Sep 17 00:00:00 2001 From: max-montes <77820353+max-montes@users.noreply.github.com> Date: Wed, 4 Mar 2026 12:51:28 -0800 Subject: [PATCH] Raise NotImplementedError for get_web_search_tool() on AzureOpenAIChatClient Azure OpenAI's Chat Completions API does not support the web_search_options parameter. Previously, calling get_web_search_tool() on AzureOpenAIChatClient inherited the base OpenAI implementation, producing a config that caused a 400 error at runtime. Now raises NotImplementedError at tool creation time with a message directing users to OpenAIChatClient or AzureOpenAIResponsesClient. Fixes #3629 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../core/agent_framework/azure/_chat_client.py | 17 +++++++++++++++++ .../core/tests/azure/test_azure_chat_client.py | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/python/packages/core/agent_framework/azure/_chat_client.py b/python/packages/core/agent_framework/azure/_chat_client.py index b4bd3659ed..f07254b489 100644 --- a/python/packages/core/agent_framework/azure/_chat_client.py +++ b/python/packages/core/agent_framework/azure/_chat_client.py @@ -282,6 +282,23 @@ class MyOptions(AzureOpenAIChatOptions, total=False): **kwargs, ) + @staticmethod + def get_web_search_tool( + *, + web_search_options: Any | None = None, + ) -> dict[str, Any]: + """Web search is not supported by Azure OpenAI's Chat Completions API. + + Use ``OpenAIChatClient`` or ``AzureOpenAIResponsesClient`` for web search support. + + Raises: + NotImplementedError: Always, since Azure OpenAI does not support web search. + """ + raise NotImplementedError( + "Web search is not supported by Azure OpenAI's Chat Completions API. " + "Use OpenAIChatClient or AzureOpenAIResponsesClient for web search support." + ) + @override def _parse_text_from_openai(self, choice: Choice | ChunkChoice) -> Content | None: """Parse the choice into a Content object with type='text'. diff --git a/python/packages/core/tests/azure/test_azure_chat_client.py b/python/packages/core/tests/azure/test_azure_chat_client.py index 3e88504493..aa1828f54d 100644 --- a/python/packages/core/tests/azure/test_azure_chat_client.py +++ b/python/packages/core/tests/azure/test_azure_chat_client.py @@ -884,3 +884,12 @@ async def test_azure_chat_client_agent_level_tool_persistence(): assert second_response.text is not None # Should use the agent-level weather tool again assert any(term in second_response.text.lower() for term in ["miami", "sunny", "72"]) + + +def test_get_web_search_tool_raises_not_implemented() -> None: + """Test that get_web_search_tool() raises NotImplementedError on Azure OpenAI. + + Regression test for: https://github.com/microsoft/agent-framework/issues/3629 + """ + with pytest.raises(NotImplementedError, match="not supported by Azure OpenAI"): + AzureOpenAIChatClient.get_web_search_tool()