LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicmemorybuffer_windowConversationBufferWindowMemory
    Class●Since v1.0Deprecated

    ConversationBufferWindowMemory

    Copy
    ConversationBufferWindowMemory()

    Bases

    BaseChatMemory

    Used in Docs

    • Baseten integration
    • OpaquePrompts integration

    Attributes

    Methods

    Inherited fromBaseChatMemory

    Attributes

    Achat_memory: BaseChatMessageHistoryAoutput_key: strAinput_key: str | None
    —

    The key from the model Run's inputs to use as the eval input.

    View source on GitHub
    A
    return_messages
    : bool

    Methods

    Msave_context
    —

    Save the context of this chain run to memory.

    Masave_context
    —

    Async save the context of this chain run to memory.

    Mclear
    —

    Clear memory contents.

    Maclear
    —

    Async clear memory contents.

    Inherited fromBaseMemory

    Attributes

    Amodel_config

    Methods

    Maload_memory_variables
    —

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

    Msave_context
    —

    Save the context of this chain run to memory.

    Masave_context
    —

    Async save the context of this chain run to memory.

    Mclear
    —

    Clear memory contents.

    Maclear
    —

    Async clear memory contents.

    Inherited fromSerializable(langchain_core)

    Attributes

    Alc_secretsAlc_attributesAmodel_config

    Methods

    Mis_lc_serializableMget_lc_namespaceMlc_idMto_jsonMto_json_not_implemented
    attribute
    human_prefix: str
    attribute
    ai_prefix: str
    attribute
    memory_key: str
    attribute
    k: int

    Number of messages to store in buffer.

    attribute
    buffer: str | list[BaseMessage]

    String buffer of memory.

    attribute
    buffer_as_str: str

    Exposes the buffer as a string in case return_messages is False.

    attribute
    buffer_as_messages: list[BaseMessage]

    Exposes the buffer as a list of messages in case return_messages is True.

    attribute
    memory_variables: list[str]

    Will always return list of memory variables.

    method
    load_memory_variables

    Return history buffer.

    Use to keep track of the last k turns of a conversation.

    If the number of messages in the conversation is more than the maximum number of messages to keep, the oldest messages are dropped.