spring-projects / spring-projects/spring-ai

Add Option to Store All User Messages in MessageChatMemoryAdvisor

Open
#4,589 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

advisors chat memory
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Expected Behavior

The MessageChatMemoryAdvisor should provide a configuration option to store all user messages in conversation history instead of only the latest one. This would enable preserving complete conversation context for applications that require full dialogue history.

// Example usage
ChatMemory chatMemory = MessageWindowChatMemory.builder().build();

MessageChatMemoryAdvisor advisor = MessageChatMemoryAdvisor.builder(chatMemory)
    .storeAllUserMessages(true)  // Store all user messages instead of just the latest
    .build();

Current Behavior

Currently, MessageChatMemoryAdvisor only stores the most recent UserMessage in chat memory, overwriting previous user messages. This approach loses conversation context in multi-turn dialogs where the full history is needed for proper context understanding. Applications requiring complete conversation history cannot achieve this with the current implementation.

Context

This feature is needed for applications that require maintaining complete conversation history, such as:
Complex multi-turn conversations where context from earlier exchanges is crucial
Audit trails that need to preserve all user interactions
Applications with long-running conversations where context from multiple previous turns is relevant
Without this feature, developers would need to implement custom memory management solutions, which adds complexity and reduces the value of the existing MessageChatMemoryAdvisor. The workaround of manually managing conversation history outside the advisor defeats the purpose of having a built-in memory management solution.
This enhancement would provide flexibility to choose between two memory management strategies while maintaining backward compatibility:
Store only the latest user message (current default behavior) - suitable for memory-constrained scenarios
Store all user messages (new option) - suitable for applications requiring complete conversation history

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating MessageChatMemoryAdvisor and the ChatMemory/MessageWindowChatMemory entry points referenced in the example. Trace how the current latest UserMessage is stored, then verify the new configuration preserves the existing default while enabling all user messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.