LangChain Memory
LangChain Memory is a standard interface for persisting state between calls of a chain or agent, enabling large language models to have memory and context. By default, LLMs are stateless, meaning each incoming query is processed independently of other interactions, but LangChain memory solves this limitation by maintaining conversation history. It enables coherent conversations, and without it, every query would be treated as an entirely independent input without considering past interactions. The framework offers multiple memory types including ConversationBufferMemory for storing complete message histories, ConversationBufferWindowMemory that keeps only the last K interactions in a sliding window, and ConversationSummaryMemory that summarizes conversations to save costs by minimizing token usage. ConversationSummaryBufferMemory combines buffer and summary approaches, using token length rather than interaction count to determine when to flush old interactions.