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
