Thuta Learning
LangChain
IntermediateAIAdvanced

Memory

LangChainLesson 8

Memory is the component that lets chains remember previous conversations. ConversationBufferMemory stores the chat history in a single variable.

python
from langchain.memory import ConversationBufferMemory

# Setup memory
memory = ConversationBufferMemory()

# Add memory to an LLMChain
chain = LLMChain(llm=llm, prompt=prompt, memory=memory)

# The first time, the memory is empty.
# The second time, the chain will "remember" the first conversation.
You should see
(With Memory in place, a chatbot can recall what was said earlier in the conversation.)

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.