CrewAI integration for Zep
Project description
Zep CrewAI Integration
A comprehensive integration package that enables CrewAI agents to leverage Zep's powerful memory platform for persistent storage, knowledge graphs, and intelligent tool usage.
Installation
pip install zep-crewai
Quick Start
User Storage with Conversation Memory
import os
from zep_cloud.client import Zep
from zep_crewai import ZepUserStorage
from crewai import Agent, Crew, Task
from crewai.memory.external.external_memory import ExternalMemory
# Initialize Zep client
zep_client = Zep(api_key=os.getenv("ZEP_API_KEY"))
# Create user and thread
zep_client.user.add(user_id="alice_123", first_name="Alice")
zep_client.thread.create(user_id="alice_123", thread_id="project_456")
# Create user storage
user_storage = ZepUserStorage(
client=zep_client,
user_id="alice_123",
thread_id="project_456", # Optional: for conversation context
mode="summary" # "summary" or "raw_messages" for thread context
)
# Create crew with user memory
crew = Crew(
agents=[...],
tasks=[...],
external_memory=ExternalMemory(storage=user_storage)
)
Knowledge Graph Storage
from zep_crewai import ZepGraphStorage
# Create graph storage for shared knowledge
graph_storage = ZepGraphStorage(
client=zep_client,
graph_id="company_knowledge",
search_filters={"node_labels": ["Technology", "Project"]}
)
# Create crew with graph memory
crew = Crew(
agents=[...],
tasks=[...],
external_memory=ExternalMemory(storage=graph_storage)
)
Tool-Equipped Agents
from zep_crewai import create_search_tool, create_add_data_tool
# Create tools for user or graph
search_tool = create_search_tool(zep_client, user_id="alice_123")
add_tool = create_add_data_tool(zep_client, graph_id="knowledge_base")
# Create agent with Zep tools
agent = Agent(
role="Knowledge Assistant",
goal="Manage and retrieve information efficiently",
tools=[search_tool, add_tool],
llm="gpt-4o-mini"
)
Features
Storage Classes
ZepUserStorage
Manages user-specific memories and conversations:
- Thread Messages: Conversation history with role-based storage
- User Graph: Personal knowledge, preferences, and context
- Parallel Search: Simultaneous search across threads and graphs
- Search Filters: Target specific node types and relationships
- Thread Context: Uses
thread.get_user_contextwith configurable mode (summary/raw_messages)
ZepGraphStorage
Manages generic knowledge graphs for shared information:
- Structured Knowledge: Store entities with defined ontologies
- Multi-scope Search: Search edges (facts), nodes (entities), and episodes
- Search Filters: Filter by node labels and attributes
- Persistent Storage: Knowledge persists across sessions
- Context Composition: Uses
compose_context_stringfor formatted context
Tool Integration
Search Tool
search_tool = create_search_tool(
zep_client,
user_id="user_123" # OR graph_id="knowledge_base"
)
- Search across edges, nodes, and episodes
- Configurable result limits
- Scope filtering (edges, nodes, episodes, or all)
- Natural language queries
Add Data Tool
add_tool = create_add_data_tool(
zep_client,
graph_id="knowledge_base" # OR user_id="user_123"
)
- Add text, JSON, or message data
- Automatic type detection
- Structured data support
- Metadata preservation
Advanced Usage
Graph Storage with Ontology
Define structured entities for better organization:
from zep_cloud.external_clients.ontology import EntityModel, EntityText
from pydantic import Field
class ProjectEntity(EntityModel):
status: EntityText = Field(description="project status")
priority: EntityText = Field(description="priority level")
team_size: EntityText = Field(description="team size")
# Set ontology
zep_client.graph.set_ontology(
graph_id="projects",
entities={"Project": ProjectEntity},
edges={}
)
# Use with filtered search and context limits
graph_storage = ZepGraphStorage(
client=zep_client,
graph_id="projects",
search_filters={"node_labels": ["Project"]},
facts_limit=20, # Max facts for context
entity_limit=5 # Max entities for context
)
# Get formatted context
context = graph_storage.get_context("project status")
print(context) # Formatted string with facts and entities
Multi-Agent with Mixed Storage
# User-specific storage for personal agent
personal_storage = ZepUserStorage(
client=zep_client,
user_id="user_123",
thread_id="thread_456",
facts_limit=20, # Max facts for context
entity_limit=5, # Max entities for context
mode="summary" # Or "raw_messages" for full conversation history
)
# Get formatted context from thread
context = personal_storage.get_context()
print(context) # Thread context based on configured mode
# Shared knowledge graph for team agent
team_storage = ZepGraphStorage(
client=zep_client,
graph_id="team_knowledge"
)
# Create agents with different storage
personal_agent = Agent(
name="Personal Assistant",
tools=[create_search_tool(zep_client, user_id="user_123")]
)
team_agent = Agent(
name="Team Coordinator",
tools=[create_search_tool(zep_client, graph_id="team_knowledge")]
)
Storage Routing
Different data types are automatically routed:
# Messages go to thread (if thread_id is set)
external_memory.save(
"How can I help you today?",
metadata={"type": "message", "role": "assistant", "name": "Helper"}
)
# JSON data goes to graph
external_memory.save(
'{"project": "Alpha", "status": "active", "budget": 50000}',
metadata={"type": "json"}
)
# Text data goes to graph
external_memory.save(
"Project Alpha requires Python and React expertise",
metadata={"type": "text"}
)
Examples
Complete Examples
- User Storage: Personal assistant with conversation memory
- Graph Storage: Knowledge graph with ontology
- Tools Usage: Agents using search and add tools
- Simple Example: Basic setup and usage
Common Patterns
Personal Assistant
# Store user preferences and context
user_storage = ZepUserStorage(client=zep_client, user_id="user_123")
external_memory = ExternalMemory(storage=user_storage)
# Agent automatically retrieves relevant context
personal_assistant = Agent(
role="Personal Assistant",
backstory="You know the user's preferences and history"
)
Knowledge Base Management
# Shared knowledge with search tools
knowledge_tools = [
create_search_tool(zep_client, graph_id="knowledge"),
create_add_data_tool(zep_client, graph_id="knowledge")
]
curator = Agent(
role="Knowledge Curator",
tools=knowledge_tools,
backstory="You maintain the organization's knowledge base"
)
Multi-Modal Memory
# Combine user and graph storage with tools
research_agent = Agent(
role="Research Analyst",
tools=[
create_search_tool(zep_client, user_id="user_123"),
create_search_tool(zep_client, graph_id="research_data")
],
backstory="You analyze both personal and organizational data"
)
Configuration
Environment Variables
# Required: Your Zep Cloud API key
export ZEP_API_KEY="your-zep-api-key"
Storage Parameters
ZepUserStorage
client: Zep client instance (required)user_id: User identifier (required)thread_id: Thread identifier (optional)search_filters: Search filters (optional)facts_limit: Maximum facts for context (default: 20)entity_limit: Maximum entities for context (default: 5)mode: Context retrieval mode - "summary" or "raw_messages" (default: "summary")
ZepGraphStorage
client: Zep client instance (required)graph_id: Graph identifier (required)search_filters: Search filters (optional)facts_limit: Maximum facts for context (default: 20)entity_limit: Maximum entities for context (default: 5)
Tool Parameters
Search Tool
query: Search query stringlimit: Maximum results (default: 10)scope: Search scope - "edges", "nodes", "episodes", or "all"
Add Data Tool
data: Content to storedata_type: Type - "text", "json", or "message"
Development
Setup
# Clone the repository
git clone https://github.com/getzep/zep.git
cd integrations/python/zep_crewai
# Install dependencies
pip install -e .
pip install -r requirements-dev.txt
Testing
# Run tests
pytest tests/
# Run with coverage
pytest --cov=zep_crewai tests/
Type Checking
mypy src/zep_crewai
Requirements
- Python 3.10+
zep-cloud>=3.0.0crewai>=0.80.0pydantic>=2.0.0
Best Practices
-
Storage Selection
- Use
ZepUserStoragefor user-specific, personal data - Use
ZepGraphStoragefor shared, organizational knowledge
- Use
-
Tool Usage
- Bind tools to specific users or graphs at creation
- Use search scope "all" sparingly (more expensive)
- Add data with appropriate types for better organization
-
Memory Management
- Set up ontologies for structured data
- Use search filters to improve relevance
- Combine storage types for comprehensive memory
-
Performance
- Allow 10-20 seconds for data processing after additions
- Use parallel search for better performance
- Limit search results appropriately
Support
License
Apache 2.0 - see LICENSE for details.
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zep_crewai-1.1.1.tar.gz.
File metadata
- Download URL: zep_crewai-1.1.1.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c0247a89e6c53e941737067efa9be9e7b53a3b01660085c5f074008b38569b8
|
|
| MD5 |
1c2010a624b8f6ef81a57f050d2cd188
|
|
| BLAKE2b-256 |
1395925bf4d4897f486703d1b2ea39498f6ffc68febc7b0cb16d70768e9e9a7b
|
Provenance
The following attestation bundles were made for zep_crewai-1.1.1.tar.gz:
Publisher:
release-integrations.yml on getzep/zep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zep_crewai-1.1.1.tar.gz -
Subject digest:
5c0247a89e6c53e941737067efa9be9e7b53a3b01660085c5f074008b38569b8 - Sigstore transparency entry: 500683252
- Sigstore integration time:
-
Permalink:
getzep/zep@e49678ed33b46349f299ae1b058ba8184c257bed -
Branch / Tag:
refs/tags/zep-crewai-v1.1.1 - Owner: https://github.com/getzep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-integrations.yml@e49678ed33b46349f299ae1b058ba8184c257bed -
Trigger Event:
release
-
Statement type:
File details
Details for the file zep_crewai-1.1.1-py3-none-any.whl.
File metadata
- Download URL: zep_crewai-1.1.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f3bdeb09c82d9d1d7a9c934e480874a9703b644a14af3a1bf029345a6dfa323
|
|
| MD5 |
5c6c611e14b3e722b7eb30d2d4724b0c
|
|
| BLAKE2b-256 |
a8636d96bc62ccca771c0ea5bb16d6bedb4ff79a9f0569d41c6f5923dec395dd
|
Provenance
The following attestation bundles were made for zep_crewai-1.1.1-py3-none-any.whl:
Publisher:
release-integrations.yml on getzep/zep
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zep_crewai-1.1.1-py3-none-any.whl -
Subject digest:
5f3bdeb09c82d9d1d7a9c934e480874a9703b644a14af3a1bf029345a6dfa323 - Sigstore transparency entry: 500683265
- Sigstore integration time:
-
Permalink:
getzep/zep@e49678ed33b46349f299ae1b058ba8184c257bed -
Branch / Tag:
refs/tags/zep-crewai-v1.1.1 - Owner: https://github.com/getzep
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-integrations.yml@e49678ed33b46349f299ae1b058ba8184c257bed -
Trigger Event:
release
-
Statement type: