-
Notifications
You must be signed in to change notification settings - Fork 851
Allow FunctionResultContent pass-through when CallId matches #7229
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
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
@copilot also unseal FunctionCallContent and FunctionResultContent and add tests validating that an AIFunction can return a FunctionResultContent-derived type and that instance is what's propagated to the IChatClient wrapped by the FunctionInvokingChatClient. |
…e propagation test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…nt test Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Done in 790f979. Unsealed both |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Show resolved
Hide resolved
…ount Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
jozkee
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.
Otherwise, LGTM.
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
…onResultContent tests Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
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 updates FunctionInvokingChatClient so that it can re-use FunctionResultContent instances returned directly from functions when the CallId matches, enabling more flexible and customized function result handling. It also unseals FunctionCallContent and FunctionResultContent to allow derivation and adds tests and API baseline updates to validate and document the new behavior.
Changes:
- Update
FunctionInvokingChatClient.CreateResponseMessages(viaCreateFunctionResultContent) to short-circuit and return an existingFunctionResultContentwhen the function result is already aFunctionResultContentwith a matchingCallId. - Unseal
FunctionCallContentandFunctionResultContentto support derived content types, and update the AI abstractions API baseline accordingly. - Add unit tests covering matching/mismatched
CallIdbehavior and propagation of a derivedFunctionResultContenttype through the innerIChatClient, including ensuring only a singleFunctionResultContentis present in the tool message.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs |
Adds a conditional path in CreateFunctionResultContent to re-use an existing FunctionResultContent instance when the CallId matches, otherwise preserving the existing wrapping logic. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs |
Removes sealed from FunctionCallContent to allow inheritance while keeping existing behavior and API intact. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionResultContent.cs |
Removes sealed from FunctionResultContent so it can be subclassed (e.g., to add custom properties) without changing its current public API surface. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json |
Updates the API baseline to reflect that FunctionCallContent and FunctionResultContent are now unsealed classes. |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs |
Adds tests verifying pass-through of matching FunctionResultContent, wrapping on mismatched CallId, and correct propagation of a derived FunctionResultContent to the inner client with only one tool result message. |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
FunctionInvokingChatClient.CreateResponseMessagesshould reuseFunctionResultContentreturned by the function if theCallIdmatchesFunctionInvokingChatClient.csat line 1230FunctionCallContentandFunctionResultContentclassesFunctionResultContenttype is propagated to the innerIChatClientSummary
This PR modifies
FunctionInvokingChatClient.CreateResponseMessagesto check if the function result is already aFunctionResultContentwith a matchingCallId. If so, it uses that instance directly instead of wrapping it in a newFunctionResultContent. This gives the AIFunction flexibility to create its own FunctionResultContent configured however it wants.Additionally, this PR unseals
FunctionCallContentandFunctionResultContentclasses to allow derivation.Changes:
FunctionInvokingChatClient.CreateFunctionResultContentmethod to check if the result is aFunctionResultContentwith a matchingCallIdand return it directlyFunctionCallContentandFunctionResultContentclasses to allow derivationFunctionReturningFunctionResultContentWithMatchingCallId_UsesItDirectly: Verifies that when a function returns a FunctionResultContent with matching CallId, it is used directly (same reference)FunctionReturningFunctionResultContentWithMismatchedCallId_WrapsIt: Verifies that when a function returns a FunctionResultContent with mismatched CallId, it is wrapped in a new FunctionResultContent (with the inner one reference-equal)FunctionReturningDerivedFunctionResultContent_PropagatesInstanceToInnerClient: Verifies that a derived FunctionResultContent type is properly propagated to the wrapped IChatClient and is the only one in the tool message (same reference)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Microsoft Reviewers: Open in CodeFlow