LangGraph integration
Add durable, cross-session memory to LangGraph agents
LangGraph agents using Zep gain durable, cross-session memory backed by a temporal knowledge graph. The zep-langgraph package wires Zep into your graph nodes: it injects the user’s context block into the system prompt, persists each turn, and exposes a graph-search tool the model can call on demand.
A complete notebook example is available in the Zep repository.
Core benefits
- Context injection: Fold the user’s context block into the system prompt on every turn
- Per-turn persistence: Write each conversation turn back to Zep with a single helper
- On-demand graph search: Expose a LangChain tool the model calls to search the knowledge graph
BaseStoresupport: UseZepStoreforcreate_react_agent(store=...)and langmem’s memory tools- Async and sync clients: Every helper has both an async and a synchronous variant
- Graceful degradation: A Zep failure is logged but never crashes the host agent
How it works
The package ships two layers. The node and tool helpers (the primary path) call Zep directly inside your graph nodes; this matches Zep’s recommended LangGraph pattern. ZepStore (secondary) is a BaseStore implementation for callers who need one — e.g. create_react_agent(store=...) or langmem’s memory tools.
The Zep loop is the same everywhere — create user, create thread, add messages, retrieve context — and each step is wrapped as a helper you call from a graph node:
build_system_message— fetches the context block (thread.get_user_context) assembled from the entire user graph and folds it into aSystemMessagewith your base instructions, ready to prepend to the model’s message list.get_zep_contextreturns just the raw block.persist_messages— wrapsthread.add_messages. Accepts LangChainBaseMessageobjects (converted automatically) or native ZepMessageobjects, flattens multimodal content to text, and maps names so Zep can resolve identity. Passreturn_context=Trueto fold persist and retrieve into one round-trip.create_graph_search_tool— returns a LangChainStructuredToolovergraph.search. Pass it tocreate_react_agent(tools=[...])and the model decides when to search. Exactly one ofuser_id(the user’s personal graph) orgraph_id(a shared standalone graph) is required. The target and search parameters are fixed at construction, so the model only supplies the query.
Identity is yours to manage — create the Zep user and thread out-of-band before the first turn.
Installation
Requires Python 3.11+, langgraph>=1.2.5, and a Zep Cloud API key. Get your API key from app.getzep.com.
Set up your environment variables:
Usage
Inject context with a prompt callable, expose the graph-search tool, and persist each turn. See the runnable examples for additional patterns.
Long-term memory with ZepStore
BaseStore is LangGraph’s cross-thread long-term-memory interface; create_react_agent(store=...) and langmem’s memory tools require one. Zep is a temporal knowledge graph, not a key-value store, so it can’t faithfully serve exact-key reads or read-after-write on its own. ZepStore bridges this with a hybrid-delegate design: a backing key-value store (default InMemoryStore) serves exact-key get / put / delete synchronously, while every put is also ingested into Zep and search is routed to Zep’s semantic graph.search.
Zep ingestion is asynchronous. A value written with put is available immediately for exact-key get (served by the backing store), but its extracted facts are not instantly returned by search. ZepStore is the long-term memory layer, not the checkpointer, so graph execution and short-term state are unaffected.
Public API
Both an AsyncZep (async helpers, recommended) and a synchronous Zep client are supported. Reuse a single client instance.
Best practices
- Create the user and thread out-of-band before the first turn — identity is yours to manage
- Pass real names to
persist_messagesso Zep can resolve the user’s identity node - Use the async helpers with
AsyncZepfor non-blocking nodes; the_syncvariants exist for synchronous graphs - Allow time for indexing — Zep extracts knowledge asynchronously, so facts from a turn are not instantly searchable
Next steps
- Explore customizing graph structure for advanced knowledge organization
- Learn about searching the graph and how to tune search
- See code examples for the
create_react_agentandZepStorepatterns