ToChatResponse: Merge AdditionalProperties into ChatMessage instead of ChatResponse#7194
Conversation
…instead of ChatResponse Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where AdditionalProperties from ChatResponseUpdate objects were incorrectly being merged into the top-level ChatResponse.AdditionalProperties instead of the individual ChatMessage.AdditionalProperties. This caused properties from different messages to collide when they had the same keys.
Key Changes:
- Moved
AdditionalPropertiesmerging logic fromChatResponselevel toChatMessagelevel inProcessUpdatemethod - Updated existing test expectations to reflect that properties now belong to messages
- Added comprehensive new test to verify properties are correctly isolated per message
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs |
Relocated the AdditionalProperties merging logic (lines 538-548) to apply to message instead of response, enabling per-message property isolation |
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs |
Updated existing test to expect AdditionalProperties on messages (lines 60-65) and added new test ToChatResponse_AdditionalPropertiesGoToMessages (lines 449-496) to verify the corrected behavior with multiple messages |
|
@copilot, there's a test failure, e.g. |
…sent Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Head branch was pushed to by a user without write access
Fixed in 04ddd18. The issue was that my initial change unconditionally moved |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs
Show resolved
Hide resolved
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
cc: @westey-m |
ToChatResponse{Async}should mergeChatResponseUpdate.AdditionalPropertiesinto the correspondingChatMessage.AdditionalPropertiesrather thanChatResponse.AdditionalPropertiesProcessUpdatemethod inChatResponseExtensions.csto addAdditionalPropertiesbased on MessageId presenceChatResponseUpdateExtensionsTests.csto expect the new behaviorToChatResponse_AdditionalPropertiesGoToMessagesto verify the correct behaviorToChatResponse_AdditionalPropertiesRoutingBasedOnMessageIdfor MessageId-based routingSummary
This PR updates
ToChatResponseandToChatResponseAsyncmethods to useMessageIdas the discriminator for routingAdditionalProperties:Routing logic:
MessageId→AdditionalPropertiesgo tomessage.AdditionalProperties(message-scoped)MessageId→AdditionalPropertiesgo toresponse.AdditionalProperties(response-scoped)Benefits:
MessageIdsystem_fingerprint) is preserved correctly for telemetryMessageIdOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Microsoft Reviewers: Open in CodeFlow