Add web search tool call content#7276
Merged
stephentoub merged 3 commits intodotnet:mainfrom Mar 5, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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, andWebSearchResulttoMicrosoft.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. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs
Show resolved
Hide resolved
jozkee
reviewed
Feb 9, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Show resolved
Hide resolved
a110624 to
f31d560
Compare
Member
Author
|
@jozkee please take another look, thanks |
f31d560 to
9fd7f2e
Compare
jozkee
reviewed
Mar 5, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientTests.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs
Show resolved
Hide resolved
- 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]>
rogerbarreto
reviewed
Mar 5, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Show resolved
Hide resolved
jozkee
approved these changes
Mar 5, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6057
Microsoft Reviewers: Open in CodeFlow