-
Notifications
You must be signed in to change notification settings - Fork 849
Unseal FunctionCallContent/FunctionResultContent; make MCP types extend them #7201
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
…ew approval types Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
…ypes Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Co-authored-by: jozkee <16040868+jozkee@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.
@copilot please fix errors and address feedback.
| /// Gets the call content that pre-invoke approval is required for. | ||
| /// </summary> | ||
| public FunctionCallContent FunctionCall { get; } | ||
| public AIContent CallContent { get; } |
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.
CallContent can go back to be FunctionCallContent FunctionCall.
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.
Done in commit 598f78b. Changed CallContent back to FunctionCallContent FunctionCall.
| /// Gets the call content for which approval was requested. | ||
| /// </summary> | ||
| public FunctionCallContent FunctionCall { get; } | ||
| public AIContent CallContent { get; } |
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.
Same here.
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.
Done in commit 598f78b. Changed CallContent back to FunctionCallContent FunctionCall.
| /// </summary> | ||
| public IReadOnlyDictionary<string, object?>? Arguments { get; set; } | ||
| [JsonIgnore] | ||
| public new IReadOnlyDictionary<string, object?>? Arguments |
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.
instead of adding a new property, let's use the one in base, let's take the breaking change of switching from IReadOnlyDictionary<string, object?>.
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.
Done in commit 598f78b. Removed the new property and using base class Arguments property directly (breaking change from IReadOnlyDictionary to IDictionary accepted).
| [JsonIgnore] | ||
| public IList<AIContent>? Output | ||
| { | ||
| get => Result as IList<AIContent>; | ||
| set => Result = value; | ||
| } |
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.
Let's take the breaking change and use base.Result instead of Output and update the call sites as needed.
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.
| case McpToolCallApprovalResponseItem mtcari: | ||
| message.Contents.Add(new McpServerToolApprovalResponseContent(mtcari.ApprovalRequestId, mtcari.Approved) { RawRepresentation = mtcari }); | ||
| // Approval responses are processed separately when converting tool messages (see ConvertToResponseItems). | ||
| // They are not included in assistant message contents. | ||
| break; |
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.
This should be removed and let the code use the default case for McpToolCallApprovalResponseItem.
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.
Done in commit 598f78b. Removed the case for McpToolCallApprovalResponseItem and letting it use the default case processing.
|
|
||
| case McpServerToolResultContent mstrc: | ||
| if (idToContentMapping?.TryGetValue(mstrc.CallId, out AIContent? callContentFromMapping) is true && | ||
| callContentFromMapping is McpServerToolCallContent associatedCall) |
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.
Not related to this change but can you change idToContentMapping to Dictionary<string, McpServerToolCallContent> and remove this condition, it should be fine since we are storing only one concrete type in it.
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.
Done in commit 598f78b. Changed idToContentMapping from Dictionary<string, AIContent> to Dictionary<string, McpServerToolCallContent> and removed the condition check.
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.
You missed a bunch of tests from https://github.com/dotnet/extensions/pull/7104/changes#diff-e6c178864ff9bd78b41577e6e0e8170e602af913f45a9108bfa830ea70739621.
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.
Done in commits 598f78b and 23d5d20. Changed namespace to Microsoft.Extensions.AI and added all three missing tests:
FunctionCallReplacedWithApproval_MixedWithMcpApprovalAsyncApprovedApprovalResponseIsExecuted_MixedWithMcpApprovalAsyncRejectedApprovalResponses_MixedWithMcpApprovalAsync
All tests updated to use Result property instead of Output.
…nts properties, fix idToContentMapping Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
…Dictionary, use Result instead of Output Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
All feedback addressed in commits 598f78b, 23d5d20, and 29454f9. Changes include:
|
Takes over #7104 and augments it by making
McpServerToolCallContentandMcpServerToolResultContentinherit fromFunctionCallContentandFunctionResultContentrespectively, enabling unified approval handling for both regular functions and MCP server tools.Changes
Core type hierarchy
FunctionCallContentandFunctionResultContentto allow inheritanceMcpServerToolCallContentextendsFunctionCallContent, addingServerNameproperty (uses baseArgumentsproperty directly)McpServerToolResultContentextendsFunctionResultContent(uses baseResultproperty directly)Unified approval types (from #7104)
FunctionApprovalRequestContentacceptsFunctionCallContentviaFunctionCallpropertyFunctionApprovalResponseContentacceptsFunctionCallContentviaFunctionCallpropertyMcpServerToolApprovalRequestContentandMcpServerToolApprovalResponseContentClient updates
FunctionInvokingChatClient: Direct access toFunctionCallpropertyOpenAIResponsesChatClient: Reordered switch cases (derived types before base types to avoid unreachable code)idToContentMappingto useDictionary<string, McpServerToolCallContent>Breaking Changes
McpServerToolCallContent.Argumentschanged fromIReadOnlyDictionary<string, object?>toIDictionary<string, object?>McpServerToolResultContentnow usesResultproperty instead ofOutputCompatibility
Tests
Microsoft.Extensions.AI.ChatCompletiontoMicrosoft.Extensions.AIExample
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow