Ensure all ResponseItems are yielded in AIContent#7063
Merged
stephentoub merged 2 commits intodotnet:mainfrom Nov 22, 2025
Merged
Ensure all ResponseItems are yielded in AIContent#7063stephentoub merged 2 commits intodotnet:mainfrom
stephentoub merged 2 commits intodotnet:mainfrom
Conversation
Contributor
Author
@dotnet-policy-service agree company="Microsoft" |
stephentoub
reviewed
Nov 21, 2025
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a generic fallback handler for streaming response items that don't have dedicated AIContent abstractions, addressing the issue where certain streaming updates would result in empty ChatMessage objects. The solution introduces a HashSet to track types with explicit handlers and provides a catch-all case to wrap unhandled items in AIContent with RawRepresentation.
Key changes:
- Adds
_responseItemTypesWithHandlersHashSet to track response item types with dedicated handlers - Removes the specific case for
McpToolDefinitionListItem(line 419-422) - Adds a generic handler for
StreamingResponseOutputItemDoneUpdatethat createsAIContentwithRawRepresentationfor types not explicitly handled elsewhere
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
approved these changes
Nov 22, 2025
This was referenced Dec 11, 2025
This was referenced Dec 18, 2025
Closed
Closed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Enable the following logic to handle cases for processing streaming updates without an AIContent abstraction (
RawRepresentationonly):In the absence of this additional logic, the following conversion results in an empty
ChatMessage:-https://github.com/dotnet/extensions/blob/main/src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs#L485
Microsoft Reviewers: Open in CodeFlow