ConversationBufferMemory class final

Buffer for storing a conversation in-memory and then retrieving the messages at a later time.

It uses ChatMessageHistory as in-memory storage by default.

Example:

final memory = ConversationBufferMemory();
await memory.saveContext({'foo': 'bar'}, {'bar': 'foo'});
final res = await memory.loadMemoryVariables();
// {'history': 'Human: bar\nAI: foo'}
Inheritance

Constructors

ConversationBufferMemory.new({BaseChatMessageHistory? chatHistory, String? inputKey, String? outputKey, bool returnMessages = false, String memoryKey = BaseMemory.defaultMemoryKey, String systemPrefix = SystemChatMessage.defaultPrefix, String humanPrefix = HumanChatMessage.defaultPrefix, String aiPrefix = AIChatMessage.defaultPrefix, String toolPrefix = ToolChatMessage.defaultPrefix})
Buffer for storing a conversation in-memory and then retrieving the messages at a later time.

Properties

aiPrefix String
The prefix to use for AI messages if returnMessages is false.
final
chatHistory BaseChatMessageHistory
The chat history.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
humanPrefix String
The prefix to use for human messages if returnMessages is false.
final
inputKey String?
The input key to use for the chat history.
finalinherited
memoryKey String
The memory key to use for the chat history. This will be passed as input variable to the prompt.
final
memoryKeys Set<String>
Input keys this memory class will load dynamically to the prompt.
no setteroverride
outputKey String?
The output key to use for the chat history.
finalinherited
returnMessages bool
If true, when loadMemoryVariables is called, it will return ChatMessage objects. If false, it will return a String representation of the messages.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
systemPrefix String
The prefix to use for system messages if returnMessages is false.
final
toolPrefix String
The prefix to use for tool messages if returnMessages is false.
final

Methods

clear() Future<void>
Clear memory contents.
inherited
loadMemoryVariables([MemoryInputValues values = const {}]) Future<MemoryVariables>
Returns key-value pairs given the MemoryInputValues.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
saveContext({required MemoryInputValues inputValues, required MemoryOutputValues outputValues}) Future<void>
Save the context of this model run to memory.
inherited
toString() String
A string representation of this object.
inherited

Operators

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