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
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.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs:333
ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),
_ => throw new NotImplementedException(),
});
return [new ChatRequestUserMessage(items) { Name = message.From }];
}
private ChatMessageImageContentItem CreateChatMessageImageContentItemFromImageMessage(ImageMessage message)
{
return message.Data is null && message.Url is not null
? new ChatMessageImageContentItem(new Uri(message.Url))
: new ChatMessageImageContentItem(message.Data, message.Data?.MediaType);
}
private IEnumerable<ChatRequestMessage> ProcessToolCallMessage(IAgent agent, ToolCallMessage message)
{
if (message.From is not null && message.From != agent.Name)
{
throw new ArgumentException("ToolCallMessage is not supported when message.From is not the same with agent");
}
var toolCall = message.ToolCalls.Select((tc, i) => new ChatCompletionsFunctionToolCall(tc.ToolCallId ?? $"{tc.FunctionName}_{i}", tc.FunctionName, tc.FunctionArguments));
var textContent = message.GetContent() ?? string.Empty;
// don't include the name field when it's tool call message.
// fix https://github.com/microsoft/autogen/issues/3437
var chatRequestMessage = new ChatRequestAssistantMessage(textContent);
foreach (var tc in toolCall)
{
chatRequestMessage.ToolCalls.Add(tc);
}
return [chatRequestMessage];
}
private IEnumerable<ChatRequestMessage> ProcessToolCallResultMessage(ToolCallResultMessage message)
{View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before var history = chatHistory; // contains other agent's ToolCallMessage await agent.SendAsync(history); // throws // after var history = chatHistory.Where(m => m is not ToolCallMessage tcm || tcm.From is null || tcm.From == agent.Name); await agent.SendAsync(history);
Defensive patterns
Strategy: validation
Validate before calling
var safeHistory = messages.Where(m => m is not ToolCallMessage tcm || tcm.From is null || tcm.From == agent.Name);
Type guard
static bool IsOwnToolCall(ToolCallMessage m, IAgent agent) => m.From is null || m.From == agent.Name;
Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("ToolCallMessage is not supported")) { /* convert foreign tool call to AggregateMessage and resend */ } Prevention
- Filter foreign ToolCallMessages per-agent when replaying group chat history
- Keep a single function-calling agent per conversation or partition tools
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to review code block
- ImageMessage is not supported when message.From is the same
- MultiModalMessage is not supported when message.From is the
- No coder message found
- No user message found.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/2f2a50072803b090.
Report an issue: GitHub.