Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Oct 20, 2025

They'll likely end up being serialized, anyway, by leaf IChatClients, but this gives those IChatClients the opportunity to do something different, such as by treating DataContent differently.

Microsoft Reviewers: Open in CodeFlow

…ions to not be serialized

They'll likely end up being serialized, anyway, by leaf IChatClients, but this gives those IChatClients the opportunity to do something different, such as by treating DataContent differently.
@stephentoub stephentoub requested a review from a team as a code owner October 20, 2025 16:28
Copilot AI review requested due to automatic review settings October 20, 2025 16:28
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 20, 2025
Copy link
Contributor

Copilot AI left a 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 modifies the AIFunctionFactory to special-case AIContent-related return types by not serializing them automatically. This allows downstream IChatClient implementations to handle different content types (like DataContent) in specialized ways rather than forcing JSON serialization at the function factory level.

Key Changes

  • Modified AIFunctionFactory to detect and preserve AIContent and IEnumerable<AIContent> return types without serialization
  • Added type normalization for return types to support reflection-based serialization scenarios
  • Updated tests to verify the new behavior across synchronous, async Task, and async ValueTask patterns
  • Reorganized JSON serialization attributes in AIJsonUtilities.Defaults.cs for better maintainability

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs Added special handling for AIContent return types and type normalization logic
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs Reorganized JsonSerializable attributes with semantic grouping and added IEnumerable
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Added switch statement structure for future AIContent type handling in tool results
test/Libraries/Microsoft.Extensions.AI.Tests/Functions/AIFunctionFactoryTest.cs Added comprehensive test coverage for AIContent return type behavior
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientTests.cs Updated test expectations to reflect serialized TextContent in tool responses
test/Libraries/Microsoft.Extensions.AI.Integration.Tests/VerbatimHttpHandler.cs Refactored whitespace removal logic and fixed control flow issue

@stephentoub stephentoub enabled auto-merge (squash) October 20, 2025 17:11
@stephentoub stephentoub merged commit aec14a5 into dotnet:main Oct 20, 2025
6 checks passed
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
…ions to not be serialized (dotnet#6935)

* Special-case AIContent returned from AIFunctionFactory.Create AIFunctions to not be serialized

They'll likely end up being serialized, anyway, by leaf IChatClients, but this gives those IChatClients the opportunity to do something different, such as by treating DataContent differently.

* Update XML comments
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
…ions to not be serialized (dotnet#6935)

* Special-case AIContent returned from AIFunctionFactory.Create AIFunctions to not be serialized

They'll likely end up being serialized, anyway, by leaf IChatClients, but this gives those IChatClients the opportunity to do something different, such as by treating DataContent differently.

* Update XML comments
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
…ions to not be serialized (dotnet#6935)

* Special-case AIContent returned from AIFunctionFactory.Create AIFunctions to not be serialized

They'll likely end up being serialized, anyway, by leaf IChatClients, but this gives those IChatClients the opportunity to do something different, such as by treating DataContent differently.

* Update XML comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants