-
Notifications
You must be signed in to change notification settings - Fork 863
Fix: Mark both TARC and TAResp FunctionCallContent as InformationalOnly after approval processing #7468
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
Open
westey-m
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
westey-m:ficc-informationonly-set
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−9
Open
Fix: Mark both TARC and TAResp FunctionCallContent as InformationalOnly after approval processing #7468
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1349,7 +1349,7 @@ FunctionResultContent CreateFunctionResultContent(FunctionInvocationResult resul | |||||||||||
| private (List<ApprovalResultWithRequestMessage>? approvals, List<ApprovalResultWithRequestMessage>? rejections) ExtractAndRemoveApprovalRequestsAndResponses( | ||||||||||||
| List<ChatMessage> messages) | ||||||||||||
| { | ||||||||||||
| Dictionary<string, ChatMessage>? allApprovalRequestsMessages = null; | ||||||||||||
| Dictionary<string, (ChatMessage Message, ToolApprovalRequestContent RequestContent)>? allApprovalRequestsMessages = null; | ||||||||||||
| List<ToolApprovalResponseContent>? allApprovalResponses = null; | ||||||||||||
| HashSet<string>? approvalRequestCallIds = null; | ||||||||||||
| HashSet<string>? functionResultCallIds = null; | ||||||||||||
|
|
@@ -1376,7 +1376,7 @@ FunctionResultContent CreateFunctionResultContent(FunctionInvocationResult resul | |||||||||||
| case ToolApprovalRequestContent tarc when tarc.ToolCall is FunctionCallContent { InformationalOnly: false }: | ||||||||||||
| // Validation: Capture each call id for each approval request to ensure later we have a matching response. | ||||||||||||
| _ = (approvalRequestCallIds ??= []).Add(tarc.ToolCall.CallId); | ||||||||||||
| (allApprovalRequestsMessages ??= []).Add(tarc.RequestId, message); | ||||||||||||
| (allApprovalRequestsMessages ??= []).Add(tarc.RequestId, (message, tarc)); | ||||||||||||
| break; | ||||||||||||
|
|
||||||||||||
| case ToolApprovalResponseContent tarc when tarc.ToolCall is FunctionCallContent { InformationalOnly: false }: | ||||||||||||
|
|
@@ -1451,9 +1451,14 @@ FunctionResultContent CreateFunctionResultContent(FunctionInvocationResult resul | |||||||||||
| ref List<ApprovalResultWithRequestMessage>? targetList = ref approvalResponse.Approved ? ref approvedFunctionCalls : ref rejectedFunctionCalls; | ||||||||||||
|
|
||||||||||||
| ChatMessage? requestMessage = null; | ||||||||||||
| _ = allApprovalRequestsMessages?.TryGetValue(approvalResponse.RequestId, out requestMessage); | ||||||||||||
| ToolApprovalRequestContent? requestContent = null; | ||||||||||||
| if (allApprovalRequestsMessages?.TryGetValue(approvalResponse.RequestId, out var requestInfo) is true) | ||||||||||||
| { | ||||||||||||
| requestMessage = requestInfo.Message; | ||||||||||||
| requestContent = requestInfo.RequestContent; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| (targetList ??= []).Add(new() { Response = approvalResponse, RequestMessage = requestMessage }); | ||||||||||||
| (targetList ??= []).Add(new() { Response = approvalResponse, Request = requestContent, RequestMessage = requestMessage }); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -1469,17 +1474,21 @@ FunctionResultContent CreateFunctionResultContent(FunctionInvocationResult resul | |||||||||||
| rejections is { Count: > 0 } ? | ||||||||||||
| rejections.ConvertAll(m => | ||||||||||||
| { | ||||||||||||
| LogFunctionRejected(m.FunctionCallContent.Name, m.Response.Reason); | ||||||||||||
| LogFunctionRejected(m.ResponseFunctionCallContent.Name, m.Response.Reason); | ||||||||||||
|
|
||||||||||||
| string result = "Tool call invocation rejected."; | ||||||||||||
| if (!string.IsNullOrWhiteSpace(m.Response.Reason)) | ||||||||||||
| { | ||||||||||||
| result = $"{result} {m.Response.Reason}"; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Mark the function call as purely informational since we're handling it (by rejecting it) | ||||||||||||
| m.FunctionCallContent.InformationalOnly = true; | ||||||||||||
| return (AIContent)new FunctionResultContent(m.FunctionCallContent.CallId, result); | ||||||||||||
| // Mark the function call as purely informational since we're handling it (by rejecting it). | ||||||||||||
| // We mark both the response and request FunctionCallContent to ensure consistency | ||||||||||||
| // across serialization boundaries where they may be separate object instances. | ||||||||||||
| m.ResponseFunctionCallContent.InformationalOnly = true; | ||||||||||||
| _ = m.RequestFunctionCallContent?.InformationalOnly = true; | ||||||||||||
|
|
||||||||||||
| return (AIContent)new FunctionResultContent(m.ResponseFunctionCallContent.CallId, result); | ||||||||||||
| }) : | ||||||||||||
| null; | ||||||||||||
|
|
||||||||||||
|
|
@@ -1708,6 +1717,13 @@ private IList<ChatMessage> ReplaceFunctionCallsWithApprovalRequests( | |||||||||||
| originalMessages, options, notInvokedApprovals.Select(x => x.Response.ToolCall).OfType<FunctionCallContent>().ToList(), 0, consecutiveErrorCount, isStreaming, cancellationToken); | ||||||||||||
| consecutiveErrorCount = modeAndMessages.NewConsecutiveErrorCount; | ||||||||||||
|
|
||||||||||||
| // Also mark the request's FCC as InformationalOnly to ensure consistency | ||||||||||||
| // across serialization boundaries where they may be separate object instances. | ||||||||||||
| foreach (var approval in notInvokedApprovals) | ||||||||||||
| { | ||||||||||||
| _ = approval.RequestFunctionCallContent?.InformationalOnly = true; | ||||||||||||
|
||||||||||||
| _ = approval.RequestFunctionCallContent?.InformationalOnly = true; | |
| if (approval.RequestFunctionCallContent is not null) | |
| { | |
| approval.RequestFunctionCallContent.InformationalOnly = true; | |
| } |
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
Oops, something went wrong.
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.
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.
m.RequestFunctionCallContent?.InformationalOnly = trueuses the null-conditional operator on the left-hand side of an assignment, which is not valid C# and will fail to compile. Update this to an explicit null check (e.g., store the value in a local and set the property when non-null).