ConversationSummaryMemory#

class langchain.memory.summary.ConversationSummaryMemory[source]#

Bases: BaseChatMemory, SummarizerMixin

Deprecated since version 0.3.1: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/

Continually summarizes the conversation history.

The summary is updated after each conversation turn. The implementations returns a summary of the conversation history which can be used to provide context to the model.

param ai_prefix: str = 'AI'#
param buffer: str = ''#
param chat_memory: BaseChatMessageHistory [Optional]#
param human_prefix: str = 'Human'#
param input_key: str | None = None#
param llm: BaseLanguageModel [Required]#
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 aclear() None#

Clear memory contents.

Return type:

None

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

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

Parameters:

inputs (dict[str, Any]) – The inputs to the chain.

Returns:

A dictionary of key-value pairs.

Return type:

dict[str, Any]

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

str

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[source]#

Clear memory contents.

Return type:

None

classmethod from_messages(llm: BaseLanguageModel, chat_memory: BaseChatMessageHistory, *, summarize_step: int = 2, **kwargs: Any) ConversationSummaryMemory[source]#
Parameters:
Return type:

ConversationSummaryMemory

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

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