Repository navigation
Prevent invoking functions when call has recorded argument exception (#7799) - #7902
Open
Manish-1kumar wants to merge 1 commit into
Open
Manish-1kumar wants to merge 1 commit into
Manish-1kumar wants to merge 1 commit into
Conversation
Guard against invoking functions when FunctionCallContent.Exception is not null in FunctionInvokingChatClient and FunctionInvokingRealtimeClientSession. Returns a failed result rather than attempting invocation with default arguments. Fixes dotnet#7799
Collaborator
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1658607&view=codecoverage-tab |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves #7799.
When an inner chat client encounters an argument parsing error (e.g. malformed JSON returned by the model), it sets
callContent.Arguments = nulland records the failure incallContent.Exception.Previously,
FunctionInvokingChatClientandFunctionInvokingRealtimeClientSessiondid not inspectcontext.CallContent.Exceptionbefore attempting invocation. If the targetAIFunctionhad parameterless or optional parameters (e.g.(string opt = "default") => ...), the parameter binder succeeded using default argument values and executed the function with unintended inputs, returning a false success (RanToCompletion) back to the model.This change:
context.CallContent.ExceptioninInvokeFunctionAsyncin bothFunctionInvokingChatClientandFunctionInvokingRealtimeClientSession.ValueTaskholding that exception without executing the underlying function.FunctionResultContentwith the exception attached and updating consecutive error counts.FunctionInvokingChatClientTestsverifying both sync and streaming execution for functions with optional parameters whencallContent.Exceptionis present.Customer Impact
Functions are protected against unintended execution with default parameter values when the model supplies invalid or corrupt arguments. The model receives an explicit tool error response, enabling it to recover.
Regression / Compatibility Analysis
net10.0,net9.0,net8.0,net472).Microsoft Reviewers: Open in CodeFlow