{"record":{"id":"6519f6aa299b2791","repo":"microsoft/autogen","slug":"imagemessage-is-not-supported-when-message-from-is-6519f6","errorCode":null,"errorMessage":"ImageMessage is not supported when message.From is the same with agent","messagePattern":"ImageMessage is not supported when message\\.From is the same with agent","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":270,"sourceCode":"        }\n        else\n        {\n            return message.From switch\n            {\n                null when message.Role == Role.User => [new UserChatMessage(message.Content)],\n                null when message.Role == Role.Assistant => [new AssistantChatMessage(message.Content)],\n                null => throw new InvalidOperationException(\"Invalid Role\"),\n                _ => [new UserChatMessage(message.Content) { ParticipantName = message.From }]\n            };\n        }\n    }\n\n    private IEnumerable<ChatMessage> ProcessImageMessage(IAgent agent, ImageMessage message)\n    {\n        if (agent.Name == message.From)\n        {\n            // image message from assistant is not supported\n            throw new ArgumentException(\"ImageMessage is not supported when message.From is the same with agent\");\n        }\n\n        var imageContentItem = this.CreateChatMessageImageContentItemFromImageMessage(message);\n        return [new UserChatMessage([imageContentItem]) { ParticipantName = message.From }];\n    }\n\n    private IEnumerable<ChatMessage> ProcessMultiModalMessage(IAgent agent, MultiModalMessage message)\n    {\n        if (agent.Name == message.From)\n        {\n            // image message from assistant is not supported\n            throw new ArgumentException(\"MultiModalMessage is not supported when message.From is the same with agent\");\n        }\n\n        IEnumerable<ChatMessageContentPart> items = message.Content.Select<IMessage, ChatMessageContentPart>(ci => ci switch\n        {\n            TextMessage text => ChatMessageContentPart.CreateTextPart(text.Content),\n            ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs#L252-L288","documentation":"ProcessImageMessage refuses to convert an ImageMessage whose From equals the receiving agent's name: OpenAI's chat protocol has no concept of an assistant-authored image user message, so replaying an agent's own image output back into its history cannot be represented.","triggerScenarios":"In a group chat or manual history replay, an ImageMessage created with from: agent.Name (or produced by that agent) is sent to the same agent.","commonSituations":"Round-robin group chats where every agent sees all messages including its own prior outputs; copying assistant image replies into the next request unmodified.","solutions":["Filter self-authored image messages out of the history before calling the agent (skip ImageMessage where From == agent.Name).","Re-label the message with From = null or the user's name if the image genuinely must be shown to the agent as input.","Use non-strict connector mode plus prior filtering so self-images are dropped rather than converted."],"exampleFix":"// before\nvar history = allMessages; // includes agent's own ImageMessage\nawait agent.SendAsync(history);\n\n// after\nvar history = allMessages.Where(m => m is not ImageMessage im || im.From != agent.Name);\nawait agent.SendAsync(history);","handlingStrategy":"validation","validationCode":"var safeHistory = messages.Where(m => m is not ImageMessage img || img.From != agent.Name).ToList();\nawait agent.SendAsync(safeHistory);","typeGuard":"static bool IsReplayableToAgent(IMessage m, string agentName) => m switch\n{\n    ImageMessage img => img.From != agentName,\n    _ => true,\n};","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"ImageMessage is not supported\"))\n{\n    var filtered = messages.Where(m => m is not ImageMessage im || im.From != agent.Name);\n    return await agent.SendAsync(filtered);\n}","preventionTips":["In group chats, always filter self-authored image/multimodal messages per recipient.","Keep a single history-normalization step before any agent call."],"tags":["openai","message-connector","image-message","group-chat","autogen"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}