Skip to content

Add Option to Store All User Messages in MessageChatMemoryAdvisor #4589

@w9lsky

Description

@w9lsky

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions