Please find sample code and logs.
` @Bean public ChatClient chatClient(ChatClient.Builder builder, VectorStore vectorStore, MessageChatMemoryAdvisor messageChatMemoryAdvisor, QuestionAnswerAdvisor questionAnswerAdvisor) { return builder .defaultAdvisors(questionAnswerAdvisor, messageChatMemoryAdvisor, new SimpleLoggerAdvisor()) .defaultSystem(""" You are a helpful assistant. Do not add what you had received in context in a response. Please also check conversion history to answer the question. Always answer in a concise manner. Please answer the user's question in good format so user can read it easily. Please do not include HTML tags in your response.
""")
.build();
}
@Bean public QuestionAnswerAdvisor questionAnswerAdvisor(VectorStore vectorStore) { return QuestionAnswerAdvisor .builder(vectorStore) .searchRequest( SearchRequest.builder() .topK(10) .build()) .build(); }
@Bean
public MessageChatMemoryAdvisor messageChatMemoryAdvisor(ChatMemoryRepository chatMemoryRepository) {
ChatMemory chatMemory = MessageWindowChatMemory.builder()
.chatMemoryRepository(chatMemoryRepository)
.maxMessages(20)
.build();
return MessageChatMemoryAdvisor.builder(chatMemory).build();
}
@GetMapping("/chat")
public Flux
chatMemory.get(conversationId);
return chatClient.prompt()
.user(message)
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.stream()
.content();
}
`
Logs.
2025-08-21T16:51:04.918+05:30 DEBUG 57428 --- [OpenAI-Integration-Demo] [oundedElastic-1] o.s.a.c.c.advisor.SimpleLoggerAdvisor :
request:
ChatClientRequest[prompt=Prompt{messages=[UserMessage{content='"who I am"', properties={messageType=USER}, messageType=USER}, AssistantMessage [messageType=ASSISTANT, toolCalls=[], textContent=I'm sorry, but I can't answer that question based on the provided context., metadata={role=ASSISTANT, messageType=ASSISTANT, finishReason=STOP, refusal=, index=0, annotations=[], id=chatcmpl-C6xdWFsjdt4Hac0b6RA58J10Fmi6N}], UserMessage{content='"I am Rajan"', properties={messageType=USER}, messageType=USER}, AssistantMessage [messageType=ASSISTANT, toolCalls=[], textContent=Hello Rajan! How can I assist you today?, metadata={role=ASSISTANT, messageType=ASSISTANT, finishReason=STOP, refusal=, index=0, annotations=[], id=chatcmpl-C6xdgRxNXapARS92kqquSWmDM4oKF}], SystemMessage{textContent='You are a helpful assistant. Do not add what you had received in context in a response. Please also check conversion history to answer the question. Always answer in a concise manner. Please answer the user's question in good format so user can read it easily. Please do not include HTML tags in your response.
', messageType=SYSTEM, metadata={messageType=SYSTEM}}, UserMessage{content='"who I am"', properties={messageType=USER}, messageType=USER}], modelOptions=OpenAiChatOptions: {"streamUsage":false,"model":"gpt-4o-mini","temperature":0.7}}, context={chat_memory_conversation_id="test"}]
2025-08-21T16:51:06.840+05:30 DEBUG 57428 --- [OpenAI-Integration-Demo] [oundedElastic-1] o.s.a.c.c.advisor.SimpleLoggerAdvisor :
response: { "result" : { "metadata" : { "finishReason" : "STOP", "contentFilters" : [ ], "empty" : true }, "output" : { "messageType" : "ASSISTANT", "metadata" : { "role" : "ASSISTANT", "messageType" : "ASSISTANT", "finishReason" : "STOP", "refusal" : "", "index" : 0, "annotations" : [ ], "id" : "chatcmpl-C6xdprVd2sct73uPdueTRf8upzcCB" }, "toolCalls" : [ ], "media" : [ ], "text" : "I'm sorry, but I can't answer that question based on the provided context." } }, "metadata" : { "id" : "chatcmpl-C6xdprVd2sct73uPdueTRf8upzcCB", "model" : "gpt-4o-mini-2024-07-18", "rateLimit" : { "requestsReset" : 0.0, "tokensReset" : 0.0, "tokensLimit" : 0, "tokensRemaining" : 0, "requestsLimit" : 0, "requestsRemaining" : 0 }, "usage" : { "promptTokens" : 0, "completionTokens" : 0, "totalTokens" : 0, "nativeUsage" : { "promptTokens" : 0, "totalTokens" : 0, "completionTokens" : 0 } }, "promptMetadata" : [ ], "empty" : true }, "results" : [ { "metadata" : { "finishReason" : "STOP", "contentFilters" : [ ], "empty" : true }, "output" : { "messageType" : "ASSISTANT", "metadata" : { "role" : "ASSISTANT", "messageType" : "ASSISTANT", "finishReason" : "STOP", "refusal" : "", "index" : 0, "annotations" : [ ], "id" : "chatcmpl-C6xdprVd2sct73uPdueTRf8upzcCB" }, "toolCalls" : [ ], "media" : [ ], "text" : "I'm sorry, but I can't answer that question based on the provided context." } } ] }
Comment From: LoperLee
Hi @weare3, I think this issue is related to #4170.