{"record":{"id":"d7a3efffa43e14eb","repo":"microsoft/semantic-kernel","slug":"a-system-message-is-provided-by-the-agent-and-shou","errorCode":null,"errorMessage":"A system message is provided by the agent and should not be included in the chat history.","messagePattern":"A system message is provided by the agent and should not be included in the chat history\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.ApiService/Controllers/AgentCompletionsController.cs","lineNumber":111,"sourceCode":"            this._agent.InvokeStreamingAsync(thread, options: new() { KernelArguments = arguments }, cancellationToken: cancellationToken);\n\n        await foreach (StreamingChatMessageContent item in content.ConfigureAwait(false))\n        {\n            yield return item;\n        }\n    }\n\n    /// <summary>\n    /// Validates the chat history.\n    /// </summary>\n    /// <param name=\"chatHistory\">The chat history to validate.</param>\n    private static void ValidateChatHistory(ChatHistory chatHistory)\n    {\n        foreach (ChatMessageContent content in chatHistory)\n        {\n            if (content.Role == AuthorRole.System)\n            {\n                throw new ArgumentException(\"A system message is provided by the agent and should not be included in the chat history.\");\n            }\n        }\n    }\n}\n","sourceCodeStart":93,"sourceCodeEnd":116,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.ApiService/Controllers/AgentCompletionsController.cs#L93-L116","documentation":"Error \"A system message is provided by the agent and should not be included in the chat history.\" thrown in microsoft/semantic-kernel.","triggerScenarios":"Thrown at dotnet/samples/Demos/AgentFrameworkWithAspire/ChatWithAgent.ApiService/Controllers/AgentCompletionsController.cs:111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove any message with role 'system' from the chat history before sending it; the agent supplies its own system message.","Filter the incoming chat history to exclude system-role messages prior to invoking the agent."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}