Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Oct 10, 2025

Originally we were only factoring in Role. Then we also augmented it to factor in MessageId, since updates from different messages are by definition not part of the same message. Now it also makes sense to factor in AuthorName, as different text from different speakers / agents are also by definition not part of the same message.

Microsoft Reviewers: Open in CodeFlow

Originally we were only factoring in Role. Then we also augmented it to factor in MessageId, since updates from different messages are by definition not part of the same message. Now it also makes sense to factor in AuthorName, as different text from different speakers / agents are also by definition not part of the same message.
@stephentoub stephentoub requested a review from a team as a code owner October 10, 2025 04:03
@stephentoub stephentoub requested review from Copilot and removed request for a team October 10, 2025 04:03
@stephentoub
Copy link
Member Author

cc: @westey-m

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 10, 2025
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 updates the ToChatResponse and ToChatResponseAsync methods to include AuthorName as an additional boundary condition for determining when to create new chat messages from streaming updates. Previously, the methods only considered Role and MessageId changes as triggers for new message boundaries. Now, changes in AuthorName will also dictate message boundaries, ensuring that text from different speakers/agents are properly separated into distinct messages.

Key changes:

  • Enhanced boundary detection logic to include AuthorName comparison alongside existing Role and MessageId checks
  • Comprehensive test coverage for various AuthorName boundary scenarios
  • Updated existing tests to reflect the new behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs Refactored message boundary detection logic to include AuthorName comparison and added helper methods for clean boundary checking
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs Added extensive test coverage for AuthorName boundary scenarios and updated existing tests to accommodate the new behavior

@stephentoub stephentoub enabled auto-merge (squash) October 10, 2025 12:10
@stephentoub stephentoub merged commit 3d0419c into dotnet:main Oct 10, 2025
6 checks passed
@stephentoub stephentoub deleted the authorsplit branch October 10, 2025 22:38
joperezr pushed a commit to joperezr/extensions that referenced this pull request Oct 14, 2025
* Update ToChatResponse{Async} to also factor in AuthorName

Originally we were only factoring in Role. Then we also augmented it to factor in MessageId, since updates from different messages are by definition not part of the same message. Now it also makes sense to factor in AuthorName, as different text from different speakers / agents are also by definition not part of the same message.

* Fix useAsync inversion in tests
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
* Update ToChatResponse{Async} to also factor in AuthorName

Originally we were only factoring in Role. Then we also augmented it to factor in MessageId, since updates from different messages are by definition not part of the same message. Now it also makes sense to factor in AuthorName, as different text from different speakers / agents are also by definition not part of the same message.

* Fix useAsync inversion in tests
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
* Update ToChatResponse{Async} to also factor in AuthorName

Originally we were only factoring in Role. Then we also augmented it to factor in MessageId, since updates from different messages are by definition not part of the same message. Now it also makes sense to factor in AuthorName, as different text from different speakers / agents are also by definition not part of the same message.

* Fix useAsync inversion in tests
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants