Persistent Memory for LangChain - Unison Integration
Add persistent team memory to LangChain agents and chains: recall before invocation, ingest after - shared across every session and teammate.
Learn how to give LangChain agents persistent team memory with the official langchain-unison adapter — three drop-in pieces, no plumbing.
Unlike LangChain's local conversation buffers, what lands in the brain is shared: every teammate's agent recalls it, across sessions and machines.
Install
pip install langchain-unisonAll three classes read UNISON_TOKEN (and optional UNISON_API_URL) from the environment.
Chat history
Wire UnisonChatMessageHistory into RunnableWithMessageHistory — each turn is ingested into the brain instead of a local buffer:
from langchain_unison import UnisonChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
with_memory = RunnableWithMessageHistory(
chain,
lambda session_id: UnisonChatMessageHistory(session_id=session_id),
input_messages_key="input",
history_messages_key="history",
)
with_memory.invoke(
{"input": "What did we decide about auth?"},
config={"configurable": {"session_id": "user-123"}},
)Retrieval
UnisonRetriever returns the relevant slice of team memory as LangChain Documents — compose it into any retrieval chain:
from langchain_unison import UnisonRetriever
from langchain_core.runnables import RunnablePassthrough
retriever = UnisonRetriever(k=6)
docs = retriever.invoke("What did we decide about the enterprise tier?")
rag = {"context": retriever, "question": RunnablePassthrough()} | prompt | llmClassic memory
UnisonMemory implements the classic BaseMemory interface — recall on load_memory_variables, ingest on save_context:
from langchain_unison import UnisonMemory
memory = UnisonMemory() # history key defaults to "history"
memory.save_context({"input": "We chose Postgres over SQLite."}, {"output": "Noted."})
vars = memory.load_memory_variables({"input": "what database did we pick?"})
# vars["history"] is the recalled team context, ready to inject into a promptFor multi-user products, mint a brain:act-as service key and pass an actor per user so each gets an isolated private namespace (details).
Persistent Memory for LangGraph Agents - Unison Integration
Give LangGraph agents persistent team memory that survives across threads and graph runs - recall into state at entry, write back on completion.
Persistent Memory for LlamaIndex - Unison Integration
Drop-in agent memory for LlamaIndex: UnisonMemory replaces ChatMemoryBuffer and recalls team knowledge before each turn, ingesting what the agent learns.