microsoft/autogen · error · ArgumentException

ImageMessage is not supported when message.From is the same

Error message

ImageMessage is not supported when message.From is the same with agent

What it means

ArgumentException thrown by ProcessImageMessage when an ImageMessage's From equals the agent's own name. The OpenAI chat API only accepts images in user messages, so an assistant-sent image cannot be converted; replaying an agent's own image output back into its history fails here.

Source

Thrown at dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs:297

        }
        else
        {
            return message.From switch
            {
                null when message.Role == Role.User => [new ChatRequestUserMessage(message.Content)],
                null when message.Role == Role.Assistant => [new ChatRequestAssistantMessage(message.Content)],
                null => throw new InvalidOperationException("Invalid Role"),
                _ => [new ChatRequestUserMessage(message.Content) { Name = message.From }]
            };
        }
    }

    private IEnumerable<ChatRequestMessage> ProcessImageMessage(IAgent agent, ImageMessage message)
    {
        if (agent.Name == message.From)
        {
            // image message from assistant is not supported
            throw new ArgumentException("ImageMessage is not supported when message.From is the same with agent");
        }

        var imageContentItem = this.CreateChatMessageImageContentItemFromImageMessage(message);
        return [new ChatRequestUserMessage([imageContentItem]) { Name = message.From }];
    }

    private IEnumerable<ChatRequestMessage> ProcessMultiModalMessage(IAgent agent, MultiModalMessage message)
    {
        if (agent.Name == message.From)
        {
            // image message from assistant is not supported
            throw new ArgumentException("MultiModalMessage is not supported when message.From is the same with agent");
        }

        IEnumerable<ChatMessageContentItem> items = message.Content.Select<IMessage, ChatMessageContentItem>(ci => ci switch
        {
            TextMessage text => new ChatMessageTextContentItem(text.Content),
            ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Exclude the producing agent's own image messages when replaying history to it (the connector's switch already does this for ImageMessage when From != agent)
  2. Convert assistant image output to a TextMessage description before storing in shared history
  3. Route the image to a different agent that consumes images

Example fix

// before
var history = new List<IMessage> { new ImageMessage(from: agent.Name, ...) };
await agent.SendAsync(history); // throws

// after
var history = fullHistory.Where(m => !(m is ImageMessage im && im.From == agent.Name));
await agent.SendAsync(history);
Defensive patterns

Strategy: validation

Validate before calling

var safeHistory = messages.Where(m => m is not ImageMessage im || im.From != agent.Name);

Type guard

static bool IsReplayableToAgent(ImageMessage m, IAgent agent) => m.From != agent.Name;

Try / catch

catch (ArgumentException ex) when (ex.Message.Contains("ImageMessage is not supported")) { /* drop self-image from history and resend */ }

Prevention

When it happens

Trigger: An ImageMessage with From == agent.Name entering ProcessIncomingMessages — typically a group chat where an agent's image reply is echoed back to the same agent.

Common situations: Round-robin group chats with image-producing agents; saving assistant ImageMessage replies into shared history and resending to everyone including the originator.

Related errors


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