microsoft/autogen · error · InvalidOperationException

Unsupported message type

Error message

Unsupported message type

What it means

Thrown by SemanticKernelChatMessageContentConnector.ProcessMessageForSelf when a Message from the agent itself does not match any supported shape. The connector only accepts: (a) string content with null FunctionName/FunctionArguments, or (b) null content with both FunctionName and FunctionArguments set (which is then rejected separately). Any other combination falls into the final else and raises this InvalidOperationException.

Solutions

  1. Ensure the message passed for 'self' history has plain string Content with FunctionName and FunctionArguments both null
  2. If the message carries a function call, set Content to null AND populate both FunctionName and FunctionArguments as non-null strings (though that path throws separately in this connector)
  3. Convert multimodal or structured content to a string (e.g. serialize/collapse to text) before sending to a SemanticKernel agent
  4. Upgrade AutoGen.SemanticKernel to a newer 0.4x+ version where message processing was reworked to support function-call history

Example fix

// before
var msg = new Message(Role.Assistant, from: agentName)
{
    Content = resultJson,
    FunctionName = "get_weather", // FunctionArguments left null -> falls to 'Unsupported message type'
};

// after
var msg = new Message(Role.Assistant, content: "Called get_weather", from: agentName); // plain string, no function fields
Defensive patterns

Strategy: validation

Validate before calling

bool IsSupportedSelfMessage(Message m) =>
    (m.Content is string && m.FunctionName is null && m.FunctionArguments is null)
    || (m.Content is null && m.FunctionName is not null && m.FunctionArguments is not null);

var safe = messages.Where(IsSupportedSelfMessage);

Type guard

static bool IsSupportedSelfMessage(Message m) =>
    m.Content is string && m.FunctionName is null && m.FunctionArguments is null;

Try / catch

try { await skAgent.SendAsync(msg); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Unsupported message type"))
{
    _logger.LogWarning("Dropping unsupported self message {Type}", msg.Content?.GetType()); // drop and continue
}

Prevention

When it happens

Trigger: Passing a Message to the SemanticKernel middleware where Content is not a string (e.g. multimodal content or an IList), or where FunctionName is set but FunctionArguments is null (or vice versa), or where both string content and a function call are present at once.

Common situations: Replaying a captured function-call message that was serialized and lost one field (arguments null after round-trip), mixing tool output with function name, or feeding a MultiModalMessage/ToolMessage content object into a SemanticKernel agent pipeline that expects plain chat text.

Related errors


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

Appendix: source

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

    [Obsolete("This method is deprecated, please use the specific method instead.")]
    private IEnumerable<ChatMessageContent> ProcessMessageForSelf(Message message)
    {
        if (message.Role == Role.System)
        {
            return [new ChatMessageContent(AuthorRole.System, message.Content)];
        }
        else if (message.Content is string && message.FunctionName is null && message.FunctionArguments is null)
        {
            return [new ChatMessageContent(AuthorRole.Assistant, message.Content)];
        }
        else if (message.Content is null && message.FunctionName is not null && message.FunctionArguments is not null)
        {
            throw new System.InvalidOperationException("Function call is not supported in the semantic kernel if it's from self.");
        }
        else
        {
            throw new System.InvalidOperationException("Unsupported message type");
        }
    }

    [Obsolete("This method is deprecated, please use the specific method instead.")]
    private IEnumerable<ChatMessageContent> ProcessMessageForOthers(Message message)
    {
        if (message.Role == Role.System)
        {
            return [new ChatMessageContent(AuthorRole.System, message.Content)];
        }
        else if (message.Content is string && message.FunctionName is null && message.FunctionArguments is null)
        {
            return [new ChatMessageContent(AuthorRole.User, message.Content)];
        }
        else if (message.Content is null && message.FunctionName is not null && message.FunctionArguments is not null)
        {
            throw new System.InvalidOperationException("Function call is not supported in the semantic kernel if it's from others.");
        }

View on GitHub (pinned to 027ecf0a37)