liveBook · Manning

Buffer memory

As explained in Building Reliable AI Systems

A conversation-memory pattern that retains the complete history of messages rather than compressing it.

Buffer memory retains the full conversation as a chronological list of messages. Each interaction remains verbatim, so the model can receive the complete history without a separate memory class or configuration. This gives complete context retention, but memory grows linearly with conversation length; the approach is best suited to short-term or limited-scope conversations. section 6.2.2

from langchain_core.messages import HumanMessage, AIMessage  

chat_history = []  

chat_history.append(HumanMessage(content="What's the weather in Paris?"))
chat_history.append(AIMessage(content="It's sunny and 25°C."))

# Inspect the history
for msg in chat_history:
    role = "Human" if isinstance(msg, HumanMessage) else "AI"
    print(f"{role}: {msg.content}")

Store HumanMessage and AIMessage objects in a list, then inspect the transcript in order. section 6.2.2

For longer conversations, a summary approach compresses history to reduce memory use; unlike a buffer, it does not retain every exchange verbatim. section 6.2.2

How Building Reliable AI Systems covers it

How deep it goes
Defines the message-list approach and its growth trade-off, then points to summary memory for longer conversations.
Examples
Demonstrates a Paris weather exchange stored as human and AI messages.
What you can do after
Apply it by storing LangChain HumanMessage and AIMessage objects in a list passed directly to a model.
How it connects
Contrasts conversation history retention with summary memory and uses LangChain message objects.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.