PrismMessageMemory class

Conversation memory that trims old turns and can summarise them.

Wraps a List<AiChatMessage> and keeps the most recent turns within a token budget. When the budget is exceeded, the oldest turns are removed. Optionally, a summarise callback is invoked with the removed turns so the caller can store a summary and inject it as a system message.

final memory = PrismMessageMemory(
  maxMessages: 20,
  onSummarise: (removed) => print('${removed.length} turns dropped'),
);
memory.add(AiChatMessage.user('Hello'));
memory.add(AiChatMessage.assistant('Hi!'));

// Pass to the client:
client.streamChat(memory.messages, model: 'gpt-4o-mini');

Constructors

PrismMessageMemory({int maxMessages = 20, void onSummarise(List<AiChatMessage> removed)?, bool keepSystemMessages = true})
Creates conversation memory.

Properties

hashCode → int
The hash code for this object.
no setterinherited
keepSystemMessages → bool
Whether system messages are excluded from trimming.
final
maxMessages → int
Maximum number of messages kept.
final
messages → List<AiChatMessage>
All messages currently in memory.
no setter
onSummarise → void Function(List<AiChatMessage> removed)?
Called with the removed messages when trimming.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(AiChatMessage message) → void
Adds a message and trims if necessary.
addAll(Iterable<AiChatMessage> messages) → void
Adds several messages and trims if necessary.
clear() → void
Clears all messages.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited