Class MessageWindowChatMemory

java.lang.Object
org.springframework.ai.chat.memory.MessageWindowChatMemory
All Implemented Interfaces:
ChatMemory

public final class MessageWindowChatMemory extends Object implements ChatMemory
A chat memory implementation that maintains a message window of a specified size, ensuring that the total number of messages does not exceed the specified limit. When the number of messages exceeds the maximum size, older messages are evicted.

Messages of type SystemMessage are treated specially: if a new SystemMessage is added, all previous SystemMessage instances are removed from the memory. Also, if the total number of messages exceeds the limit, the SystemMessage messages are preserved while evicting other types of messages.

Since:
1.0.0
Author:
Thomas Vitale