{"record":{"id":"adae22d8aab19f69","repo":"microsoft/autogen","slug":"invalid-message-as-message-from-self","errorCode":null,"errorMessage":"Invalid Message as message from self.","messagePattern":"Invalid Message as message from self\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":239,"sourceCode":"            {\n                return new[] { new ChatRequestToolMessage(content, message.FunctionName) };\n            }\n        }\n        else if (message.FunctionName is string functionName)\n        {\n            var msg = new ChatRequestAssistantMessage(content: null)\n            {\n                FunctionCall = new FunctionCall(functionName, message.FunctionArguments)\n            };\n\n            return new[]\n            {\n                msg,\n            };\n        }\n        else\n        {\n            throw new InvalidOperationException(\"Invalid Message as message from self.\");\n        }\n    }\n\n    [Obsolete(\"This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.\")]\n    private IEnumerable<ChatRequestMessage> ProcessIncomingMessagesForOther(Message message)\n    {\n        if (message.Role == Role.System)\n        {\n            return [new ChatRequestSystemMessage(message.Content) { Name = message.From }];\n        }\n        else if (message.Content is string content && content is { Length: > 0 })\n        {\n            if (message.FunctionName is not null)\n            {\n                return new[] { new ChatRequestToolMessage(content, message.FunctionName) };\n            }\n\n            return [new ChatRequestUserMessage(message.Content) { Name = message.From }];","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nhistory.Add(new Message(Role.Assistant, null, from: agent.Name)); // throws\n\n// after\nhistory.Add(new ToolCallMessage(functionName, args, from: agent.Name));","handlingStrategy":"validation","validationCode":"// before sending legacy Message from self, ensure it is representable\nif (msg is Message { From: var from } lm && from == agent.Name && lm.FunctionName is null) { /* replace with ToolCallMessage/TextMessage */ }","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message == \"Invalid Message as message from self.\") { /* drop or convert the legacy message */ }","preventionTips":["Migrate off the obsolete Message type","Never create self-messages without content or function call","Validate replayed histories before injection"],"tags":["autogen","dotnet","azure-openai","legacy-message","deprecated"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}