langchain.memory.summary_buffer.ConversationSummaryBufferMemory

class langchain.memory.summary_buffer.ConversationSummaryBufferMemory(*, human_prefix: str = 'Human', ai_prefix: str = 'AI', llm: ~langchain.schema.language_model.BaseLanguageModel, prompt: ~langchain.schema.prompt_template.BasePromptTemplate = PromptTemplate(input_variables=['summary', 'new_lines'], output_parser=None, 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:', template_format='f-string', validate_template=True), summary_message_cls: ~typing.Type[~langchain.schema.messages.BaseMessage] = <class 'langchain.schema.messages.SystemMessage'>, chat_memory: ~langchain.schema.memory.BaseChatMessageHistory = None, output_key: ~typing.Optional[str] = None, input_key: ~typing.Optional[str] = None, return_messages: bool = False, max_token_limit: int = 2000, moving_summary_buffer: str = '', memory_key: str = 'history')[source]

Bases: BaseChatMemory, SummarizerMixin

Buffer with summarizer for storing conversation memory.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param ai_prefix: str = 'AI'
param chat_memory: BaseChatMessageHistory [Optional]
param human_prefix: str = 'Human'
param input_key: Optional[str] = None
param llm: BaseLanguageModel [Required]
param max_token_limit: int = 2000
param memory_key: str = 'history'
param moving_summary_buffer: str = ''
param output_key: Optional[str] = None
param prompt: BasePromptTemplate = PromptTemplate(input_variables=['summary', 'new_lines'], output_parser=None, 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:', template_format='f-string', validate_template=True)
param return_messages: bool = False
param summary_message_cls: Type[BaseMessage] = <class 'langchain.schema.messages.SystemMessage'>
clear() None[source]

Clear memory contents.

load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any][source]

Return history buffer.

predict_new_summary(messages: List[BaseMessage], existing_summary: str) str
prune() None[source]

Prune buffer if it exceeds max token limit

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

Save context from this conversation to buffer.

to_json() Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() SerializedNotImplemented
validator validate_prompt_input_variables  »  all fields[source]

Validate that prompt input variables are consistent.

property buffer: List[langchain.schema.messages.BaseMessage]
property lc_attributes: Dict

Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.

property lc_namespace: List[str]

Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]

property lc_secrets: Dict[str, str]

Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}

property lc_serializable: bool

Return whether or not the class is serializable.

model Config

Bases: object

Configuration for this pydantic object.

arbitrary_types_allowed = True

Examples using ConversationSummaryBufferMemory