microsoft/autogen · error · ArgumentException
Unknown message type: {message.GetType()}
Error message
Unknown message type: {message.GetType()} What it means
This ArgumentException is the catch-all of the foreign-sender branch of ToOpenAIChatRequestMessage: the message's From differs from the agent name and its type matched none of the handled cases (TextMessage, ImageMessage, ToolCallMessage, ToolCallResultMessage, MultiModalMessage, AggregateMessage), so it cannot be converted.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:152
{
if (msg.Role == Role.Function)
{
return [new ChatRequestFunctionMessage(msg.FunctionName, msg.Content)];
}
else
{
return [new ChatRequestUserMessage(msg.Content)];
}
}
else
{
var userMessage = new ChatRequestUserMessage(msg.Content ?? throw new ArgumentException("Content is null"));
return [userMessage];
}
}
else
{
throw new ArgumentException($"Unknown message type: {message.GetType()}");
}
}
else
{
if (message is TextMessage textMessage)
{
if (textMessage.Role == Role.System)
{
throw new ArgumentException("System message is not supported when message.From is the same with agent");
}
return [new ChatRequestAssistantMessage(textMessage.Content)];
}
else if (message is ToolCallMessage toolCallMessage)
{
var assistantMessage = new ChatRequestAssistantMessage(string.Empty);
var toolCalls = toolCallMessage.ToolCalls.Select(tc => new ChatCompletionsFunctionToolCall(tc.FunctionName, tc.FunctionName, tc.FunctionArguments));
foreach (var tc in toolCalls)View on GitHub (pinned to 027ecf0a37)
Solutions
- Convert custom messages to TextMessage/ImageMessage before they reach the OpenAI connector
- Update AutoGen.OpenAI.V1 to a version that supports your message type
- Wrap with your own middleware that normalizes unknown message types into TextMessage
Example fix
// before await agent.SendAsync(new MyCustomMessage(...)); // unknown type // after var asText = new TextMessage(Role.User, myCustomMessage.ToString(), from: myCustomMessage.From); await agent.SendAsync(asText);
Defensive patterns
Strategy: fallback
Validate before calling
var known = msg is TextMessage or ImageMessage or ToolCallMessage
or ToolCallResultMessage or MultiModalMessage
or AggregateMessage<ToolCallMessage, ToolCallResultMessage>;
if (!known) msg = new TextMessage(Role.User, msg.ToString(), msg.From); Type guard
static bool IsConvertibleForeignMessage(IMessage m) =>
m is TextMessage or ImageMessage or ToolCallResultMessage or MultiModalMessage
or AggregateMessage<ToolCallMessage, ToolCallResultMessage>; Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("Unknown message type"))
{
var flattened = new TextMessage(Role.User, originalMessage.ToString(), originalMessage.From);
return await agent.SendAsync(flattened);
} Prevention
- Normalize custom message types to TextMessage before OpenAI agents
- Keep AutoGen packages version-aligned
- Centralize message construction in one factory
When it happens
Trigger: Sending a custom IMessage implementation, an obscure built-in type, or a message kind the extension doesn't handle (with From set to another agent) to an OpenAI agent via the deprecated conversion path.
Common situations: User-defined message types in middleware pipelines; newer AutoGen message types flowing through an older AutoGen.OpenAI.V1 build after a partial package upgrade.
Related errors
- Invalid message type
- Content is null and metadata is null
- Unknown message type: {m.GetType()}
- Content is null
- Failed to fetch galleries
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/693567d8080ab0b9.
Report an issue: GitHub.