Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create. If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description When we use the chatClient class with "defaultSystem" and "MessageChatMemoryAdvisor", when making the call to OpenAI with a message history, the first element of the array is not of role "system"

Image

Environment Spring AI: 1.0.0-M5 Java version: 21.0.5-zulu

Steps to reproduce I created a chatClient linked to a "defaultSystem" and with the "MessageChatMemoryAdvisor", and checked the order of the messages sent to OpenAI.

Expected behavior The default system message will always be the first message in the array sent to OpenAI.

Minimal Complete Reproducible example Please provide a failing test or a minimal complete verifiable example that reproduces the issue. Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

Comment From: ThomasVitale

Thanks for reporting this issue. I would recommend addressing this together with https://github.com/spring-projects/spring-ai/issues/873, making sure to implement a consistent and predictable strategy for placing system messages across different use cases.