microsoft/autogen · error · ArgumentException
Invalid message type
Error message
Invalid message type
What it means
Error "Invalid message type" thrown in microsoft/autogen.
Source
Thrown at dotnet/src/AutoGen.AzureAIInference/Agent/ChatCompletionsClientAgent.cs:124
public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(
IEnumerable<IMessage> messages,
GenerateReplyOptions? options = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var settings = this.CreateChatCompletionsOptions(options, messages);
var response = await this.chatCompletionsClient.CompleteStreamingAsync(settings, cancellationToken);
await foreach (var update in response.WithCancellation(cancellationToken))
{
yield return new MessageEnvelope<StreamingChatCompletionsUpdate>(update, from: this.Name);
}
}
private ChatCompletionsOptions CreateChatCompletionsOptions(GenerateReplyOptions? options, IEnumerable<IMessage> messages)
{
var oaiMessages = messages.Select(m => m switch
{
IMessage<ChatRequestMessage> chatRequestMessage => chatRequestMessage.Content,
_ => throw new ArgumentException("Invalid message type")
});
// add system message if there's no system message in messages
if (!oaiMessages.Any(m => m is ChatRequestSystemMessage))
{
oaiMessages = new[] { new ChatRequestSystemMessage(systemMessage) }.Concat(oaiMessages);
}
// clone the options by serializing and deserializing
var json = JsonSerializer.Serialize(this.options);
var settings = JsonSerializer.Deserialize<ChatCompletionsOptions>(json) ?? throw new InvalidOperationException("Failed to clone options");
foreach (var m in oaiMessages)
{
settings.Messages.Add(m);
}
settings.Temperature = options?.Temperature ?? settings.Temperature;View on GitHub (pinned to 027ecf0a37)
Solutions
- Pass only TextMessage, ImageMessage, MultiModalMessage, or ToolCallMessage
Example fix
Convert the message to a supported IMessage type before invoking the agent
When it happens
Trigger: Thrown at dotnet/src/AutoGen.AzureAIInference/Agent/ChatCompletionsClientAgent.cs:124 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/1139b0bf0a839a54.
Report an issue: GitHub.