We can use a simple List<ChatMessage> to create a multi-turn conversation (check out this example), but that is not same as using ChatMemory. In this tutorial we are going to see what the difference is.
Core Difference
List<ChatMessage> is just a data container, while ChatMemory is a managed conversation state system.
List<ChatMessage> (Manual Control)
A simple collection you manage completely yourself.
List<ChatMessage> messages = new ArrayList<>();
Your Responsibilities:
Adding messages in correct order
Removing old messages manually
Preventing unlimited growth
Managing session separation
Limitations:
No automatic message trimming
Easy to exceed token limits
No built-in strategies
No persistence support
ChatMemory (Managed System)
A contract defining how conversation history is managed.