microsoft/autogen · error · InvalidOperationException
Invalid return message type {message.GetType().Name}
Error message
Invalid return message type {message.GetType().Name} What it means
Error "Invalid return message type {message.GetType().Name}" thrown in microsoft/autogen.
Source
Thrown at dotnet/src/AutoGen.AzureAIInference/Middleware/AzureAIInferenceChatRequestMessageConnector.cs:98
{
throw new InvalidOperationException($"Invalid streaming message type {reply.GetType().Name}");
}
else
{
yield return reply;
}
}
}
}
public IMessage PostProcessMessage(IMessage message)
{
return message switch
{
IMessage<ChatResponseMessage> m => PostProcessChatResponseMessage(m.Content, m.From),
IMessage<ChatCompletions> m => PostProcessChatCompletions(m),
_ when strictMode is false => message,
_ => throw new InvalidOperationException($"Invalid return message type {message.GetType().Name}"),
};
}
public IMessage? PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate> update, string? currentToolName)
{
if (update.Content.ContentUpdate is string contentUpdate && string.IsNullOrEmpty(contentUpdate) == false)
{
// text message
return new TextMessageUpdate(Role.Assistant, contentUpdate, from: update.From);
}
else if (update.Content.FunctionName is string functionName)
{
return new ToolCallMessageUpdate(functionName, string.Empty, from: update.From);
}
else if (update.Content.FunctionArgumentsUpdate is string functionArgumentsUpdate && currentToolName is string)
{
return new ToolCallMessageUpdate(currentToolName, functionArgumentsUpdate, from: update.From);
}View on GitHub (pinned to 027ecf0a37)
Solutions
- Return a TextMessage or ToolCallMessage as the final reply
Example fix
Ensure the agent's final reply is a supported IMessage type
When it happens
Trigger: Thrown at dotnet/src/AutoGen.AzureAIInference/Middleware/AzureAIInferenceChatRequestMessageConnector.cs:98 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/d0ac5e9d5e67a028.
Report an issue: GitHub.