microsoft/autogen · error · ArgumentException
System message is not supported when message.From is the…
Error message
System message is not supported when message.From is the same with agent
What it means
In the own-message branch (message.From == agent.Name) of the deprecated conversion, a TextMessage with Role.System throws. Messages attributed to the agent map to ChatRequestAssistantMessage; an assistant-role slot cannot carry a system prompt, so the combination is rejected instead of silently mislabeling it.
Solutions
- Keep system prompts out of the replayed history; supply them via systemMessage at agent construction
- When echoing history, set From = null (or the true sender) for system-role messages
- Filter Role.System messages out of anything you forward back to the agent
Example fix
// before var replayed = new TextMessage(Role.System, systemPrompt, from: agent.Name); await agent.SendAsync(replayed); // after // system prompt handled at construction: var agent = new OpenAIChatAgent(client, "gpt", options, systemMessage: systemPrompt); // history replay contains only user/assistant messages
Defensive patterns
Strategy: validation
Validate before calling
bool ok = textMsg.Role != Role.System || textMsg.From != agent.Name; if (!ok) textMsg = new TextMessage(Role.User, textMsg.Content, from: null);
Type guard
static bool IsOwnSystemMessage(TextMessage m, string agentName) =>
m.Role == Role.System && m.From == agent.Name; Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("System message is not supported"))
{
var demoted = new TextMessage(Role.User, textMsg.Content, from: null);
return await agent.SendAsync(demoted);
} Prevention
- Never attribute system messages to the agent itself
- Set system prompts at construction time
- Filter Role.System turns during history replay
When it happens
Trigger: Replaying a system message whose From was set to the agent's name (e.g. echoing the whole conversation, including the system turn, back with From rewritten) into the same agent.
Common situations: History replay loops that stamp From = agent.Name on every prior turn; copying the agent's system message into the chat as a TextMessage and then attributing it to the agent.
Related errors
- Multiple and Not continuous system messages are not…
- Assistant not initialized
- Content is null
- Content is null and metadata is null
- Error in coding document with OpenAI
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/5bd2aed7954cf4e5.
Report an issue: GitHub.
Appendix: source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:161
}
else
{
var userMessage = new ChatRequestUserMessage(msg.Content ?? throw new ArgumentException("Content is null"));
return [userMessage];
}
}
else
{
throw new ArgumentException($"Unknown message type: {message.GetType()}");
}
}
else
{
if (message is TextMessage textMessage)
{
if (textMessage.Role == Role.System)
{
throw new ArgumentException("System message is not supported when message.From is the same with agent");
}
return [new ChatRequestAssistantMessage(textMessage.Content)];
}
else if (message is ToolCallMessage toolCallMessage)
{
var assistantMessage = new ChatRequestAssistantMessage(string.Empty);
var toolCalls = toolCallMessage.ToolCalls.Select(tc => new ChatCompletionsFunctionToolCall(tc.FunctionName, tc.FunctionName, tc.FunctionArguments));
foreach (var tc in toolCalls)
{
assistantMessage.ToolCalls.Add(tc);
}
return [assistantMessage];
}
else if (message is AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage)
{
var toolCallMessage1 = aggregateMessage.Message1;View on GitHub (pinned to 027ecf0a37)