{"record":{"id":"305e4b1938beb4dd","repo":"microsoft/autogen","slug":"toolcallmessage-is-not-supported-when-message-from-305e4b","errorCode":null,"errorMessage":"ToolCallMessage is not supported when message.From is not the same with agent","messagePattern":"ToolCallMessage is not supported when message\\.From is not the same with agent","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs","lineNumber":89,"sourceCode":"\n                    return [msg];\n                }\n                else\n                {\n                    var msg = new ChatRequestUserMessage(textMessage.Content);\n                    return [msg];\n                }\n            }\n            else if (message is ImageMessage imageMessage)\n            {\n                // multi-modal\n                var msg = new ChatRequestUserMessage(new ChatMessageImageContentItem(new Uri(imageMessage.Url ?? imageMessage.BuildDataUri())));\n\n                return [msg];\n            }\n            else if (message is ToolCallMessage)\n            {\n                throw new ArgumentException($\"ToolCallMessage is not supported when message.From is not the same with agent\");\n            }\n            else if (message is ToolCallResultMessage toolCallResult)\n            {\n                return toolCallResult.ToolCalls.Select(m =>\n                {\n                    var msg = new ChatRequestToolMessage(m.Result, m.FunctionName);\n\n                    return msg;\n                });\n            }\n            else if (message is MultiModalMessage multiModalMessage)\n            {\n                var messageContent = multiModalMessage.Content.Select<IMessage, ChatMessageContentItem>(m =>\n                {\n                    return m switch\n                    {\n                        TextMessage textMessage => new ChatMessageTextContentItem(textMessage.Content),\n                        ImageMessage imageMessage => new ChatMessageImageContentItem(new Uri(imageMessage.Url ?? imageMessage.BuildDataUri())),","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs#L71-L107","documentation":"In ToOpenAIChatRequestMessage this ArgumentException fires when a ToolCallMessage arrives with From different from the receiving agent's name. An assistant tool-call can only be converted in the 'own message' branch (where it becomes ChatRequestAssistantMessage with tool calls); as a foreign message there is no valid OpenAI representation.","triggerScenarios":"Group-chat history replay where agent B's ToolCallMessage (From = \"B\") is sent to agent A; forwarding tool-call messages between agents without converting them to results or text first.","commonSituations":"Multi-agent function-calling workflows that share a single message list; orchestration middleware that broadcasts every message (including tool calls) to all participants.","solutions":["Don't forward raw ToolCallMessage between agents; convert to a ToolCallResultMessage or TextMessage first","In group-chat selection logic, route tool-call messages only to the agent that issued them (From == agent.Name)","Filter message lists per recipient: drop other agents' ToolCallMessage entries"],"exampleFix":"// before\nvar shared = new List<IMessage> { bToolCall }; // ToolCallMessage from agent \"B\"\nawait agentA.SendAsync(shared, ctx); // throws for agentA\n\n// after\nvar forA = shared.Where(m => m is not ToolCallMessage || m.From == agentA.Name);\nawait agentA.SendAsync(forA, ctx);","handlingStrategy":"validation","validationCode":"IEnumerable<IMessage> FilterForAgent(IEnumerable<IMessage> msgs, string agentName) =>\n    msgs.Where(m => m is not ToolCallMessage || m.From == agentName);","typeGuard":"static bool IsForeignToolCall(IMessage m, string agentName) =>\n    m is ToolCallMessage && m.From != agentName;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"ToolCallMessage is not supported\"))\n{\n    var asText = new TextMessage(Role.User, $\"{msg.From} invoked a tool\");\n    return await agent.SendAsync(asText);\n}","preventionTips":["Route tool-call messages only to their issuing agent","Convert tool calls to text/result before cross-agent forwarding","Per-recipient history filtering in group chats"],"tags":["openai","tool-call","group-chat","message-routing"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}