Conversation
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
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Show resolved
Hide resolved
a110624 to
f31d560
Compare
|
@jozkee please take another look, thanks |
f31d560 to
9fd7f2e
Compare
| break; | ||
|
|
||
| case WebSearchCallResponseItem wscri: | ||
| _ = wscri.Patch.TryGetValue("$.action.query"u8, out string? wsQuery); |
There was a problem hiding this comment.
Query shows as [DEPRECATED] in OpenAI docs and there's also queries. Should we lookup that patch field too?
| } | ||
|
|
||
| [Fact] | ||
| public async Task UnavailableBuiltInFunctionCall_NonStreaming() |
There was a problem hiding this comment.
| public async Task HostedWebSearchTool_MapsToWebSearchOptions_NonStreaming() |
| // Fifth update: WebSearchCallResponseItem -> ToolCallContent + ToolResultContent | ||
| ToolCallContent? wsToolCall = updates[4].Contents.OfType<ToolCallContent>().FirstOrDefault(); | ||
| // Fifth update: WebSearchCallResponseItem -> WebSearchToolCallContent | ||
| WebSearchToolCallContent? wsToolCall = updates[4].Contents.OfType<WebSearchToolCallContent>().FirstOrDefault(); |
There was a problem hiding this comment.
Also update AsChatMessages_FromResponseItems_AllContentTypes_SetsRawRepresentation.
| #pragma warning disable OPENAI001 // WebSearchOptions is experimental | ||
| result.WebSearchOptions ??= new(); | ||
| #pragma warning restore OPENAI001 | ||
| break; |
There was a problem hiding this comment.
Do we need to return the websearch contents in FromOpenAIChatCompletion?
Closes #6057
Microsoft Reviewers: Open in CodeFlow