CrewAI integration
CrewAI agents equipped with Zep’s memory platform can maintain context across conversations, access shared knowledge bases, and make more informed decisions. This integration provides persistent memory storage and intelligent knowledge retrieval for your CrewAI workflows.
Core benefits
- Persistent Memory: Conversations and knowledge persist across sessions
- Context-Aware Agents: Agents automatically retrieve relevant context during execution
- Dual Storage: User-specific memories and shared organizational knowledge
- Intelligent Tools: Search and data addition tools for dynamic knowledge management
How External Memory Works in CrewAI
External memory in CrewAI operates automatically during crew execution, providing seamless context retrieval and persistence across tasks and executions.
Automatic Memory Operations
Key Behaviors:
- Automatic Retrieval: When an agent starts a task, CrewAI automatically queries external memory using the query “{task.description} {context}” to find relevant historical context
- Automatic Storage: When an agent completes a task, CrewAI automatically saves the task output to external memory (if external memory is configured)
- Cross-Execution Persistence: External memory persists between crew runs, enabling agents to learn from previous executions
- Manual Operations: Developers can also manually add data to external memory or query it directly using the storage interface
This automatic behavior means that once you configure Zep as your external memory provider, your CrewAI agents will seamlessly build context from past interactions and contribute new learnings without additional code.
Installation
Requires Python 3.10+, Zep CrewAI >=1.1.1, CrewAI >=0.186.0, and a Zep Cloud API key. Get your API key from app.getzep.com.
Set up your environment variables:
Storage types
User storage
Use ZepUserStorage
for personal context and conversation history:
User storage automatically routes data:
- Messages (
type: "message"
) → Thread API for conversation context - JSON/Text (
type: "json"
ortype: "text"
) → User Graph for preferences
Graph storage
Use ZepGraphStorage
for organizational knowledge that multiple agents can access:
Tool integration
Equip your agents with Zep tools for dynamic knowledge management:
Tool parameters:
Search tool:
query
: Natural language search querylimit
: Maximum results (default: 10)scope
: Search scope - “edges”, “nodes”, “episodes”, or “all”
Add data tool:
data
: Content to store (text, JSON, or message)data_type
: Explicit type - “text”, “json”, or “message”
Advanced patterns
Structured data with ontologies
Define entity models for better knowledge organization:
Multi-agent with mixed storage
Combine user and graph storage for comprehensive memory:
Research and curation workflow
Agents can search existing knowledge and add new discoveries:
Configuration options
ZepUserStorage parameters
client
: Zep client instance (required)user_id
: User identifier (required)thread_id
: Thread identifier (optional, enables conversation context)mode
: Context mode - “summary” or “basic” (default: “summary”)search_filters
: Filter search results by node labels or attributesfacts_limit
: Maximum facts for context (default: 20)entity_limit
: Maximum entities for context (default: 5)
ZepGraphStorage parameters
client
: Zep client instance (required)graph_id
: Graph identifier (required)search_filters
: Filter by node labels (e.g.,{"node_labels": ["Technology"]}
)facts_limit
: Maximum facts for context (default: 20)entity_limit
: Maximum entities for context (default: 5)
Memory routing
The integration automatically routes different data types to appropriate storage:
Complete example
Here’s a complete example showing personal assistance with conversation memory:
Best practices
Storage selection
- Use ZepUserStorage for personal preferences, conversation history, and user-specific context
- Use ZepGraphStorage for shared knowledge, organizational data, and collaborative information
Memory management
- Set up ontologies for structured data organization
- Use search filters to target specific node types and improve relevance
- Combine storage types for comprehensive memory coverage
Tool usage
- Bind tools to specific users or graphs at creation time
- Use search scope “all” sparingly as it’s more expensive
- Add data with appropriate types (message, json, text) for correct routing
- Limit search results appropriately to avoid context bloat
Next steps
- Explore customizing graph structure for advanced knowledge organization
- Learn about searching the graph and how to search the graph
- See code examples for additional patterns