BufferMemory
Stores all chat messages in memory, passing the full conversation history to the model on each invocation.
Syntax
langchain
new BufferMemory({ returnMessages: true, memoryKey: "chat_history" })Example
langchain
import { BufferMemory } from "langchain/memory";
import { ConversationChain } from "langchain/chains";
const memory = new BufferMemory();
const chain = new ConversationChain({ llm: model, memory });
await chain.invoke({ input: "My name is Alice." });
const r = await chain.invoke({ input: "What is my name?" });
console.log(r.response); // "Your name is Alice."