Skip to main content
StateBase provides an official BaseMemory integration that makes it trivial to upgrade your existing LangChain agents to production durability.

Installation

pip install statebase-sdk langchain

Usage

Replace your ephemeral ConversationBufferMemory with StateBaseMemory.
1

Initialize Memory

Point the memory to a unique session ID.
from statebase.integrations.langchain import StateBaseMemory

memory = StateBaseMemory(
    session_id="sess_123",
    api_key=os.getenv("STATEBASE_API_KEY"),
    # Optional: Auto-inject context into system prompt
    memory_key="history",
    return_messages=True
)
2

Connect to Chain

Pass the memory object to any Chain or Agent.
from langchain.chains import ConversationChain
from langchain.chat_models import ChatOpenAI

llm = ChatOpenAI(model="gpt-4", temperature=0)

chain = ConversationChain(
    llm=llm,
    memory=memory,
    verbose=True
)
3

Run Loop

StateBase automatically captures every input/output pair.
response = chain.predict(input="My name is Alex.")
# StateBase: Logged Turn #1 (User: "My name is...") -> Extracted Entity: "Alex"

response = chain.predict(input="What is my name?")
# StateBase: Retrieved Context -> "User's name is Alex"

Features

FeatureConversationBufferMemoryStateBaseMemory
Persistence❌ (Lost on restart)✅ (Durable forever)
Vector Search✅ (Auto-RAG)
Audit Logs✅ (Full dashboard)
Rollback✅ (Via API)