Skip to content

Add web search tool call content#7276

Merged
stephentoub merged 3 commits intodotnet:mainfrom
stephentoub:websearchcontent
Mar 5, 2026
Merged

Add web search tool call content#7276
stephentoub merged 3 commits intodotnet:mainfrom
stephentoub:websearchcontent

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Feb 8, 2026

Closes #6057

Microsoft Reviewers: Open in CodeFlow

Copy link
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

This PR standardizes “web search tool” interactions in the AI abstractions layer by introducing new AIContent-derived types for web search tool calls/results, wiring them into OpenAI client adapters (Responses + Chat Completions), and ensuring they roundtrip through the shared JSON serialization pipeline.

Changes:

  • Added WebSearchToolCallContent, WebSearchToolResultContent, and WebSearchResult to Microsoft.Extensions.AI.Abstractions, including experimental attribution and JSON polymorphic registration.
  • Updated OpenAI adapters to emit web search tool call/result content (non-streaming + streaming) and to enable web search via chat completion options.
  • Added/updated unit and integration tests covering serialization and streaming coalescing behavior.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs Adds non-streaming + streaming tests validating web search tool call/result content emission and coalescing.
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs Extends integration test to assert web search call/result content presence alongside citations.
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientTests.cs Updates expected request payload to include web_search_options when HostedWebSearchTool is supplied.
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/WebSearchToolResultContentTests.cs New unit tests for WebSearchToolResultContent defaults, property roundtrips, and JSON roundtrips.
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/WebSearchToolCallContentTests.cs New unit tests for WebSearchToolCallContent defaults, property roundtrips, and JSON roundtrips.
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/WebSearchResultTests.cs New unit tests for WebSearchResult property and JSON roundtrips.
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs Adds tests ensuring web search tool call content coalesces correctly across updates.
src/Shared/DiagnosticIds/DiagnosticIds.cs Introduces AIWebSearch experiment constant for [Experimental] attribution.
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Maps OpenAI Responses web search items/updates into new web search tool call/result content types.
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs Enables web_search_options when HostedWebSearchTool is present in ChatOptions.Tools.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs Registers new web search content types for polymorphic JSON + source gen context.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/WebSearchToolResultContent.cs Adds new AIContent-derived type for web search tool results.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/WebSearchToolCallContent.cs Adds new AIContent-derived type for web search tool calls.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/WebSearchResult.cs Adds new model type representing an individual web search result.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIContent.cs Documents (commented) future [JsonDerivedType] entries for the new experimental types.
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs Adds coalescing logic for WebSearchToolCallContent based on CallId.

@stephentoub
Copy link
Member Author

@jozkee please take another look, thanks
@rogerbarreto any feedback?

- Read both 'queries' (array) and deprecated 'query' (string) from
  WebSearchCallResponseItem patch, preferring the array form
- Rename test to HostedWebSearchTool_MapsToWebSearchOptions_NonStreaming
- Update AllContentTypes test to assert WebSearchToolCallContent/
  WebSearchToolResultContent instead of base types
- Add comment clarifying Chat Completions API surfaces web search
  results via annotations, not tool call items
- Add tests for queries extraction: array preferred, fallback to
  deprecated field, and neither field present

Co-authored-by: Copilot <[email protected]>
@stephentoub stephentoub requested a review from jozkee March 5, 2026 14:25
@stephentoub stephentoub enabled auto-merge (squash) March 5, 2026 14:25
@stephentoub stephentoub merged commit f85ef9c into dotnet:main Mar 5, 2026
6 checks passed
@stephentoub stephentoub deleted the websearchcontent branch March 5, 2026 15:51
stephentoub added a commit to stephentoub/extensions that referenced this pull request Mar 6, 2026
* Add web search tool call content

* Address PR feedback and adapt to recent changes

* Address PR review feedback for web search tool call content

- Read both 'queries' (array) and deprecated 'query' (string) from
  WebSearchCallResponseItem patch, preferring the array form
- Rename test to HostedWebSearchTool_MapsToWebSearchOptions_NonStreaming
- Update AllContentTypes test to assert WebSearchToolCallContent/
  WebSearchToolResultContent instead of base types
- Add comment clarifying Chat Completions API surfaces web search
  results via annotations, not tool call items
- Add tests for queries extraction: array preferred, fallback to
  deprecated field, and neither field present

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize several additional forms of content

4 participants