microsoft/semantic-kernel · error · ArgumentException

A system message is provided by the agent and should not be

Error message

A system message is provided by the agent and should not be included in the chat history.

What it means

Error "A system message is provided by the agent and should not be included in the chat history." thrown in microsoft/semantic-kernel.

Source

Thrown at dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.ApiService/Controllers/AgentCompletionsController.cs:111

            this._agent.InvokeStreamingAsync(thread, options: new() { KernelArguments = arguments }, cancellationToken: cancellationToken);

        await foreach (StreamingChatMessageContent item in content.ConfigureAwait(false))
        {
            yield return item;
        }
    }

    /// <summary>
    /// Validates the chat history.
    /// </summary>
    /// <param name="chatHistory">The chat history to validate.</param>
    private static void ValidateChatHistory(ChatHistory chatHistory)
    {
        foreach (ChatMessageContent content in chatHistory)
        {
            if (content.Role == AuthorRole.System)
            {
                throw new ArgumentException("A system message is provided by the agent and should not be included in the chat history.");
            }
        }
    }
}

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Remove any message with role 'system' from the chat history before sending it; the agent supplies its own system message.
  2. Filter the incoming chat history to exclude system-role messages prior to invoking the agent.

When it happens

Trigger: Thrown at dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.ApiService/Controllers/AgentCompletionsController.cs:111 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/d7a3efffa43e14eb. Report an issue: GitHub.