{"record":{"id":"4c7f17cefee31fa5","repo":"microsoft/autogen","slug":"image-message-is-not-supported-as-model-role-in-ge","errorCode":null,"errorMessage":"Image message is not supported as model role in Gemini.","messagePattern":"Image message is not supported as model role in Gemini\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":367,"sourceCode":"            {\n                parts.Add(new Part { Text = textMessage.Content });\n            }\n            else if (message is ImageMessage imageMessage)\n            {\n                parts.Add(CreateImagePart(imageMessage));\n            }\n            else\n            {\n                throw new InvalidOperationException($\"Unsupported message type: {message.GetType()}\");\n            }\n        }\n\n        var shouldParseAsUser = ShouldParseAsUser(multiModalMessage, agent);\n\n        if (strictMode && !shouldParseAsUser)\n        {\n            // image message is not supported as model role in Gemini\n            throw new InvalidOperationException(\"Image message is not supported as model role in Gemini.\");\n        }\n\n        var content = new Content\n        {\n            Parts = { parts },\n            Role = shouldParseAsUser ? \"user\" : \"model\",\n        };\n\n        return [MessageEnvelope.Create(content, multiModalMessage.From)];\n    }\n\n    private IEnumerable<IMessage> ProcessTextMessage(TextMessage textMessage, IAgent agent)\n    {\n        if (textMessage.Role == Role.System)\n        {\n            // there are only user | model role in Gemini\n            // if the role is system and the strict mode is enabled, throw an exception\n            if (strictMode)","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L349-L385","documentation":"In strict mode, GeminiMessageConnector.ProcessMultiModalMessage refuses to render a MultiModalMessage containing images with the 'model' role: Gemini's API only accepts inline image data from the user side. ShouldParseAsUser returns false when the message's From matches the Gemini agent's own name, meaning the agent is being asked to re-send images as if it produced them.","triggerScenarios":"strictMode:true and a MultiModalMessage with an ImageMessage whose From equals the Gemini agent name (or otherwise resolves to model role) is fed back through ProcessMessage.","commonSituations":"Group-chat history replay where the Gemini agent's own prior multimodal output is echoed back to it; workflows that forward a user's image to multiple agents and then merge histories.","solutions":["Strip ImageMessages from assistant-role history before replaying the conversation to a strict Gemini agent (keep text only).","Ensure multimodal inputs are attributed with From set to the user/another agent, not the Gemini agent's name.","Turn off strict mode if lenient pass-through is acceptable for your pipeline."],"exampleFix":"// before\nhistory.Add(new MultiModalMessage(Role.Assistant, [img], from: geminiAgent.Name));\nvar reply = await geminiAgent.InitiateChatAsync(null, history: history);\n\n// after\nhistory.Add(new TextMessage(Role.Assistant, \"[image was shown]\", from: geminiAgent.Name));","handlingStrategy":"validation","validationCode":"bool parsesAsUser = multiModalMessage.From != geminiAgent.Name;\nbool hasImage = multiModalMessage.Content.Any(c => c is ImageMessage);\nif (!parsesAsUser && hasImage) { /* strip images or re-attribute before sending */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never replay assistant-role image messages into Gemini history","Attribute multimodal inputs to the user side"],"tags":["gemini","strict-mode","multimodal","role-mapping"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}