Class that manages the memory of a generative agent in LangChain. It extends the BaseMemory class and has methods for adding a memory, formatting memories, getting memories until a token limit is reached, loading memory variables, saving the context of a model run to memory, and clearing memory contents.

const createNewMemoryRetriever = async () => {
const vectorStore = new MemoryVectorStore(new OpenAIEmbeddings());
const retriever = new TimeWeightedVectorStoreRetriever({
vectorStore,
otherScoreKeys: ["importance"],
k: 15,
});
return retriever;
};
const tommiesMemory = new GenerativeAgentMemory(
llm,
await createNewMemoryRetriever(),
{ reflectionThreshold: 8 },
);
const summary = await tommiesMemory.getSummary();

Hierarchy (view full)

Constructors

Properties

addMemoryKey: string = "addMemory"
llm: BaseLanguageModelInterface<any, BaseLanguageModelCallOptions>
memoryChain: GenerativeAgentMemoryChain
mostRecentMemoriesKey: string = "most_recent_memories"
mostRecentMemoriesTokenKey: string = "recent_memories_token"
nowKey: string = "now"
queriesKey: string = "queries"
reflectionThreshold?: number
relevantMemoriesKey: string = "relevant_memories"
relevantMemoriesSimpleKey: string = "relevant_memories_simple"
verbose: boolean

Accessors

Methods

  • Method that adds a memory to the agent's memory.

    Parameters

    • memoryContent: string

      The content of the memory to add.

    • Optionalnow: Date

      The current date.

    • Optionalmetadata: Record<string, unknown>

      The metadata for the memory.

    • Optionalcallbacks: Callbacks

      The Callbacks to use for adding the memory.

    Returns Promise<ChainValues>

    The result of the memory addition.