ConversationBufferMemory#
- class langchain.memory.buffer.ConversationBufferMemory[source]#
Bases:
BaseChatMemory
Deprecated since version 0.3.1: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/
A basic memory implementation that simply stores the conversation history.
This stores the entire conversation history in memory without any additional processing.
Note that additional processing may be required in some situations when the conversation history is too large to fit in the context window of the model.
- param ai_prefix: str = 'AI'#
- param chat_memory: BaseChatMessageHistory [Optional]#
- param human_prefix: str = 'Human'#
- param input_key: str | None = None#
- param output_key: str | None = None#
- param return_messages: bool = False#
- async abuffer_as_messages() List[BaseMessage] [source]#
Exposes the buffer as a list of messages in case return_messages is False.
- Return type:
List[BaseMessage]
- async abuffer_as_str() str [source]#
Exposes the buffer as a string in case return_messages is True.
- Return type:
str
- async aclear() None #
Clear memory contents.
- Return type:
None
- async aload_memory_variables(inputs: Dict[str, Any]) Dict[str, Any] [source]#
Return key-value pairs given the text input to the chain.
- Parameters:
inputs (Dict[str, Any])
- Return type:
Dict[str, Any]
- async asave_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None #
Save context from this conversation to buffer.
- Parameters:
inputs (Dict[str, Any])
outputs (Dict[str, str])
- Return type:
None
- clear() None #
Clear memory contents.
- Return type:
None
- load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any] [source]#
Return history buffer.
- Parameters:
inputs (Dict[str, Any])
- Return type:
Dict[str, Any]
- save_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None #
Save context from this conversation to buffer.
- Parameters:
inputs (Dict[str, Any])
outputs (Dict[str, str])
- Return type:
None
- property buffer: Any#
String buffer of memory.
- property buffer_as_messages: List[BaseMessage]#
Exposes the buffer as a list of messages in case return_messages is False.
- property buffer_as_str: str#
Exposes the buffer as a string in case return_messages is True.
Examples using ConversationBufferMemory