Class AgentMemory
Provides persistent memory storage and retrieval capabilities for conversational agents.
The AgentMemory
class uses a retrieval-augmented generation (RAG) engine to store text-based information in partitions and later recall the most relevant ones based on incoming messages.
This mechanism enhances multi-turn conversations by integrating additional context or previously stored information.
public sealed class AgentMemory : ISerializableData
- Inheritance
-
AgentMemory
- Implements
- Inherited Members
Constructors
- AgentMemory(LM)
Initializes a new instance of the AgentMemory class using the specified language model.
The provided language model is used to initialize the underlying RAG engine, which is essential for both storing and retrieving text partitions.
Properties
- DataSources
Gets the collection of data sources currently managed by the agent memory.
- Filter
Gets or sets the filtering criteria used to determine which memory entries are included during retrieval operations.
Methods
- AddDataSource(DataSource)
Adds a single data source to the agent memory.
- AddDataSources(IEnumerable<DataSource>)
Adds multiple data sources to the agent memory.
- Clear()
Clears all stored memory data by removing all data sources.
- Deserialize(byte[], LM)
Deserializes binary data from a byte array into an AgentMemory instance.
- Deserialize(Stream, LM)
Deserializes an AgentMemory instance from the provided stream.
The stream must contain binary data in the format produced by the Serialize(Stream) method.
- Deserialize(string, LM)
Deserializes binary data from the specified file into an AgentMemory instance.
The file must be in a valid format as produced by the Serialize(string) method.
- GetMemoryType(DataSource)
Retrieves the memory type associated with the specified data source based on its metadata.
- IsEmpty()
Determines whether any memory data has been stored.
- RemoveDataSource(DataSource)
Removes a specified data source from the agent memory.
- RemoveDataSource(string)
Removes a data source from the agent memory using its unique identifier.
- SaveInformation(string, string, string, MemoryType, MetadataCollection, CancellationToken)
Synchronously saves text information into a designated memory data source, allowing you to specify the memory type.
This method internally calls the asynchronous SaveInformationAsync(string, string, string, MemoryType, MetadataCollection, CancellationToken) method and blocks until the operation completes. It stores the provided text under the specified section identifier, associates it with the provided memory type, and optionally attaches additional metadata.
- SaveInformation(string, string, string, MetadataCollection, CancellationToken)
Synchronously saves text information into a designated memory data source.
This method internally invokes the asynchronous SaveInformationAsync(string, string, string, MetadataCollection, CancellationToken) and blocks until completion.
- SaveInformationAsync(string, string, string, MemoryType, MetadataCollection, CancellationToken)
Asynchronously saves text information into a designated memory data source, allowing you to specify the memory type.
The method stores the given text and assigns it a unique section identifier. Optionally, additional metadata can be associated with the stored section.
- SaveInformationAsync(string, string, string, MetadataCollection, CancellationToken)
Asynchronously saves text information into a designated memory data source.
The method stores the given text and assigns it a unique section identifier. Optionally, additional metadata can be associated with the stored section.
- Serialize()
Serializes the current AgentMemory instance into a binary format.
This method writes a header (including magic numbers and version information) followed by all stored data sources.
- Serialize(Stream)
Serializes the current instance into a binary format and writes it to the provided stream.
The stream must be writable; otherwise, an ArgumentException is thrown.
- Serialize(string)
Serializes the current instance into a binary format and writes it to the specified file.
If the file already exists, it will be overwritten.