Fixing the 'ConversationBufferMemory' ImportError in LangChain v0.3

beginner🧠 AI Tools2026-07-14| Python 3.9+, LangChain v0.3.x, langchain-community, Windows/macOS/Linux

Error Message

ImportError: cannot import name 'ConversationBufferMemory' from 'langchain.memory'
#langchain#python#import-error#memory#langchain-community

The Problem

You just ran pip install --upgrade langchain and suddenly your chatbot is dead in the water. When you try to launch your application, Python hits you with a traceback that looks like this:

Traceback (most recent call last):
  File "app.py", line 5, in <module>
    from langchain.memory import ConversationBufferMemory
ImportError: cannot import name 'ConversationBufferMemory' from 'langchain.memory'

This happens because LangChain v0.3 has completed a major architectural shift. The developers have stripped the core langchain package down to its essentials. Legacy components, including most memory utilities, have been moved to a separate package to keep the core library lightweight and modular.

Why the Import Fails

In previous versions (v0.1 and early v0.2), ConversationBufferMemory was bundled directly inside the main package. Starting with v0.3, the langchain package acts primarily as a thin wrapper.

The ConversationBufferMemory class now lives in langchain-community. If you upgraded your main package but didn't install the community partner, your code won't find the class where it used to be. It's a classic case of a dependency moving to a new home without leaving a forwarding address in the old namespace.

Step 1: Install the Community Package

The first step is ensuring you have the necessary implementation package installed. Most developers forget this step during a bulk upgrade.

Run this command in your terminal:

pip install -U langchain-community

For those using modern dependency managers, use the corresponding command:

# For Poetry users
poetry add langchain-community

# For Pipenv users
pipenv install langchain-community

Step 2: Update Your Import Statements

Simply installing the package isn't enough. You must also tell Python to look in the new langchain_community namespace. The old import path is now deprecated and will throw errors in v0.3.

The Broken Import

# This will fail in v0.3
from langchain.memory import ConversationBufferMemory

The Correct Import

# Change this to the community namespace
from langchain_community.memory import ConversationBufferMemory

This change applies to other memory types as well. If you use ConversationSummaryMemory or ReadOnlySharedMemory, you'll need to update those paths to langchain_community.memory too.

Don't Forget Chat History

If your project uses ChatMessageHistory to store raw message strings, that has moved as well. You'll likely need to update that import to avoid a second error immediately after fixing the first one:

# New path for message history
from langchain_community.chat_message_histories import ChatMessageHistory

Verification: Testing the Fix

Confirm everything is working by running a quick 5-line test script. Create a file named check_memory.py:

try:
    from langchain_community.memory import ConversationBufferMemory
    memory = ConversationBufferMemory()
    memory.save_context({"user": "Hello"}, {"bot": "Hi there!"})
    print("Success: Memory is working correctly.")
    print("Buffer content:", memory.load_memory_variables({}))
except ImportError:
    print("Import failed. Check your langchain-community installation.")

Run it with python check_memory.py. If you see the "Success" message, you're back in business.

A Better Way: Moving to LangGraph

While this fix keeps your legacy code running, the LangChain team now considers the langchain.memory module to be in maintenance mode. For production apps in 2024 and beyond, they recommend using LangGraph for state management.

LangGraph's checkpointers offer much better persistence and control than the older ConversationBufferMemory. If you're starting a new project, it's worth investing the time to learn LangGraph's state management instead of relying on these legacy community components.

Related Error Notes