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
ProcessToolCallMessage converts an assistant's function-call message into an AssistantChatMessage with tool-call parts. This is only valid for the agent that issued the calls (tool call results must be attributed to the same assistant in OpenAI's protocol), so a ToolCallMessage authored by a different agent is rejected.
Source
Thrown at dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs:306
ImageMessage image => this.CreateChatMessageImageContentItemFromImageMessage(image),
_ => throw new NotImplementedException(),
});
return [new UserChatMessage(items) { ParticipantName = message.From }];
}
private ChatMessageContentPart CreateChatMessageImageContentItemFromImageMessage(ImageMessage message)
{
return message.Data is null && message.Url is not null
? ChatMessageContentPart.CreateImagePart(new Uri(message.Url))
: ChatMessageContentPart.CreateImagePart(message.Data, message.Data?.MediaType);
}
private IEnumerable<ChatMessage> 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 toolCallParts = message.ToolCalls.Select((tc, i) => ChatToolCall.CreateFunctionToolCall(tc.ToolCallId ?? $"{tc.FunctionName}_{i}", tc.FunctionName, BinaryData.FromString(tc.FunctionArguments)));
var textContent = message.GetContent() ?? null;
// Don't set participant name for assistant when it is tool call
// fix https://github.com/microsoft/autogen/issues/3437
AssistantChatMessage chatRequestMessage;
if (string.IsNullOrEmpty(textContent) is true)
{
chatRequestMessage = new AssistantChatMessage(toolCallParts);
}
else
{
chatRequestMessage = new AssistantChatMessage(textContent);
foreach (var toolCallPart in toolCallParts)View on GitHub (pinned to 027ecf0a37)
Solutions
- Only forward a ToolCallMessage to the agent whose name matches message.From.
- Set From to null if the tool call should be attributed to the receiving agent.
- Filter other agents' tool calls out of the history: keep only ToolCallResultMessage pairs for the owning agent.
Example fix
// before
var toolCallFromOther = new ToolCallMessage(toolCalls, from: "agent-a");
await agentB.SendAsync(new[] { toolCallFromOther });
// after
var toolCallForSelf = new ToolCallMessage(toolCalls, from: agentB.Name);
await agentB.SendAsync(new[] { toolCallForSelf }); Defensive patterns
Strategy: validation
Validate before calling
// Route tool-call messages only to their author var forThisAgent = messages.Where(m => m is not ToolCallMessage tc || tc.From is null || tc.From == agent.Name);
Type guard
static bool ToolCallBelongsToAgent(ToolCallMessage tc, string agentName) =>
tc.From is null || tc.From == agentName; Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("ToolCallMessage is not supported"))
{
logger.LogWarning("Dropping foreign tool call from {From}", foreignFrom);
return await agent.SendAsync(messages.Where(m => m is not ToolCallMessage tc || tc.From == agent.Name));
} Prevention
- In multi-agent flows, pair each ToolCallMessage with its owning agent before dispatch.
- Set From to null only when the receiving agent is genuinely the author.
When it happens
Trigger: message.From is non-null and differs from agent.Name while the connector's incoming-message switch routes the ToolCallMessage to this handler (the arm requires From == null or From == agent.Name, but this method double-checks and throws for mismatched senders in code paths that reach it directly).
Common situations: Group chats where one agent's tool calls land in another agent's context; manually forwarded tool-call messages between agents.
Related errors
- ImageMessage is not supported when message.From is the same
- MultiModalMessage is not supported when message.From is the
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
- Invalid message type
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/2083cfb5320a8bf0.
Report an issue: GitHub.