Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Enables specialized tool call/result types to derive from FunctionCallContent and FunctionResultContent while remaining compatible with FunctionInvokingChatClient.

Changes

  • Unsealed classes: Removed sealed modifier from FunctionCallContent and FunctionResultContent
  • API baseline: Updated Microsoft.Extensions.AI.Abstractions.json to reflect non-sealed classes
  • Tests: Added validation for derived type serialization via AIJsonUtilities.AddAIContentType

Usage

// Define specialized content types
public sealed class ShellCallContent : FunctionCallContent
{
    public ShellCallContent(string callId, string name, IDictionary<string, object?>? arguments = null)
        : base(callId, name, arguments) { }
    
    public string? WorkingDirectory { get; set; }
    public IDictionary<string, string>? EnvironmentVariables { get; set; }
}

// Register for polymorphic serialization
var options = new JsonSerializerOptions();
options.AddAIContentType<ShellCallContent>("shellCall");

// FunctionInvokingChatClient treats as normal FunctionCallContent
// while specialized handlers can access strongly-typed properties

Implements specification from microsoft/agent-framework#3369 (comment)

Original prompt

Implement support for deriving from FunctionCallContent and FunctionResultContent (unseal them) in dotnet/extensions, as per Stephen Toub’s specification in microsoft/agent-framework#3369 (comment).

Specification (from Stephen’s comment):

  • We want to enable scenarios where a specialized tool call/result content can derive from the existing function call/result content types (e.g., ShellCallContent : FunctionCallContent and ShellResultContent : FunctionResultContent), so that FunctionInvokingChatClient can treat them as normal FCC/FRC while still allowing specialized clients/tools to access strongly-typed additional data.
  • This requires making FunctionCallContent and FunctionResultContent non-sealed.

Expected changes in dotnet/extensions:

  1. Update src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs and src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionResultContent.cs to be inheritable (remove sealed). Ensure their constructors can be used correctly by derived types (e.g., keep public constructors; consider making them protected in addition only if needed, but do not break existing public API usage).
  2. Ensure JSON polymorphic serialization continues to work for the base types and does not regress. Because AIContent uses [JsonPolymorphic] / [JsonDerivedType], ensure derived-from-FCC/FRC types can be registered via AIJsonUtilities.AddAIContentType(...) and participate in polymorphic serialization alongside existing built-ins.
    • Add or adjust tests to validate a custom type derived from FunctionCallContent and FunctionResultContent can round-trip through JsonSerializer using AIJsonUtilities.DefaultOptions once registered.
  3. Ensure existing tests for FCC/FRC still pass.

Implementation notes:

  • Create minimal internal test-only derived types (e.g., DerivedFunctionCallContent and DerivedFunctionResultContent) in the appropriate test project, register them via JsonSerializerOptions.AddAIContentType(...), serialize a ChatMessage containing them (or serialize the content directly via AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent))), and assert the discriminator and property round-tripping works.
  • Keep API behavior backward compatible; only remove sealed and add any additional constructors/virtuals if strictly required.

Open a pull request in dotnet/extensions targeting base branch main with a concise title like: "Unseal FunctionCallContent/FunctionResultContent to enable derived tool call/result types".

This pull request was created from Copilot chat.


💡 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

@stephentoub
Copy link
Member

@jozkee : #7229

Copilot AI changed the title [WIP] Enable derivation from FunctionCallContent and FunctionResultContent Unseal FunctionCallContent and FunctionResultContent Jan 26, 2026
Copilot AI requested a review from jozkee January 26, 2026 19:21
@jozkee jozkee closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants