microsoft/autogen · error · InvalidOperationException
Image message is not supported as model role in Gemini.
Error message
Image message is not supported as model role in Gemini.
What it means
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.
Source
Thrown at dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs:367
{
parts.Add(new Part { Text = textMessage.Content });
}
else if (message is ImageMessage imageMessage)
{
parts.Add(CreateImagePart(imageMessage));
}
else
{
throw new InvalidOperationException($"Unsupported message type: {message.GetType()}");
}
}
var shouldParseAsUser = ShouldParseAsUser(multiModalMessage, agent);
if (strictMode && !shouldParseAsUser)
{
// image message is not supported as model role in Gemini
throw new InvalidOperationException("Image message is not supported as model role in Gemini.");
}
var content = new Content
{
Parts = { parts },
Role = shouldParseAsUser ? "user" : "model",
};
return [MessageEnvelope.Create(content, multiModalMessage.From)];
}
private IEnumerable<IMessage> ProcessTextMessage(TextMessage textMessage, IAgent agent)
{
if (textMessage.Role == Role.System)
{
// there are only user | model role in Gemini
// if the role is system and the strict mode is enabled, throw an exception
if (strictMode)View on GitHub (pinned to 027ecf0a37)
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.
Example fix
// before history.Add(new MultiModalMessage(Role.Assistant, [img], from: geminiAgent.Name)); var reply = await geminiAgent.InitiateChatAsync(null, history: history); // after history.Add(new TextMessage(Role.Assistant, "[image was shown]", from: geminiAgent.Name));
Defensive patterns
Strategy: validation
Validate before calling
bool parsesAsUser = multiModalMessage.From != geminiAgent.Name;
bool hasImage = multiModalMessage.Content.Any(c => c is ImageMessage);
if (!parsesAsUser && hasImage) { /* strip images or re-attribute before sending */ } Prevention
- Never replay assistant-role image messages into Gemini history
- Attribute multimodal inputs to the user side
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ToolCallMessage is not supported as user role in Gemini.
- System role is not supported in Gemini.
- The response should contain either text or tool calls.
- Unsupported message type: {m.GetType()}
- Unsupported message type: {message.GetType()}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/4c7f17cefee31fa5.
Report an issue: GitHub.