LangChain Integration
Drop-in chat history and memory for LangChain
A managed chat history for LangChain chains and agents. Long-term user memory and semantic search included, no vector database to run.
BufferMemoryConversationSummaryMemoryRunnableWithMessageHistoryimplements BaseListChatMessageHistory
DialogueChatHistory
Backed by DialogueDB
Messages
Memory
Search
Where the default chat history stops
The default chat history is scoped to a single process
Every LangChain memory class delegates to a chat history object. The default, InMemoryChatMessageHistory, keeps messages in an in-process array and drops them on restart. Fine for local development, and short on the guarantees a chatbot needs when it runs on serverless, in a container, or across multiple worker instances.
- Every message lives in a plain array on one instance
- One chain instance per session, no shared state model
- Message history only, nothing for facts or preferences
- Retrieval walks the array, no semantic query
- Restarts, deploys, and serverless cold starts wipe every user
- Multi-instance workers don't see each other's history
- Nothing to carry facts about a user across sessions
- "What did we discuss about X" needs a separate search stack
What DialogueDB adds
A managed chat history for LangChain, plus three things the defaults leave out
The chat history class implements the interface every LangChain memory surface already accepts, so nothing about the chain changes. DialogueDB then covers the three concerns the defaults leave for the developer to solve.
Chat history that survives every restart
Every message from every user persists to DialogueDB. Chains and agents keep their context across deploys, cold starts, and multi-instance workers.
Namespaces for multi-user chains
Pass a namespace on every read and write. Conversations, memory, and search stay isolated per user, tenant, or workspace at the data layer.
Memory that carries across sessions
Store facts and preferences the assistant should remember beyond a single conversation. Retrieve them on the next run to seed the system prompt.
Semantic search over past runs
Query past messages and memory by meaning, not keyword. Inject into a prompt or expose as a tool the agent can call, no vector database to run.
The integration pattern
Add DialogueChatHistory to the memory constructor, and the chain runs exactly as it did before
One line in the constructor persists every message the chain touches. Two optional calls around the run cover long-term memory and semantic search, and nothing else about the chain code has to change.
const db = new DialogueDB()
// 1. Construct DialogueChatHistory
const history = new DialogueChatHistory({
dialogueId: sessionId,
namespace: userId,
})
// 2. Wire it into the memory class
const memory = new BufferMemory({
chatHistory: history,
returnMessages: true,
})
// 3. Search memory (optional)
const facts = await db.searchMemories(
userInput, { namespace: userId }
)
// 4. Run the chain
const chain = new ConversationChain({ llm, memory })
const result = await chain.call({ input: userInput })
// 5. Save new facts (optional)
await db.createMemory({ value: newFact, namespace: userId })What this unlocks in your LangChain app
Six patterns the integration makes shorter to build.
Chatbots that survive every deploy
A chain that talked to a user yesterday picks up the same conversation today, even if the process restarted in between.
DialogueChatHistorySupport agents that carry ticket history
Every past conversation about a customer is a load call away. The agent picks up mid-thread without you re-hydrating context.
dialogueIdOnboarding chains with real user profiles
As the assistant learns preferences and answers, store them as Memory objects. The next session starts with a profile, not a blank slate.
db.createMemory()Agent conversations that pick up where they stopped
On restart, the agent reloads every prior message from DialogueDB and continues with full context of what the last run said and answered.
DialogueChatHistoryMulti-tenant SaaS with per-user isolation
One codebase, many customers, each with their own namespace. No cross-tenant leakage, no WHERE clauses in your chain code.
namespace: userIdRecall past runs by meaning
Search over every past conversation, scoped to a namespace. Answer "what did we discuss about X" even when the reader phrased it differently.
db.searchMessages()Install in 3 steps
From npm install to the first message that survives a restart, in under five minutes.
Install the client
npm install dialogue-dbSet the API key
DIALOGUE_DB_API_KEY=...Drop in the chat history
new BufferMemory({
chatHistory: new DialogueChatHistory({
dialogueId: sessionId,
namespace: userId,
}),
})Copy the class from the examples repo.
No credit card. Free tier to start. Starter is $29/month when usage grows.
The reference example
A LangChain example repo with two runnable samples, cloneable and locally runnable in about a minute.
A conversation chain that survives a cold restart
A BufferMemory and ConversationChain with a DialogueDB-backed chat history. Runs a short exchange, restarts the process, and continues with the earlier context intact.
A tool-calling agent that resumes on the next call
A createToolCallingAgent with two example tools and a DialogueDB-backed chat history. Runs a multi-step query, restarts the process, and picks up a follow-up in the same thread.
Read the DialogueChatHistory class
The full implementation lives in the same example repo. Select a section to jump to its lines.
Where DialogueDB fits
Options for LangChain chat history and cross-session memory, side by side.
| InMemoryChatMessageHistory LangChain default | Redis or SQL history @langchain/community classes | Standalone memory service Facts and preferences only | DialogueDB | |
|---|---|---|---|---|
| Persists messages | No, in-process | Yes | Facts only | Yes, every message |
| Multi-user isolation | None | Bring your own | By user ID | Namespaces, first-class |
| Long-term memory across sessions | No | No | Yes | Yes, Memory objects |
| Semantic search over past runs | No | Build it yourself | Facts only | Every message and memory |
| Infra to run | None (in-process) | Redis or DB you host | Their managed service | Managed |
If you know LangChain, you already know DialogueDB
The concepts map one-to-one to what LangChain already exposes.
| LangChain | DialogueDB |
|---|---|
BaseListChatMessageHistory | DialogueChatHistory |
HumanMessage, AIMessage, SystemMessage | message with role |
| Session identifier from your app | dialogueId |
| User from your auth layer | namespace |
| Tool call on an AIMessage | message content and metadata (extend the class to serialize) |
| Facts the assistant should carry | memory |
Frequently asked questions
One API for messages, memory, and search
Add it to your LangChain app in minutes.