summary_buffer.py — langchain Source File
Architecture documentation for summary_buffer.py, a python file in the langchain codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b5eb628f_f038_6143_08fb_3f75c24c699d["summary_buffer.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] b5eb628f_f038_6143_08fb_3f75c24c699d --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"] b5eb628f_f038_6143_08fb_3f75c24c699d --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] b5eb628f_f038_6143_08fb_3f75c24c699d --> d758344f_537f_649e_f467_b9d7442e86df f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"] b5eb628f_f038_6143_08fb_3f75c24c699d --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] b5eb628f_f038_6143_08fb_3f75c24c699d --> 91721f45_4909_e489_8c1f_084f8bd87145 34f6662f_3e50_5bf7_54f1_05e82f591554["langchain_classic.memory.chat_memory"] b5eb628f_f038_6143_08fb_3f75c24c699d --> 34f6662f_3e50_5bf7_54f1_05e82f591554 68580bf1_e2f3_15de_9d81_9a40ff9b227f["langchain_classic.memory.summary"] b5eb628f_f038_6143_08fb_3f75c24c699d --> 68580bf1_e2f3_15de_9d81_9a40ff9b227f style b5eb628f_f038_6143_08fb_3f75c24c699d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Any
from langchain_core._api import deprecated
from langchain_core.messages import BaseMessage, get_buffer_string
from langchain_core.utils import pre_init
from typing_extensions import override
from langchain_classic.memory.chat_memory import BaseChatMemory
from langchain_classic.memory.summary import SummarizerMixin
@deprecated(
since="0.3.1",
removal="1.0.0",
message=(
"Please see the migration guide at: "
"https://python.langchain.com/docs/versions/migrating_memory/"
),
)
class ConversationSummaryBufferMemory(BaseChatMemory, SummarizerMixin):
"""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.
"""
max_token_limit: int = 2000
moving_summary_buffer: str = ""
memory_key: str = "history"
@property
def buffer(self) -> str | list[BaseMessage]:
"""String buffer of memory."""
return self.load_memory_variables({})[self.memory_key]
async def abuffer(self) -> str | list[BaseMessage]:
"""Async memory buffer."""
memory_variables = await self.aload_memory_variables({})
return memory_variables[self.memory_key]
@property
def memory_variables(self) -> list[str]:
"""Will always return list of memory variables."""
return [self.memory_key]
@override
def load_memory_variables(self, inputs: dict[str, Any]) -> dict[str, Any]:
"""Return history buffer."""
buffer = self.chat_memory.messages
if self.moving_summary_buffer != "":
first_messages: list[BaseMessage] = [
self.summary_message_cls(content=self.moving_summary_buffer),
]
buffer = first_messages + buffer
if self.return_messages:
final_buffer: Any = buffer
else:
final_buffer = get_buffer_string(
buffer,
// ... (89 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain_classic.memory.chat_memory
- langchain_classic.memory.summary
- langchain_core._api
- langchain_core.messages
- langchain_core.utils
- typing
- typing_extensions
Source
Frequently Asked Questions
What does summary_buffer.py do?
summary_buffer.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does summary_buffer.py depend on?
summary_buffer.py imports 7 module(s): langchain_classic.memory.chat_memory, langchain_classic.memory.summary, langchain_core._api, langchain_core.messages, langchain_core.utils, typing, typing_extensions.
Where is summary_buffer.py in the architecture?
summary_buffer.py is located at libs/langchain/langchain_classic/memory/summary_buffer.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/memory).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free