ConversationSummaryBufferMemory#

class langchain.memory.summary_buffer.ConversationSummaryBufferMemory[source]#

Bases: BaseChatMemory, SummarizerMixin

Deprecated since version 0.3.1: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/ It will be removed in None==1.0.0.

Buffer with summarizer for storing conversation memory.

Provides a running summary of the conversation together with the most recent messages in the conversation under the constraint that the total number of tokens in the conversation does not exceed a certain limit.

param ai_prefix: str = 'AI'#
param chat_memory: BaseChatMessageHistory [Optional]#
param human_prefix: str = 'Human'#
param input_key: str | None = None#
param llm: BaseLanguageModel [Required]#
param max_token_limit: int = 2000#
param memory_key: str = 'history'#
param moving_summary_buffer: str = ''#
param output_key: str | None = None#
param prompt: BasePromptTemplate = PromptTemplate(input_variables=['new_lines', 'summary'], input_types={}, partial_variables={}, template='Progressively summarize the lines of conversation provided, adding onto the previous summary returning a new summary.\n\nEXAMPLE\nCurrent summary:\nThe human asks what the AI thinks of artificial intelligence. The AI thinks artificial intelligence is a force for good.\n\nNew lines of conversation:\nHuman: Why do you think artificial intelligence is a force for good?\nAI: Because artificial intelligence will help humans reach their full potential.\n\nNew summary:\nThe human asks what the AI thinks of artificial intelligence. The AI thinks artificial intelligence is a force for good because it will help humans reach their full potential.\nEND OF EXAMPLE\n\nCurrent summary:\n{summary}\n\nNew lines of conversation:\n{new_lines}\n\nNew summary:')#
param return_messages: bool = False#
param summary_message_cls: Type[BaseMessage] = <class 'langchain_core.messages.system.SystemMessage'>#
async abuffer() str | List[BaseMessage][source]#

Async memory buffer.

Return type:

str | List[BaseMessage]

async aclear() None[source]#

Asynchronously clear memory contents.

Return type:

None

async aload_memory_variables(inputs: Dict[str, Any]) Dict[str, Any][source]#

Asynchronously return key-value pairs given the text input to the chain.

Parameters:

inputs (Dict[str, Any])

Return type:

Dict[str, Any]

async apredict_new_summary(messages: List[BaseMessage], existing_summary: str) str#
Parameters:
Return type:

str

async aprune() None[source]#

Asynchronously prune buffer if it exceeds max token limit

Return type:

None

async asave_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None[source]#

Asynchronously save context from this conversation to buffer.

Parameters:
  • inputs (Dict[str, Any])

  • outputs (Dict[str, str])

Return type:

None

clear() None[source]#

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]

predict_new_summary(messages: List[BaseMessage], existing_summary: str) str#
Parameters:
Return type:

str

prune() None[source]#

Prune buffer if it exceeds max token limit

Return type:

None

save_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None[source]#

Save context from this conversation to buffer.

Parameters:
  • inputs (Dict[str, Any])

  • outputs (Dict[str, str])

Return type:

None

classmethod validate_prompt_input_variables(values: Dict) Dict[source]#

Validate that prompt input variables are consistent.

Parameters:

values (Dict)

Return type:

Dict

property buffer: str | List[BaseMessage]#

String buffer of memory.