microsoft/autogen · error · InvalidOperationException

Unsupported content type

Error message

Unsupported content type

What it means

SemanticKernelChatMessageContentConnector.PostProcessMessage converts each item of a SK ChatMessageContent into AutoGen messages. Only TextContent and ImageContent (with Uri or Data) are supported; any other KernelContent-derived item — notably FunctionCallContent — throws 'Unsupported content type'.

Source

Thrown at dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs:88

    private IMessage PostProcessStreamingMessage(IMessage input)
    {
        return input switch
        {
            IMessage<StreamingChatMessageContent> streamingMessage => PostProcessMessage(streamingMessage),
            IMessage msg => PostProcessMessage(msg),
            _ => input,
        };
    }

    private IMessage PostProcessMessage(IMessage<ChatMessageContent> messageEnvelope)
    {
        var chatMessageContent = messageEnvelope.Content;
        var items = chatMessageContent.Items.Select<KernelContent, IMessage>(i => i switch
        {
            TextContent txt => new TextMessage(Role.Assistant, txt.Text!, messageEnvelope.From),
            ImageContent img when img.Uri is Uri uri => new ImageMessage(Role.Assistant, uri.ToString(), from: messageEnvelope.From),
            ImageContent img when img.Data is ReadOnlyMemory<byte> data => new ImageMessage(Role.Assistant, BinaryData.FromBytes(data), from: messageEnvelope.From),
            _ => throw new InvalidOperationException("Unsupported content type"),
        });

        if (items.Count() == 1)
        {
            return items.First();
        }
        else
        {
            return new MultiModalMessage(Role.Assistant, items, from: messageEnvelope.From);
        }
    }

    private IMessage PostProcessMessage(IMessage<StreamingChatMessageContent> streamingMessage)
    {
        var chatMessageContent = streamingMessage.Content;
        if (chatMessageContent.ChoiceIndex > 0)
        {
            throw new InvalidOperationException("Only one choice is supported in streaming response");

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Enable SK auto function invocation (ToolCallBehavior) so function calls are resolved before content reaches the connector, or route function-call completions through a connector that handles them.
  2. Configure the agent so tool calls land in the tool-call channel rather than content items.
  3. Update AutoGen to a version whose SK connector supports the content kinds your SK version emits.
  4. Intercept IMessage<ChatMessageContent> yourself and extract FunctionCallContent before post-processing.

Example fix

// before
var settings = new OpenAIPromptExecutionSettings { ToolCallBehavior = null }; // tool calls leak into content

// after
var settings = new OpenAIPromptExecutionSettings { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions };
Defensive patterns

Strategy: type-guard

Validate before calling

// Before post-processing, verify all items are convertible
var unsupported = chatMessageContent.Items.Where(i => i is not TextContent && i is not (ImageContent ic when ic.Uri is not null || ic.Data is not null)).ToList();
if (unsupported.Count > 0) { /* extract FunctionCallContent yourself or reconfigure SK */ }

Type guard

static bool IsSupportedKernelContent(KernelContent c) => c switch
{
    TextContent => true,
    ImageContent img => img.Uri is not null || img.Data is not null,
    _ => false,
};

Try / catch

catch (InvalidOperationException ex) when (ex.Message == "Unsupported content type")
{
    logger.LogError("SK returned non text/image content (likely FunctionCallContent). Enable auto function invocation.");
    throw;
}

Prevention

When it happens

Trigger: The SK chat completion returns content items such as FunctionCallContent (auto function invocation disabled), AudioContent, or BinaryContent instead of plain text/image parts.

Common situations: Auto function-calling is turned off (or tool calls arrive as content rather than the ToolCalls property), so function-call payloads surface in ChatMessageContent.Items; using newer SK content kinds this connector predates.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/77971f5fa8942aa3. Report an issue: GitHub.