LangChain integration for the Unison Brain — memory, chat history, and retriever
Project description
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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_unison-0.1.1.tar.gz.
File metadata
- Download URL: langchain_unison-0.1.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd609f2283df70854d59e614ac2804768bdce59ce7378086153172000a9318e0
|
|
| MD5 |
1e07fd294954496fe32f85962a3893d8
|
|
| BLAKE2b-256 |
fd136522db12a302e503df36830963cf961c4c0c092a172f193a018f32f46320
|
File details
Details for the file langchain_unison-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langchain_unison-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49ec26d5ff44f49954b08a9a9a2dfc79f13f46eff0b85bec36ff42a4403716e4
|
|
| MD5 |
0799c69746b1c4ce521d2c5ca48d9293
|
|
| BLAKE2b-256 |
557a6c5ec116a36500b3fc9b2f1f418921003409716274e1d7565bcea0576e48
|