Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryChat MessagesMemory typesConversation BufferConversation Buffer WindowEntityConversation Knowledge GraphConversation SummaryConversation Summary BufferConversation Token BufferBacked by a Vector StoreMemory in LLMChainMemory in the Multi-Input ChainMemory in AgentMessage Memory in Agent backed by a databaseCustomizing Conversational MemoryCustom MemoryMultiple Memory classesAgentsCallbacksModulesSecurityGuidesMoreModulesMemoryMemory typesConversation Token BufferOn this pageConversation Token BufferConversationTokenBufferMemory keeps a buffer of recent interactions in memory, and uses token length rather than number of interactions to determine when to flush interactions.Let's first walk through how to use the utilities.Using memory with LLM‚Äãfrom langchain.memory import ConversationTokenBufferMemoryfrom langchain.llms import OpenAIllm = OpenAI()memory = ConversationTokenBufferMemory(llm=llm, max_token_limit=10)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})memory.load_memory_variables({})    {'history': 'Human: not much you\nAI: not much'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationTokenBufferMemory(    llm=llm, max_token_limit=10, return_messages=True)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})Using in a chain‚ÄãLet's walk through an example, again setting verbose=True so we can see the prompt.from langchain.chains import ConversationChainconversation_with_summary = ConversationChain(    llm=llm,    # We set a
ConversationTokenBufferMemory keeps a buffer of recent interactions in memory, and uses token length rather than number of interactions to determine when to flush interactions.
ConversationTokenBufferMemory keeps a buffer of recent interactions in memory, and uses token length rather than number of interactions to determine when to flush interactions. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryChat MessagesMemory typesConversation BufferConversation Buffer WindowEntityConversation Knowledge GraphConversation SummaryConversation Summary BufferConversation Token BufferBacked by a Vector StoreMemory in LLMChainMemory in the Multi-Input ChainMemory in AgentMessage Memory in Agent backed by a databaseCustomizing Conversational MemoryCustom MemoryMultiple Memory classesAgentsCallbacksModulesSecurityGuidesMoreModulesMemoryMemory typesConversation Token BufferOn this pageConversation Token BufferConversationTokenBufferMemory keeps a buffer of recent interactions in memory, and uses token length rather than number of interactions to determine when to flush interactions.Let's first walk through how to use the utilities.Using memory with LLM‚Äãfrom langchain.memory import ConversationTokenBufferMemoryfrom langchain.llms import OpenAIllm = OpenAI()memory = ConversationTokenBufferMemory(llm=llm, max_token_limit=10)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})memory.load_memory_variables({})    {'history': 'Human: not much you\nAI: not much'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationTokenBufferMemory(    llm=llm, max_token_limit=10, return_messages=True)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})Using in a chain‚ÄãLet's walk through an example, again setting verbose=True so we can see the prompt.from langchain.chains import ConversationChainconversation_with_summary = ConversationChain(    llm=llm,    # We set a