microsoft/autogen · error · ArgumentException

ToolCallMessage is not supported when message.From is not th

Error message

ToolCallMessage is not supported when message.From is not the same with agent

What it means

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.

Source

Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:89

                    return [msg];
                }
                else
                {
                    var msg = new ChatRequestUserMessage(textMessage.Content);
                    return [msg];
                }
            }
            else if (message is ImageMessage imageMessage)
            {
                // multi-modal
                var msg = new ChatRequestUserMessage(new ChatMessageImageContentItem(new Uri(imageMessage.Url ?? imageMessage.BuildDataUri())));

                return [msg];
            }
            else if (message is ToolCallMessage)
            {
                throw new ArgumentException($"ToolCallMessage is not supported when message.From is not the same with agent");
            }
            else if (message is ToolCallResultMessage toolCallResult)
            {
                return toolCallResult.ToolCalls.Select(m =>
                {
                    var msg = new ChatRequestToolMessage(m.Result, m.FunctionName);

                    return msg;
                });
            }
            else if (message is MultiModalMessage multiModalMessage)
            {
                var messageContent = multiModalMessage.Content.Select<IMessage, ChatMessageContentItem>(m =>
                {
                    return m switch
                    {
                        TextMessage textMessage => new ChatMessageTextContentItem(textMessage.Content),
                        ImageMessage imageMessage => new ChatMessageImageContentItem(new Uri(imageMessage.Url ?? imageMessage.BuildDataUri())),

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Don't forward raw ToolCallMessage between agents; convert to a ToolCallResultMessage or TextMessage first
  2. In group-chat selection logic, route tool-call messages only to the agent that issued them (From == agent.Name)
  3. Filter message lists per recipient: drop other agents' ToolCallMessage entries

Example fix

// before
var shared = new List<IMessage> { bToolCall }; // ToolCallMessage from agent "B"
await agentA.SendAsync(shared, ctx); // throws for agentA

// after
var forA = shared.Where(m => m is not ToolCallMessage || m.From == agentA.Name);
await agentA.SendAsync(forA, ctx);
Defensive patterns

Strategy: validation

Validate before calling

IEnumerable<IMessage> FilterForAgent(IEnumerable<IMessage> msgs, string agentName) =>
    msgs.Where(m => m is not ToolCallMessage || m.From == agentName);

Type guard

static bool IsForeignToolCall(IMessage m, string agentName) =>
    m is ToolCallMessage && m.From != agentName;

Try / catch

catch (ArgumentException ex) when (ex.Message.Contains("ToolCallMessage is not supported"))
{
    var asText = new TextMessage(Role.User, $"{msg.From} invoked a tool");
    return await agent.SendAsync(asText);
}

Prevention

When it happens

Trigger: 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.

Common situations: Multi-agent function-calling workflows that share a single message list; orchestration middleware that broadcasts every message (including tool calls) to all participants.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/305e4b1938beb4dd. Report an issue: GitHub.