Integrations

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.

langchain-unison

Learn how to give LangGraph agents persistent team memory that survives across threads and graph runs.

LangGraph's checkpointer persists thread state; Unison persists what the team knows. Keep the checkpointer for resuming runs — add Unison so knowledge survives across threads, agents, and people.

Official adapter

LangGraph is built on LangChain, so the langchain-unison package works directly inside your graph nodes — UnisonRetriever, UnisonMemory, and UnisonChatMessageHistory, no plumbing:

pip install langchain-unison langgraph

Recall in a node, write back in a node

from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langchain_core.messages import SystemMessage
from langchain_unison import UnisonRetriever, UnisonChatMessageHistory

retriever = UnisonRetriever(k=6)  # reads UNISON_TOKEN

class State(TypedDict):
    thread_id: str
    messages: Annotated[list, add_messages]

def recall(state: State):
    """Entry node: pull relevant team memory into the graph's state."""
    docs = retriever.invoke(state["messages"][-1].content)
    if not docs:
        return {}
    memory = "\n".join(d.page_content for d in docs)
    return {"messages": [SystemMessage(content=f"Relevant team memory:\n{memory}")]}

def agent(state: State):
    ...  # your model call; returns {"messages": [ai_message]}

def persist(state: State):
    """Terminal node: write the exchange back so the next run recalls it."""
    history = UnisonChatMessageHistory(session_id=state["thread_id"])
    for message in state["messages"][-2:]:   # the latest user + assistant turn
        history.add_message(message)
    return {}

graph = StateGraph(State)
graph.add_node("recall", recall)
graph.add_node("agent", agent)
graph.add_node("persist", persist)
graph.add_edge(START, "recall")
graph.add_edge("recall", "agent")
graph.add_edge("agent", "persist")
graph.add_edge("persist", END)
app = graph.compile()

The recall node injects team memory into state before the model runs; the persist node writes the exchange back so the next graph run — on any thread, by any teammate's agent — recalls it. Keep your existing checkpointer for thread resumption; Unison is the cross-thread layer on top.

For multi-user products, mint a brain:act-as service key and pass an actor per user (details).

On this page