.Net: feat(connectors): Support ImageContent in tool/function results #13431
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.
Motivation and Context
Fixes #13430
Currently, when a Semantic Kernel function returns
ImageContent, it gets serialized to JSON - losing the binary image data and preventing multimodal-capable models from processing the image.This PR enables
ImageContentpreservation in tool/function results, allowing connectors with multimodal capabilities (Gemini 3+, Anthropic) to pass images natively to the model. This is essential for agentic workflows where tools generate or process images that the model needs to analyze.Description
FunctionCallsProcessor (shared infrastructure)
ProcessFunctionResult()return type fromstringtoobjectImageContentto preserve it for multimodal-capable connectorsImageContentNotSupportedErrorMessageconstant for consistent error messagingGoogle Gemini Connector (native support)
FunctionResponsePartwithPartsproperty for nested multimodal contentFunctionResponsePartContentclass withInlineDatasupportCreateImageFunctionResponsePart()to convertImageContentto Gemini's nativeinlineDataformatOpenAI Connector (error handling)
ImageContentcheck with clear error message (API does not support images in tool results)OpenAI Agents (error handling)
GetFunctionResultAsString()helper withImageContenterror handlingAmazon Bedrock Agents (error handling)
GetFunctionResultAsString()helper withImageContenterror handlingNew Unit Tests
ItShouldPreserveImageContentWithoutSerializationFunctionCallsProcessorTests.csFromChatHistoryImageContentInToolResultCreatesInlineDataPartGeminiRequestTests.csFromChatHistoryImageContentWithoutDataThrowsInvalidOperationExceptionGeminiRequestTests.csFromChatHistoryImageContentWithoutMimeTypeThrowsInvalidOperationExceptionGeminiRequestTests.csVerifyAssistantMessageAdapterGetMessageWithImageContentInFunctionResultAssistantMessageFactoryTests.csNotes
FunctionResultContent.Resultproperty is alreadyobject?.functionResponse.parts, the API will return an appropriate error.ImageContentwith binary data is supported. URI-basedImageContentwill throwInvalidOperationException.ProcessFunctionResultimplementation.Contribution Checklist
sk-pr-MultimodalToolResults.md