microsoft/autogen · error · InvalidOperationException
Invalid Message as message from self.
Error message
Invalid Message as message from self.
What it means
Thrown from the legacy Message handling path (ProcessMessage) when a Message attributed to the agent itself has no function name (and no usable content), so it cannot be reconstructed as a ChatRequestAssistantMessage carrying a function call. It only occurs while processing a 'message from self' that is neither a function call nor representable text.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs:239
{
return new[] { new ChatRequestToolMessage(content, message.FunctionName) };
}
}
else if (message.FunctionName is string functionName)
{
var msg = new ChatRequestAssistantMessage(content: null)
{
FunctionCall = new FunctionCall(functionName, message.FunctionArguments)
};
return new[]
{
msg,
};
}
else
{
throw new InvalidOperationException("Invalid Message as message from self.");
}
}
[Obsolete("This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.")]
private IEnumerable<ChatRequestMessage> ProcessIncomingMessagesForOther(Message message)
{
if (message.Role == Role.System)
{
return [new ChatRequestSystemMessage(message.Content) { Name = message.From }];
}
else if (message.Content is string content && content is { Length: > 0 })
{
if (message.FunctionName is not null)
{
return new[] { new ChatRequestToolMessage(content, message.FunctionName) };
}
return [new ChatRequestUserMessage(message.Content) { Name = message.From }];View on GitHub (pinned to 027ecf0a37)
Solutions
- Migrate from the obsolete Message type to ToolCallMessage (for self function calls) or TextMessage(Role.Assistant)
- Ensure legacy self-messages always carry FunctionName+FunctionArguments when replayed
- Set strictMode: false does NOT help here — this throw is in the legacy branch; filter legacy messages out before sending
Example fix
// before history.Add(new Message(Role.Assistant, null, from: agent.Name)); // throws // after history.Add(new ToolCallMessage(functionName, args, from: agent.Name));
Defensive patterns
Strategy: validation
Validate before calling
// before sending legacy Message from self, ensure it is representable
if (msg is Message { From: var from } lm && from == agent.Name && lm.FunctionName is null) { /* replace with ToolCallMessage/TextMessage */ } Try / catch
catch (InvalidOperationException ex) when (ex.Message == "Invalid Message as message from self.") { /* drop or convert the legacy message */ } Prevention
- Migrate off the obsolete Message type
- Never create self-messages without content or function call
- Validate replayed histories before injection
When it happens
Trigger: A legacy Microsoft.AutoGen 'Message' whose From equals the agent name, whose FunctionName is null and content path doesn't apply, being fed into ProcessIncomingMessages with the deprecated Message branch active.
Common situations: Code still using the obsolete Message type instead of TextMessage/ToolCallMessage after upgrading AutoGen; replaying recorded conversations into an OpenAI.V1 agent; group chat history containing legacy self-messages.
Related errors
- Invalid Message as message from other.
- Please set AZURE_OPENAI_API_KEY environment variable.
- Please set AZURE_OPENAI_ENDPOINT environment variable.
- Please set environment variable AZURE_OPENAI_API_KEY
- Invalid return message type {message.GetType().Name}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/adae22d8aab19f69.
Report an issue: GitHub.