langchain-unison
LangChain memory, history & retriever — backed by the Unison brain.
Install • UnisonMemory • UnisonChatMessageHistory • UnisonRetriever • Env vars • For agents
🤖 Reading this as an AI agent? Jump to
AGENTS.md— it covers install, auth (UNISON_TOKEN), the three classes, the recall-before / persist-after pattern, and the contributor guide, all in one page.
LangChain memory, chat history, and retriever backed by the Unison brain — a personal knowledge graph that stores and recalls context across every session, tool, and agent.
Install
pip install langchain-unison
Quick start
UnisonMemory
Drop-in memory for any LangChain chain. On every call it recalls relevant context from your brain and ingests the new turn when done.
from langchain_unison import UnisonMemory
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
memory = UnisonMemory() # reads UNISON_TOKEN from env
template = PromptTemplate.from_template(
"Context from your knowledge base:\n{history}\n\nQuestion: {input}\nAnswer:"
)
# Load memory before the chain call
inputs = {"input": "What pricing model did we decide on?"}
inputs.update(memory.load_memory_variables(inputs))
# ... run your LLM chain with `inputs` ...
outputs = {"output": "We went with a freemium tier at $49/mo."}
# Save the exchange back to the brain
memory.save_context(inputs, outputs)
UnisonChatMessageHistory
BaseChatMessageHistory that appends every message to the Unison brain in real time.
from langchain_unison import UnisonChatMessageHistory
from langchain_core.messages import HumanMessage, AIMessage
history = UnisonChatMessageHistory(session_id="my-session-001")
history.add_message(HumanMessage(content="What is the refund policy?"))
history.add_message(AIMessage(content="Refunds are available within 30 days."))
print(history.messages)
# [HumanMessage(content='What is the refund policy?'),
# AIMessage(content='Refunds are available within 30 days.')]
UnisonRetriever
BaseRetriever that queries GET /v1/brain/search and returns LangChain Document objects.
from langchain_unison import UnisonRetriever
retriever = UnisonRetriever(k=6)
docs = retriever.invoke("What did we decide about the enterprise tier?")
for doc in docs:
print(doc.metadata["title"], "—", doc.page_content[:120])
Environment variables
| Variable | Default | Description |
|---|---|---|
UNISON_TOKEN |
(required) | Bearer token from unisonlabs.ai |
UNISON_API_URL |
https://brain.unisonlabs.ai |
Override for self-hosted or staging deployments |
You can also pass token= and base_url= directly to any class constructor.
For agents
See AGENTS.md — install, auth, usage patterns, and contributor guide in one page.
Links
- Homepage: https://unisonlabs.ai
- Docs: https://unisonlabs.ai/docs
- Unison brain repo: https://github.com/unison-labs-ai/unison-brain
- Issues: https://github.com/unison-labs-ai/langchain-unison/issues
Releasing
Set a PyPI token — either via ~/.pypirc or environment variables:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-...
Then run:
python3 scripts/release.py
This builds langchain-unison, publishes it to PyPI (idempotent — skips if the version is already on PyPI), then tags and pushes the release tag.
License
MIT — see LICENSE.
Part of the Unison Labs constellation
One brain, every agent. Every repo below reads from and writes to the same Unison brain — no per-tool memory silos.
| Repo | What it does |
|---|---|
| unison-brain | CLI · SDK · MCP server — the core |
| claude-unison | Memory for Claude Code |
| cursor-unison | Memory for Cursor |
| codex-unison | Memory for OpenAI Codex CLI |
| opencode-unison | Memory for OpenCode |
| openclaw-unison | Memory for OpenClaw |
| pipecat-unison | Memory for Pipecat voice agents |
| langchain-unison | LangChain memory, history & retriever ← you are here |
| llama-index-memory-unison | LlamaIndex memory provider |
| unison-ai-sdk | Vercel AI SDK memory middleware |
| unison-mastra | Mastra agent memory provider |
| python-sdk | Python SDK for the brain |
| install-mcp | One-command MCP installer |
| unison-fs | Mount the brain as a filesystem |
| backchannel | Async messaging between agents |
| Unison-evals | Open memory benchmark suite |
Metadata
Release files for langchain-unison 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_unison-0.1.1.tar.gz | 10.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_unison-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.3 kB
Release files / langchain_unison-0.1.1.tar.gz
| Download URL | langchain_unison-0.1.1.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd609f2283df70854d59e614ac2804768bdce59ce7378086153172000a9318e0
|
|
BLAKE2b-256 checksum How to use checksums |
fd136522db12a302e503df36830963cf961c4c0c092a172f193a018f32f46320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / langchain_unison-0.1.1-py3-none-any.whl
| Download URL | langchain_unison-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49ec26d5ff44f49954b08a9a9a2dfc79f13f46eff0b85bec36ff42a4403716e4
|
|
BLAKE2b-256 checksum How to use checksums |
557a6c5ec116a36500b3fc9b2f1f418921003409716274e1d7565bcea0576e48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|