{"record":{"id":"2f2a50072803b090","repo":"microsoft/autogen","slug":"toolcallmessage-is-not-supported-when-message-from-2f2a50","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/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":333,"sourceCode":"            ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),\n            _ => throw new NotImplementedException(),\n        });\n\n        return [new ChatRequestUserMessage(items) { Name = message.From }];\n    }\n\n    private ChatMessageImageContentItem CreateChatMessageImageContentItemFromImageMessage(ImageMessage message)\n    {\n        return message.Data is null && message.Url is not null\n            ? new ChatMessageImageContentItem(new Uri(message.Url))\n            : new ChatMessageImageContentItem(message.Data, message.Data?.MediaType);\n    }\n\n    private IEnumerable<ChatRequestMessage> ProcessToolCallMessage(IAgent agent, ToolCallMessage message)\n    {\n        if (message.From is not null && message.From != agent.Name)\n        {\n            throw new ArgumentException(\"ToolCallMessage is not supported when message.From is not the same with agent\");\n        }\n\n        var toolCall = message.ToolCalls.Select((tc, i) => new ChatCompletionsFunctionToolCall(tc.ToolCallId ?? $\"{tc.FunctionName}_{i}\", tc.FunctionName, tc.FunctionArguments));\n        var textContent = message.GetContent() ?? string.Empty;\n\n        // don't include the name field when it's tool call message.\n        // fix https://github.com/microsoft/autogen/issues/3437\n        var chatRequestMessage = new ChatRequestAssistantMessage(textContent);\n        foreach (var tc in toolCall)\n        {\n            chatRequestMessage.ToolCalls.Add(tc);\n        }\n\n        return [chatRequestMessage];\n    }\n\n    private IEnumerable<ChatRequestMessage> ProcessToolCallResultMessage(ToolCallResultMessage message)\n    {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L315-L351","documentation":"ArgumentException thrown by ProcessToolCallMessage when a ToolCallMessage has a non-null From that differs from the agent's name. Tool/function calls are only valid inside the assistant's own history; a tool-call message attributed to a different agent cannot be replayed as this agent's assistant turn.","triggerScenarios":"A ToolCallMessage with From = 'OtherAgent' sent to agent 'A' (the connector's dispatch only routes ToolCallMessage to this method when From is null or equals agent.Name, so this fires when history isn't filtered).","commonSituations":"Group chat where one function-calling agent's ToolCallMessage lands in another function-calling agent's context; naive full-history replay in multi-agent orchestrators.","solutions":["When replaying history to agent X, drop ToolCallMessages whose From is neither null nor X","Convert other agents' tool calls into AggregateMessage<ToolCallMessage, ToolCallResultMessage>, which the connector handles for foreign senders","Have only one function-calling agent per conversation, or partition tool ownership"],"exampleFix":"// before\nvar history = chatHistory; // contains other agent's ToolCallMessage\nawait agent.SendAsync(history); // throws\n\n// after\nvar history = chatHistory.Where(m => m is not ToolCallMessage tcm || tcm.From is null || tcm.From == agent.Name);\nawait agent.SendAsync(history);","handlingStrategy":"validation","validationCode":"var safeHistory = messages.Where(m => m is not ToolCallMessage tcm || tcm.From is null || tcm.From == agent.Name);","typeGuard":"static bool IsOwnToolCall(ToolCallMessage m, IAgent agent) => m.From is null || m.From == agent.Name;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"ToolCallMessage is not supported\")) { /* convert foreign tool call to AggregateMessage and resend */ }","preventionTips":["Filter foreign ToolCallMessages per-agent when replaying group chat history","Keep a single function-calling agent per conversation or partition tools"],"tags":["autogen","dotnet","azure-openai","function-calling","group-chat"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}