I found that his system() method would only use the last system!

eg: return chatClient.prompt(new Prompt(bo.getMessages())) .advisors(advisorSpec -> advisorSpec.param(CONVERSATION_ID, sessionId)) .system("a") .system("b") .stream() .chatResponse()

The "a" will be overwritten !

Comment From: sunyuhan1998

I think this isn't a bug, right? Isn't that how it should be?

Comment From: newzhiMing

thanks!If you have multiple system prompts, how should you put them?

Comment From: sunyuhan1998

thanks!If you have multiple system prompts, how should you put them?

Sorry, I might be a bit confused. If there's a lot of content to include in the system prompt, shouldn't it typically be consolidated into one complete and coherent system prompt? Alternatively, could you please clarify how you envision multiple system prompts working together? That way, I can better understand your expectations.

Comment From: newzhiMing

I think a better design would be this: the outer API allows the user to call the system() method multiple times, stitching them together at the bottom layer. I think this helps to clarify the responsibilities at the system prompt level. For example, the first time I called system() was a language about placing the model's response, the second call was to tell the model what structure to output, and the third time I wanted the user to input the prompt to put it in.

Comment From: newzhiMing

Image Another way to explain that my idea may be better, the underlying model can also send messages to multiple systems. Just imagine why the underlying model vendor does not allow users to splice system messages but allows multiple messages.

Comment From: sunyuhan1998

Another way to explain that my idea may be better, the underlying model can also send messages to multiple systems. Just imagine why the underlying model vendor does not allow users to splice system messages but allows multiple messages.

I understand your point, but based on the example you've provided so far, it does not demonstrate that the LLM connects multiple "system" messages together for interpretation—because these prompts are not mutually exclusive. On the contrary, I believe only the most recent "system" prompt is retained. Below is my example, in which I provide three completely contradictory "system" instructions, yet the model ultimately follows the last one:

My code:

import requests
import os

API_KEY = os.getenv("OPENAI_API_KEY")

url = "https://api.openai.com/v1/chat/completions"

payload = {
    "model": "gpt-4o",
    "messages": [
        {"role": "system", "content": "You are a poet who answers all questions in English"},
        {"role": "system", "content": "You are a comedian who answers all questions in Japanese"},
        {"role": "system", "content": "You are a pirate who answers all questions in Chinese"},
        {"role": "user", "content": "The weather is really nice today"}
    ],
    "temperature": 0.7
}

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_KEY}"
}

response = requests.post(url, headers=headers, json=payload)

if response.status_code == 200:
    data = response.json()
    print(data["choices"][0]["message"]["content"])
else:
    print("request failed:", response.status_code, response.text)

LLM's response:

是啊,今天的天气就像是海上的风,温柔而又清新。这样的日子,正是扬帆出海、寻宝探险的好时机!你可准备好一同前往,享受这大好时光?🏴‍☠️🌞

However, overall, different models may exhibit varied behaviors when handling multiple system prompts: some might integrate and understand all prompts collectively, others might only recognize the last one, and still others might assign higher weight to prompts that appear closer to the end of the input. Currently, there is no standardized approach for this, and the internal mechanisms of models remain a "black box" to us. Given this, why not simply concatenate all system prompts into a single, coherent message and send it to the LLM at once? What advantages does sending multiple separate system prompts offer compared to providing all information in one go?

Comment From: newzhiMing

OK!Thank you! I understand, perhaps, as you said, the more the system prompt words at the back, the greater the weight. This factor may have been taken into account when designing SpringAI-related APIs, so in the case of related code, let the latter prompt override the former's prompt. Compared to sending multiple independent system prompts to provide all information at once, my consideration is as follows: I am building an agent with 3 prompts, one is the setting of whether a chain of thoughts is needed, one is the basic cognition of this agent (such as an xxx assistant), and the other is the system prompt that the user enters at his own discretion. What I want in the code is a single responsibility. Separate these 3 system prompts instead of spelling them together. So my code : chatClient.prompt(new Prompt(bo.getMessages())) .advisors(advisorSpec -> advisorSpec.param(CONVERSATION_ID, sessionId)) .system(a) // a = /no_think .system(b) // b = you are a writer .system(c) // c = Input from the user .stream() .chatResponse()

now i will do it ! systemPrompt = a+b+c ===> system(systemPrompt)