buffer.py — langchain Source File
Architecture documentation for buffer.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b4796d6b_42cf_9939_9978_b9dcf5d6fb57["buffer.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> feec1ec4_6917_867b_d228_b134d0ff8099 2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 bd035cf2_5933_bc0f_65e9_0dfe57627ca3["langchain_core.utils"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> bd035cf2_5933_bc0f_65e9_0dfe57627ca3 f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> f85fae70_1011_eaec_151c_4083140ae9e5 8d1ab66e_47c1_1140_c3a5_5112af3b1cac["langchain_classic.base_memory"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> 8d1ab66e_47c1_1140_c3a5_5112af3b1cac 0631e07f_ced9_09bd_71a1_4630e7d30d26["langchain_classic.memory.chat_memory"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> 0631e07f_ced9_09bd_71a1_4630e7d30d26 195e5a37_104f_e0be_e49a_f5d06550a9be["langchain_classic.memory.utils"] b4796d6b_42cf_9939_9978_b9dcf5d6fb57 --> 195e5a37_104f_e0be_e49a_f5d06550a9be style b4796d6b_42cf_9939_9978_b9dcf5d6fb57 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.base_memory import BaseMemory
from langchain_classic.memory.chat_memory import BaseChatMemory
from langchain_classic.memory.utils import get_prompt_input_key
@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 ConversationBufferMemory(BaseChatMemory):
"""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.
"""
human_prefix: str = "Human"
ai_prefix: str = "AI"
memory_key: str = "history"
@property
def buffer(self) -> Any:
"""String buffer of memory."""
return self.buffer_as_messages if self.return_messages else self.buffer_as_str
async def abuffer(self) -> Any:
"""String buffer of memory."""
return (
await self.abuffer_as_messages()
if self.return_messages
else await self.abuffer_as_str()
)
def _buffer_as_str(self, messages: list[BaseMessage]) -> str:
return get_buffer_string(
messages,
human_prefix=self.human_prefix,
ai_prefix=self.ai_prefix,
)
@property
def buffer_as_str(self) -> str:
"""Exposes the buffer as a string in case return_messages is True."""
return self._buffer_as_str(self.chat_memory.messages)
async def abuffer_as_str(self) -> str:
// ... (114 more lines)
Domain
Subdomains
Dependencies
- langchain_classic.base_memory
- langchain_classic.memory.chat_memory
- langchain_classic.memory.utils
- langchain_core._api
- langchain_core.messages
- langchain_core.utils
- typing
- typing_extensions
Source
Frequently Asked Questions
What does buffer.py do?
buffer.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What does buffer.py depend on?
buffer.py imports 8 module(s): langchain_classic.base_memory, langchain_classic.memory.chat_memory, langchain_classic.memory.utils, langchain_core._api, langchain_core.messages, langchain_core.utils, typing, typing_extensions.
Where is buffer.py in the architecture?
buffer.py is located at libs/langchain/langchain_classic/memory/buffer.py (domain: LangChainCore, subdomain: MessageInterface, 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