For example, if you want the memory variables to be returned in the key chat_history you can do:memory = ConversationBufferMemory(memory_key="chat_history")memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("what's up?")    {'chat_history': "Human: hi!\nAI: what's up?"}The parameter name to control these keys may vary per memory type, but it's important to understand that (1) this is controllable, and (2) how to control it.Whether memory is a string or a list of messages‚ÄãOne of the most common types of memory involves returning a list of chat messages.
These can either be returned as a single string, all concatenated together (useful when they will be passed into LLMs)
or a list of ChatMessages (useful when passed into ChatModels).By default, they are returned as a single string.
In order to return as a list of messages, you can set return_messages=Truememory = ConversationBufferMemory(return_messages=True)memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("what's up?")    {'history': [HumanMessage(content='hi!', additional_kwargs={}, example=False),  AIMessage(content='what's up?', additional_kwargs={}, example=False)]}What keys are saved to memory‚ÄãOften times chains take in or return multiple input/output keys.
In these cases, how can we know which keys we want to save to the chat message history?
This is generally controllable by input_key and output_key parameters on the memory types.
These default to None - and if there is only one input/output key it is known to just use that.
However, if there are multiple input/output keys then you MUST specify the name of which one to use.End to end example‚ÄãFinally, let's take a look at using this in a chain.
Most LLM applications have a conversational interface. An essential component of a conversation is being able to refer to information introduced earlier in the conversation.
Most LLM applications have a conversational interface. An essential component of a conversation is being able to refer to information introduced earlier in the conversation. ->: For example, if you want the memory variables to be returned in the key chat_history you can do:memory = ConversationBufferMemory(memory_key="chat_history")memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("what's up?")    {'chat_history': "Human: hi!\nAI: what's up?"}The parameter name to control these keys may vary per memory type, but it's important to understand that (1) this is controllable, and (2) how to control it.Whether memory is a string or a list of messages‚ÄãOne of the most common types of memory involves returning a list of chat messages.
These can either be returned as a single string, all concatenated together (useful when they will be passed into LLMs)
or a list of ChatMessages (useful when passed into ChatModels).By default, they are returned as a single string.
In order to return as a list of messages, you can set return_messages=Truememory = ConversationBufferMemory(return_messages=True)memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("what's up?")    {'history': [HumanMessage(content='hi!', additional_kwargs={}, example=False),  AIMessage(content='what's up?', additional_kwargs={}, example=False)]}What keys are saved to memory‚ÄãOften times chains take in or return multiple input/output keys.
In these cases, how can we know which keys we want to save to the chat message history?
This is generally controllable by input_key and output_key parameters on the memory types.
These default to None - and if there is only one input/output key it is known to just use that.
However, if there are multiple input/output keys then you MUST specify the name of which one to use.End to end example‚ÄãFinally, let's take a look at using this in a chain.