Conversation summary memory summarizes the conversation as it happens and stores the current summary in memory. This memory can then be used to inject the summary of the conversation so far into a prompt/chain. This memory is most useful for longer conversations, where keeping the past message history in the prompt verbatim would take up too many tokens.Let's first explore the basic functionality of this type of memory.from langchain.memory import ConversationSummaryMemory, ChatMessageHistoryfrom langchain.llms import OpenAImemory = ConversationSummaryMemory(llm=OpenAI(temperature=0))memory.save_context({"input": "hi"}, {"output": "whats up"})memory.load_memory_variables({})    {'history': '\nThe human greets the AI, to which the AI responds.'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationSummaryMemory(llm=OpenAI(temperature=0), return_messages=True)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.load_memory_variables({})    {'history': [SystemMessage(content='\nThe human greets the AI, to which the AI responds.', additional_kwargs={})]}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 greets the AI, to which the AI responds.'Initializing with messages/existing summary‚ÄãIf you have messages outside this class, you can easily initialize the class with ChatMessageHistory. During loading, a summary will be calculated.history = ChatMessageHistory()history.add_user_message("hi")history.add_ai_message("hi there!")memory = ConversationSummaryMemory.from_messages(    llm=OpenAI(temperature=0),    chat_memory=history,    return_messages=True)memory.buffer    '\nThe human greets the AI, to which the AI responds with a friendly greeting.'Optionally you can speed up initialization using a previously generated summary, and avoid
Now let's take a look at using a slightly more complex type of memory - ConversationSummaryMemory. This type of memory creates a summary of the conversation over time. This can be useful for condensing information from the conversation over time.
Now let's take a look at using a slightly more complex type of memory - ConversationSummaryMemory. This type of memory creates a summary of the conversation over time. This can be useful for condensing information from the conversation over time. ->: Conversation summary memory summarizes the conversation as it happens and stores the current summary in memory. This memory can then be used to inject the summary of the conversation so far into a prompt/chain. This memory is most useful for longer conversations, where keeping the past message history in the prompt verbatim would take up too many tokens.Let's first explore the basic functionality of this type of memory.from langchain.memory import ConversationSummaryMemory, ChatMessageHistoryfrom langchain.llms import OpenAImemory = ConversationSummaryMemory(llm=OpenAI(temperature=0))memory.save_context({"input": "hi"}, {"output": "whats up"})memory.load_memory_variables({})    {'history': '\nThe human greets the AI, to which the AI responds.'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationSummaryMemory(llm=OpenAI(temperature=0), return_messages=True)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.load_memory_variables({})    {'history': [SystemMessage(content='\nThe human greets the AI, to which the AI responds.', additional_kwargs={})]}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 greets the AI, to which the AI responds.'Initializing with messages/existing summary‚ÄãIf you have messages outside this class, you can easily initialize the class with ChatMessageHistory. During loading, a summary will be calculated.history = ChatMessageHistory()history.add_user_message("hi")history.add_ai_message("hi there!")memory = ConversationSummaryMemory.from_messages(    llm=OpenAI(temperature=0),    chat_memory=history,    return_messages=True)memory.buffer    '\nThe human greets the AI, to which the AI responds with a friendly greeting.'Optionally you can speed up initialization using a previously generated summary, and avoid