{"record":{"id":"d4b8948ce4fdcbe8","repo":"microsoft/autogen","slug":"imagemessage-is-not-supported-when-message-from-is-d4b894","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.V1/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":297,"sourceCode":"        }\n        else\n        {\n            return message.From switch\n            {\n                null when message.Role == Role.User => [new ChatRequestUserMessage(message.Content)],\n                null when message.Role == Role.Assistant => [new ChatRequestAssistantMessage(message.Content)],\n                null => throw new InvalidOperationException(\"Invalid Role\"),\n                _ => [new ChatRequestUserMessage(message.Content) { Name = message.From }]\n            };\n        }\n    }\n\n    private IEnumerable<ChatRequestMessage> 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 ChatRequestUserMessage([imageContentItem]) { Name = message.From }];\n    }\n\n    private IEnumerable<ChatRequestMessage> 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<ChatMessageContentItem> items = message.Content.Select<IMessage, ChatMessageContentItem>(ci => ci switch\n        {\n            TextMessage text => new ChatMessageTextContentItem(text.Content),\n            ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L279-L315","documentation":"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.","triggerScenarios":"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.","commonSituations":"Round-robin group chats with image-producing agents; saving assistant ImageMessage replies into shared history and resending to everyone including the originator.","solutions":["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)","Convert assistant image output to a TextMessage description before storing in shared history","Route the image to a different agent that consumes images"],"exampleFix":"// before\nvar history = new List<IMessage> { new ImageMessage(from: agent.Name, ...) };\nawait agent.SendAsync(history); // throws\n\n// after\nvar history = fullHistory.Where(m => !(m is ImageMessage im && im.From == agent.Name));\nawait agent.SendAsync(history);","handlingStrategy":"validation","validationCode":"var safeHistory = messages.Where(m => m is not ImageMessage im || im.From != agent.Name);","typeGuard":"static bool IsReplayableToAgent(ImageMessage m, IAgent agent) => m.From != agent.Name;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"ImageMessage is not supported\")) { /* drop self-image from history and resend */ }","preventionTips":["Filter each agent's own image output from its replayed history","Store assistant images as text descriptions in shared group-chat state"],"tags":["autogen","dotnet","azure-openai","image-message","group-chat"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}