LangGraph × cognee: Enhancing Agents with Persistent, Queryable Memory
LangGraph agents excel in single-session workflows, with robust state management capabilities. Yet, preserving context across separate runs often demands additional infrastructure, like using checkpointers with thread_ids for short-term continuity or the LangChain Store for long-term memory.
The LangGraph-cognee integration complements this by weaving in a semantic memory layer that fits naturally into LangGraph's existing tool ecosystem. While the Store offers simple key-value persistence, cognee delivers richer, queryable layers via embeddings and graphs.
What developers get out-of-the-box:
- Reliable Control: LangGraph's deterministic edges and conditional routing, paired with cognee's tools.
- Simplified Agents: Use create_react_agent for tooling-driven flows, no custom orchestration needed.
- Modular Memory: Add, search, prune, and visualize with cognee, building incrementally.
- Scoped Sessions: Multi-tenant or per-user isolation, keeping data clean without custom agent wrappers.
Core Mechanics: The cognee-LangGraph Workflow
The integration provides sessionized memory tools based on cognee’s core features. Agents store data in cognee's knowledge graph with embeddings, then query it semantically—leveraging LangGraph's tool-calling capabilities while adding persistent memory functionality.
Here's the basic flow:
- Storage: Use add_tool to ingest data into cognee’s graph.
- Processing: cognee structures it with entities, relationships, and embeddings automatically.
- Isolation: Each user session maintains grouped node sets (think schemas in relational store) for organized, leak-proof memory.
- Retrieval: Agents query stored information with search_tool using natural language.
- Context continuity: Knowledge persists across agent instances and conversation sessions.
- Incremental enrichment: cognee can connect previously stored information (e.g., business data) to information ingested in new sessions.
Real-World Demo: Cross-Session Context Recall
Say we have two sessions days apart: In session one, the agent records contract details from messaging with a human; in session two, a different agent instance asks for “healthcare contracts” and immediately surfaces all the relevant information stored in cognee’s memory (including all the contracts in healthcare industry that were already there).
This works via:
- Fact Fact Recall: cognee's thread-independent semantic memory.
- Decision Tool Loop: LangGraph's ReAct pattern for when to add, search, or respond.
The integration follows LangGraph's standard tool patterns:
The Value of Sessionization: Clean Isolation and Global Access
LangGraph isolates short-term state via thread_id and durable memory through namespaces (e.g., org_id, user_id). cognee layers on this with external semantic memory, respecting boundaries while simplifying ops.
Using user_id scopes cognee's stores so:
- Session vs. Global: Per-run data (thread_id-scoped) stays separate from broader inputs (documents/datasets) ingested “out-of-session” under the user namespace.
- Out-of-Session Adds: Ingest data anytime and still retrieve/visualize it alongside session data, yielding clear clusters by session versus global inputs.
You can also enable cognee’s user management features if users want separate databases so that personalization doesn’t leak across users or threads (multi-tenant isolation by user/org).
Cross-Session Persistence
The key benefit of the integration is the ability to maintain context across separate agent instances. Below is a simplified version of creating different agent instances that:
- Has no conversation history from the previous agent
- Has no internal state carried over
- Can access all information stored in Cognee's knowledge graph
Below you can explore the graph example as an output of the notebook (hover over to see node and edge properties).
User Session Isolation
The integration also provides session isolation for better memory management:
You can see the sessionized graph example example above. Run the notebook to clearly observe session-based data clustering:
- Session Cluster: All data processed within our specific session is grouped together around the session identifier
- Global Data: Information added outside the session forms a separate cluster
- Clean Separation: The two data groups remain distinct while still being part of the same knowledge graph
This demonstrates how cognee maintains both session isolation and global knowledge accessibility.
Technical Implementation Details
The integration handles several technical considerations. LangGraph can make tool calls concurrently, and we want to make sure cognee slots in seamlessly.
Incorporating new data into cognee is a two step process:
- .add() - imports data, but doesn’t rebuild knowledge graph yet
- .cognify() - actually rebuilds knowledge graph
We can run .add() and .cognify() one after the other or run .cognify() once, after multiple .add() runs completed. Interaction with LangGraph can vary from user to user.
Below we will cover both scenarios by leveraging async queues and waiting for some time for new queue inputs (2 seconds here) before cognifying the data.
Async Operations
Thread Safety
- Dedicated locks prevent race conditions during initialization
- Queue management for efficient batch processing
Tool Integration
The memory tools follow LangChain's tool specifications:
Understanding Session ID Generation
Let's explore how session management works under the hood via get_sessionized_cognee_tools():
Sessionization by definition requires a unique session_id to identify distinct sessions. To preserve the UX of using LangGraph tools, we return tools just as any other integration, but before that we create the session_id and use closures to make tools aware of the state.
Use Cases and Patterns
The integration enables several practical patterns:
- Knowledge Accumulation—Agents can build domain knowledge over multiple interactions:
- Context-Aware Assistance—Maintain user context across work sessions:
Looking Ahead: Expanding Agent Capabilities
This initial setup taps just part of cognee’s potential—enrichment, temporal awareness, and self-improving loops could further extend LangGraph agents’ functionalities and performance.
Jump In: Setting Up the Integration
The integration aims to provide a straightforward way to add cognee’s semantic memory to LangGraph agents while maintaining compatibility with existing LangGraph patterns and best practices.
To begin using persistent memory with your LangGraph agents:
1- Go to the integration repo or install the integration package
2- Configure session management for your application
3- Add cognee memory tools to your agent's tool list
4- Test cross-session persistence in your use case
Last but not least, join our community and star our repo to help us reach more developers.

LangGraph × cognee: Enhancing Agents with Persistent, Queryable Memory

🚀 cognee Update: September 2025
