It 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 ConversationSummaryBufferMemoryfrom langchain.llms import OpenAIllm = OpenAI()memory = ConversationSummaryBufferMemory(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': 'System: \nThe human says "hi", and the AI responds with "whats up".\nHuman: 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 = ConversationSummaryBufferMemory(    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"})We can also utilize the predict_new_summary method directly.messages = memory.chat_memory.messagesprevious_summary = ""memory.predict_new_summary(messages, previous_summary)    '\nThe human and AI state that they are not doing 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 very low max_token_limit for the purposes of testing.    memory=ConversationSummaryBufferMemory(llm=OpenAI(), max_token_limit=40),    verbose=True,)conversation_with_summary.predict(input="Hi, what's up?")            > Entering new ConversationChain chain...    Prompt after formatting:    The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.        Current conversation:        Human: Hi, what's up?
ConversationSummaryBufferMemory combines the two ideas. It keeps a buffer of recent interactions in memory, but rather than just completely flushing old interactions it compiles them into a summary and uses both.
ConversationSummaryBufferMemory combines the two ideas. It keeps a buffer of recent interactions in memory, but rather than just completely flushing old interactions it compiles them into a summary and uses both. ->: It 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 ConversationSummaryBufferMemoryfrom langchain.llms import OpenAIllm = OpenAI()memory = ConversationSummaryBufferMemory(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': 'System: \nThe human says "hi", and the AI responds with "whats up".\nHuman: 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 = ConversationSummaryBufferMemory(    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"})We can also utilize the predict_new_summary method directly.messages = memory.chat_memory.messagesprevious_summary = ""memory.predict_new_summary(messages, previous_summary)    '\nThe human and AI state that they are not doing 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 very low max_token_limit for the purposes of testing.    memory=ConversationSummaryBufferMemory(llm=OpenAI(), max_token_limit=40),    verbose=True,)conversation_with_summary.predict(input="Hi, what's up?")            > Entering new ConversationChain chain...    Prompt after formatting:    The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.        Current conversation:        Human: Hi, what's up?