Skip to content

Python: Fix web_search_options sent to Azure OpenAI Chat Completions API (issue #3629)#6225

Open
Oxygen56 wants to merge 3 commits into
microsoft:mainfrom
Oxygen56:fix/azure-web-search-options
Open

Python: Fix web_search_options sent to Azure OpenAI Chat Completions API (issue #3629)#6225
Oxygen56 wants to merge 3 commits into
microsoft:mainfrom
Oxygen56:fix/azure-web-search-options

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented May 31, 2026

Summary

Azure OpenAI Chat Completions API does not support the web_search_options parameter. Sending it results in a 400 error:

{'error': {'message': "Unknown parameter: 'web_search_options'."}}

This PR fixes the issue by storing the Azure client flag and skipping web search tools when configured with Azure OpenAI.

Changes

  1. Store _use_azure_client flag in RawOpenAIChatCompletionClient.__init__ so downstream methods can check whether the client is Azure-based
  2. Skip web search for Azure in _prepare_tools_for_openai: when the client is Azure-based, web search tools are silently excluded with a warning guiding users to use OpenAIChatClient (Responses API) instead

Before

client = OpenAIChatCompletionClient(azure_endpoint="...", api_key="...", model="gpt-4o-mini")
tool = OpenAIChatCompletionClient.get_web_search_tool()
agent = Agent(client=client, tools=[tool])
await agent.run("Weather?")
# -> ServiceResponseException: Unknown parameter: 'web_search_options'

After

client = OpenAIChatCompletionClient(azure_endpoint="...", api_key="...", model="gpt-4o-mini")
tool = OpenAIChatCompletionClient.get_web_search_tool()
agent = Agent(client=client, tools=[tool])
await agent.run("Weather?")
# -> Warning logged: Web search not supported by Azure OpenAI Chat Completions
# -> Agent runs without web search, no error

Alternatives

For web search on Azure, use the Responses API via OpenAIChatClient:

from agent_framework.openai import OpenAIChatClient
client = OpenAIChatClient(azure_endpoint="...", credential=AzureCliCredential())

Fixes #3629

Copilot AI review requested due to automatic review settings May 31, 2026 17:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Azure-specific handling for web search tools in the Chat Completions client, preventing unsupported parameters from being sent when using an Azure endpoint.

Changes:

  • Persist use_azure_client configuration on the instance for later branching.
  • Update tool preparation to ignore web_search tools when configured for Azure, and log a warning.
  • Add a docstring note describing Azure Chat Completions limitations around web search.

Comment thread python/packages/openai/agent_framework_openai/_chat_completion_client.py Outdated
@Oxygen56
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/openai/agent_framework_openai
   _chat_completion_client.py3662593%432, 528–529, 533, 778–785, 787–790, 878, 880, 897, 918, 946, 959, 983, 1003, 1318
TOTAL37396435088% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7453 34 💤 0 ❌ 0 🔥 1m 54s ⏱️

@Oxygen56 Oxygen56 requested a review from Copilot June 2, 2026 14:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread python/packages/openai/agent_framework_openai/_chat_completion_client.py Outdated
@Oxygen56 Oxygen56 force-pushed the fix/azure-web-search-options branch from 7e71818 to af5076b Compare June 2, 2026 14:38
@Oxygen56
Copy link
Copy Markdown
Author

Oxygen56 commented Jun 2, 2026

Addressed Copilot review feedback:

  1. Centralized error message — extracted _AZURE_WEB_SEARCH_UNSUPPORTED_MSG as a module-level constant in _chat_completion_client.py
  2. Test uses shared constanttest_openai_chat_completion_client.py now imports and matches against the same constant
  3. Docstring — already correct (says "raises ValueError" which matches the current implementation)
  4. ✅ Commit author fixed to Oxygen56 <1391083091@qq.com>

Ready for re-review.

@Oxygen56 Oxygen56 force-pushed the fix/azure-web-search-options branch from af5076b to 8b0759f Compare June 2, 2026 14:44
Azure OpenAI Chat Completions API does not support the web_search_options
parameter. Sending it results in a 400 error: 'Unknown parameter:
web_search_options'.

This fix:
- Stores the use_azure_client flag during initialization
- In _prepare_tools_for_openai, skips web search tools when the client
  is Azure-based, logging a warning that guides users to the Responses
  API (OpenAIChatClient) for web search support on Azure

Closes microsoft#3629

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Oxygen56 Oxygen56 force-pushed the fix/azure-web-search-options branch from 8b0759f to b3cc4e4 Compare June 2, 2026 14:45
Address review feedback: silent logger.warning was too easy to miss.
Raising ValueError ensures callers know immediately that web search is
incompatible with Azure Chat Completions and directs them to the
Responses API alternative.

- Changed logger.warning to ValueError in _prepare_tools_for_openai
- Added test_prepare_tools_with_web_search_on_azure_raises
- Added test_prepare_tools_with_web_search_on_openai_allowed
@Oxygen56 Oxygen56 force-pushed the fix/azure-web-search-options branch from b3cc4e4 to 3dbe723 Compare June 2, 2026 14:46
@Oxygen56
Copy link
Copy Markdown
Author

Oxygen56 commented Jun 2, 2026

Thanks for the review approval @eavanvalkenburg!

It looks like the CI workflows need manual approval to run on this fork PR — all 6 critical checks (Python tests, code quality, merge gatekeeper, etc.) are stuck in action_required. Could you approve the workflow runs when you get a chance?

The CI run page should be here: https://github.com/microsoft/agent-framework/actions?query=branch%3Afix%2Fazure-web-search-options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: HostedWebSearchTool failed with AzureOpenAIChatClient

4 participants