CrewAI integration
Add long-term agent memory and knowledge graphs to CrewAI agents
The zep-crewai package gives CrewAI agents persistent memory backed by Zep’s temporal knowledge graph. You persist conversation turns and business data with Zep storage adapters, and give your agents Zep tools so they can retrieve relevant context when they need it. This lets agents carry context across executions, share a common knowledge base, and ground their decisions in what was learned before.
Core benefits
- Persistent memory — Conversations and knowledge persist across sessions and crew runs.
- On-demand retrieval — Agents search Zep through tools and pull in context exactly when a task calls for it.
- Dual storage — User-specific memory for individuals and shared knowledge graphs for organizational data.
- Tool integration — Search and add-data tools let agents read from and write to Zep during execution.
How it works
Memory in this integration is explicit and tool-driven. There are two distinct steps, and you control both.
Persisting context. Create a ZepUserStorage or ZepGraphStorage adapter and call storage.save(value, metadata={"type": ...}). The adapter routes each item by its type:
Retrieving context. Attach create_search_tool (and optionally create_add_data_tool) to an Agent(tools=[...]). The agent searches Zep when it decides the task needs it. You can also call ZepUserStorage.get_context() directly to fetch the prompt-ready context block that Zep auto-assembles for a thread.
There is no automatic retrieval or storage, and no external_memory= Crew wiring. CrewAI 1.x removed the ExternalMemory(storage=...) wrapper and the storage interface it depended on, so context is never injected behind the scenes. You decide what to save with save(...), and the agent decides what to search through its tools.
Installation
Requires Python 3.11+, zep-crewai>=1.1.2, crewai>=1.0.0, and zep-cloud>=3.23.0, plus a Zep Cloud API key. Get your API key from app.getzep.com.
Set your API key in the environment:
Storage types
User storage
Use ZepUserStorage for an individual user’s conversation history and personal context. A thread_id is required and ties message storage to a conversation thread.
To fetch the auto-assembled context block for the thread directly, call get_context():
Graph storage
Use ZepGraphStorage for shared organizational knowledge that multiple agents can read and write.
You can also search a graph directly. search returns a list whose entries include a composed context string:
Tool integration
Tools are the supported extension point for exposing Zep to CrewAI agents. Bind a tool to a single user or a single graph at creation time, then add it to an agent’s tools list.
Search tool parameters:
query— Natural language search query.limit— Maximum results (default: 10).scope— Search scope:edges(default),nodes,episodes, orall.
Add-data tool parameters:
data— Content to store (text, JSON, or message).data_type— Explicit type:text(default),json, ormessage.
Structured data with ontologies
Define entity models so Zep organizes graph data into typed entities. The SDK requires a docstring on each entity class to describe it.
Configuration options
ZepUserStorage parameters
client— Zep client instance (required).user_id— User identifier (required).thread_id— Thread identifier (required); ties message storage to a conversation thread.search_filters— Filter search results by node labels or attributes.facts_limit— Maximum facts (edges) for context (default: 20).entity_limit— Maximum entities (nodes) for context (default: 5).
ZepGraphStorage parameters
client— Zep client instance (required).graph_id— Graph identifier (required).search_filters— Filter by node labels, for exampleSearchFilters(node_labels=["Technology"]).facts_limit— Maximum facts (edges) for context (default: 20).entity_limit— Maximum entities (nodes) for context (default: 5).
Complete example
This example mirrors the simple_example.py from the integration repository. It persists conversation turns and business data to a user’s memory, then runs an agent that searches that memory through a Zep tool before answering.
Best practices
Storage selection
- Use
ZepUserStoragefor personal preferences, conversation history, and user-specific context. - Use
ZepGraphStoragefor shared knowledge, organizational data, and collaborative information.
Memory management
- Set up ontologies for structured graph data, and give every entity class a docstring.
- Use search filters to target specific node types and improve relevance.
- Combine storage types for comprehensive memory coverage.
Tool usage
- Bind tools to a specific user or graph at creation time.
- Use search scope
allsparingly — it queries edges, nodes, and episodes and is more expensive. - Save data with the right
type(message,json, ortext) so it routes correctly. - 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 additional patterns