-
Notifications
You must be signed in to change notification settings - Fork 849
Fix FunctionApprovalResponseContent to message mapping #7152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 fixes a bug in the FunctionInvokingChatClient where FunctionApprovalResponseContent items from messages with null MessageId were incorrectly split into separate FunctionCallContent messages instead of being grouped together. The issue stemmed from inconsistent dictionary key usage when tracking messages during the conversion process.
Key Changes:
- Added regression test to verify correct grouping behavior when MessageId is null
- Fixed dictionary key mismatch by using RequestMessage.MessageId consistently for lookup and storage
- Added logic to handle fallback MessageId substitution when seeding the dictionary
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientApprovalsTests.cs | Adds comprehensive regression test with detailed documentation explaining the null MessageId grouping bug and expected behavior |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Fixes dictionary key inconsistency by computing effective keys that account for fallback MessageId substitution and using RequestMessage.MessageId consistently |
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Show resolved
Hide resolved
|
@dotnet-policy-service agree |
|
Fixes #7153 |
stephentoub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fix.
...ies/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientApprovalsTests.cs
Outdated
Show resolved
Hide resolved
…nctionInvokingChatClientApprovalsTests.cs
When FunctionApprovalResponseContent items from the same original message (with MessageId = null) are processed, they incorrectly get split into separate FunctionCallContent messages instead of being grouped together.
Root Cause: Key mismatch in ConvertToFunctionCallContentMessages:
Fix (2 changes in FunctionInvokingChatClient.cs):
This ensures all approvals from the same original message (whether MessageId is set or null) get properly grouped into a single FunctionCallContent message.
Microsoft Reviewers: Open in CodeFlow