-
Couldn't load subscription status.
- Fork 840
Special-case AIContent returned from AIFunctionFactory.Create AIFunctions to not be serialized #6935
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
Conversation
…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.
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.
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
AIFunctionFactoryto detect and preserveAIContentandIEnumerable<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.csfor 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 |
test/Libraries/Microsoft.Extensions.AI.Tests/Functions/AIFunctionFactoryTest.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs
Show resolved
Hide resolved
…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
…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
…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
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