spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

fix(MessageChatMemory) When adding data to Message Chat Memory Data, the actual data was not replaced

Open zhangshenghang opened this issue 7 months ago • 1 comments

When I use something like ReReadingAdvisor, I will use {re2_input_query} for parameter substitution.

image

However, when MessageChatMemoryAdvisor executes this.getChatMemoryStore().add, it does not perform replacement and will directly save {re2_input_query} to ChatMemory. This is incorrect.

// 4. Add the new user input to the conversation memory.
		UserMessage userMessage = new UserMessage(request.userText(), request.media());
		this.getChatMemoryStore().add(this.doGetConversationId(request.adviseContext()), userMessage);

image

We need to replace {re2_input_query} with real content. Modified code:

String processedUserText = request.userText();
		if (!CollectionUtils.isEmpty(request.userParams())) {
			processedUserText = new PromptTemplate(processedUserText, request.userParams()).render();
		}
		UserMessage userMessage = new UserMessage(processedUserText, request.media());

		this.getChatMemoryStore().add(this.doGetConversationId(request.adviseContext()), userMessage);

zhangshenghang avatar Apr 18 '25 07:04 zhangshenghang