Fix approval request/response correlation in FunctionInvokingChatClient#7261
Fix approval request/response correlation in FunctionInvokingChatClient#7261stephentoub merged 7 commits intomainfrom
Conversation
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
…tent.Id for correlation Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Updated in commit 9034f0e. The dictionary now uses |
There was a problem hiding this comment.
Pull request overview
This PR fixes approval request/response correlation in FunctionInvokingChatClient so that reconstructed function call messages can reliably reuse the original request message metadata (e.g., MessageId) instead of falling back to synthetic identifiers.
Changes:
- Updated
FunctionInvokingChatClientapproval-response processing to look up the original approval request message byFunctionApprovalResponseContent.Id, matching the dictionary keyFunctionApprovalRequestContent.Id. - Added a focused regression test ensuring that, for both non-streaming and streaming flows, the reconstructed function call message preserves the original request message’s
MessageId.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientApprovalsTests.cs | Adds ApprovalResponsePreservesOriginalRequestMessageMetadata regression test verifying that approval processing preserves the original request message MessageId for both buffered and streaming paths. |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Adjusts approval response handling to correlate responses with their requests via the shared approval Id, ensuring the original request ChatMessage is recovered and its metadata reused. |
…nctionInvokingChatClientApprovalsTests.cs
...ies/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientApprovalsTests.cs
Outdated
Show resolved
Hide resolved
…nctionInvokingChatClientApprovalsTests.cs
Fix approval request/response correlation in FunctionInvokingChatClient
Summary
Fixed an inconsistency in how approval request messages are tracked vs looked up in
FunctionInvokingChatClient.Issue
FunctionApprovalRequestContent.IdapprovalResponse.FunctionCall.CallIdChanges Made
approvalResponse.FunctionCall.CallIdtoapprovalResponse.IdinExtractAndRemoveApprovalRequestsAndResponsesmethodFunctionApprovalRequestContent.Idfor storing approval request messagesApprovalResponsePreservesOriginalRequestMessageMetadatathat validates the fixTest Results
✅ All tests passing:
Original prompt
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Microsoft Reviewers: Open in CodeFlow