zep-crewai 0.1.0__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,10 @@ dist/
44
44
  downloads/
45
45
  eggs/
46
46
  .eggs/
47
- lib/
47
+ lib/**/*.py
48
+ lib/**/*.pyc
49
+ lib/**/__pycache__/
50
+ lib/**/site-packages/
48
51
  lib64/
49
52
  parts/
50
53
  sdist/
@@ -0,0 +1,404 @@
1
+ Metadata-Version: 2.4
2
+ Name: zep-crewai
3
+ Version: 1.1.0
4
+ Summary: CrewAI integration for Zep
5
+ Project-URL: Homepage, https://github.com/getzep/zep
6
+ Project-URL: Documentation, https://help.getzep.com
7
+ Project-URL: Repository, https://github.com/getzep/zep
8
+ Project-URL: Bug Tracker, https://github.com/getzep/zep/issues
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: aiohttp>=3.8.0
11
+ Requires-Dist: crewai>=0.80.0
12
+ Requires-Dist: python-dotenv>=1.0.0
13
+ Requires-Dist: python-slugify>=8.0.4
14
+ Requires-Dist: rich>=14.0.0
15
+ Requires-Dist: zep-cloud>=3.4.1
16
+ Provides-Extra: dev
17
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
18
+ Requires-Dist: pytest-asyncio; extra == 'dev'
19
+ Requires-Dist: pytest-cov; extra == 'dev'
20
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
21
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Zep CrewAI Integration
25
+
26
+ A comprehensive integration package that enables [CrewAI](https://github.com/joaomdmoura/crewai) agents to leverage [Zep](https://getzep.com)'s powerful memory platform for persistent storage, knowledge graphs, and intelligent tool usage.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install zep-crewai
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ### User Storage with Conversation Memory
37
+
38
+ ```python
39
+ import os
40
+ from zep_cloud.client import Zep
41
+ from zep_crewai import ZepUserStorage
42
+ from crewai import Agent, Crew, Task
43
+ from crewai.memory.external.external_memory import ExternalMemory
44
+
45
+ # Initialize Zep client
46
+ zep_client = Zep(api_key=os.getenv("ZEP_API_KEY"))
47
+
48
+ # Create user and thread
49
+ zep_client.user.add(user_id="alice_123", first_name="Alice")
50
+ zep_client.thread.create(user_id="alice_123", thread_id="project_456")
51
+
52
+ # Create user storage
53
+ user_storage = ZepUserStorage(
54
+ client=zep_client,
55
+ user_id="alice_123",
56
+ thread_id="project_456", # Optional: for conversation context
57
+ mode="summary" # "summary" or "raw_messages" for thread context
58
+ )
59
+
60
+ # Create crew with user memory
61
+ crew = Crew(
62
+ agents=[...],
63
+ tasks=[...],
64
+ external_memory=ExternalMemory(storage=user_storage)
65
+ )
66
+ ```
67
+
68
+ ### Knowledge Graph Storage
69
+
70
+ ```python
71
+ from zep_crewai import ZepGraphStorage
72
+
73
+ # Create graph storage for shared knowledge
74
+ graph_storage = ZepGraphStorage(
75
+ client=zep_client,
76
+ graph_id="company_knowledge",
77
+ search_filters={"node_labels": ["Technology", "Project"]}
78
+ )
79
+
80
+ # Create crew with graph memory
81
+ crew = Crew(
82
+ agents=[...],
83
+ tasks=[...],
84
+ external_memory=ExternalMemory(storage=graph_storage)
85
+ )
86
+ ```
87
+
88
+ ### Tool-Equipped Agents
89
+
90
+ ```python
91
+ from zep_crewai import create_search_tool, create_add_data_tool
92
+
93
+ # Create tools for user or graph
94
+ search_tool = create_search_tool(zep_client, user_id="alice_123")
95
+ add_tool = create_add_data_tool(zep_client, graph_id="knowledge_base")
96
+
97
+ # Create agent with Zep tools
98
+ agent = Agent(
99
+ role="Knowledge Assistant",
100
+ goal="Manage and retrieve information efficiently",
101
+ tools=[search_tool, add_tool],
102
+ llm="gpt-4o-mini"
103
+ )
104
+ ```
105
+
106
+ ## Features
107
+
108
+ ### Storage Classes
109
+
110
+ #### ZepUserStorage
111
+ Manages user-specific memories and conversations:
112
+ - **Thread Messages**: Conversation history with role-based storage
113
+ - **User Graph**: Personal knowledge, preferences, and context
114
+ - **Parallel Search**: Simultaneous search across threads and graphs
115
+ - **Search Filters**: Target specific node types and relationships
116
+ - **Thread Context**: Uses `thread.get_user_context` with configurable mode (summary/raw_messages)
117
+
118
+ #### ZepGraphStorage
119
+ Manages generic knowledge graphs for shared information:
120
+ - **Structured Knowledge**: Store entities with defined ontologies
121
+ - **Multi-scope Search**: Search edges (facts), nodes (entities), and episodes
122
+ - **Search Filters**: Filter by node labels and attributes
123
+ - **Persistent Storage**: Knowledge persists across sessions
124
+ - **Context Composition**: Uses `compose_context_string` for formatted context
125
+
126
+ ### Tool Integration
127
+
128
+ #### Search Tool
129
+ ```python
130
+ search_tool = create_search_tool(
131
+ zep_client,
132
+ user_id="user_123" # OR graph_id="knowledge_base"
133
+ )
134
+ ```
135
+ - Search across edges, nodes, and episodes
136
+ - Configurable result limits
137
+ - Scope filtering (edges, nodes, episodes, or all)
138
+ - Natural language queries
139
+
140
+ #### Add Data Tool
141
+ ```python
142
+ add_tool = create_add_data_tool(
143
+ zep_client,
144
+ graph_id="knowledge_base" # OR user_id="user_123"
145
+ )
146
+ ```
147
+ - Add text, JSON, or message data
148
+ - Automatic type detection
149
+ - Structured data support
150
+ - Metadata preservation
151
+
152
+ ## Advanced Usage
153
+
154
+ ### Graph Storage with Ontology
155
+
156
+ Define structured entities for better organization:
157
+
158
+ ```python
159
+ from zep_cloud.external_clients.ontology import EntityModel, EntityText
160
+ from pydantic import Field
161
+
162
+ class ProjectEntity(EntityModel):
163
+ status: EntityText = Field(description="project status")
164
+ priority: EntityText = Field(description="priority level")
165
+ team_size: EntityText = Field(description="team size")
166
+
167
+ # Set ontology
168
+ zep_client.graph.set_ontology(
169
+ graph_id="projects",
170
+ entities={"Project": ProjectEntity},
171
+ edges={}
172
+ )
173
+
174
+ # Use with filtered search and context limits
175
+ graph_storage = ZepGraphStorage(
176
+ client=zep_client,
177
+ graph_id="projects",
178
+ search_filters={"node_labels": ["Project"]},
179
+ facts_limit=20, # Max facts for context
180
+ entity_limit=5 # Max entities for context
181
+ )
182
+
183
+ # Get formatted context
184
+ context = graph_storage.get_context("project status")
185
+ print(context) # Formatted string with facts and entities
186
+ ```
187
+
188
+ ### Multi-Agent with Mixed Storage
189
+
190
+ ```python
191
+ # User-specific storage for personal agent
192
+ personal_storage = ZepUserStorage(
193
+ client=zep_client,
194
+ user_id="user_123",
195
+ thread_id="thread_456",
196
+ facts_limit=20, # Max facts for context
197
+ entity_limit=5, # Max entities for context
198
+ mode="summary" # Or "raw_messages" for full conversation history
199
+ )
200
+
201
+ # Get formatted context from thread
202
+ context = personal_storage.get_context()
203
+ print(context) # Thread context based on configured mode
204
+
205
+ # Shared knowledge graph for team agent
206
+ team_storage = ZepGraphStorage(
207
+ client=zep_client,
208
+ graph_id="team_knowledge"
209
+ )
210
+
211
+ # Create agents with different storage
212
+ personal_agent = Agent(
213
+ name="Personal Assistant",
214
+ tools=[create_search_tool(zep_client, user_id="user_123")]
215
+ )
216
+
217
+ team_agent = Agent(
218
+ name="Team Coordinator",
219
+ tools=[create_search_tool(zep_client, graph_id="team_knowledge")]
220
+ )
221
+ ```
222
+
223
+ ### Storage Routing
224
+
225
+ Different data types are automatically routed:
226
+
227
+ ```python
228
+ # Messages go to thread (if thread_id is set)
229
+ external_memory.save(
230
+ "How can I help you today?",
231
+ metadata={"type": "message", "role": "assistant", "name": "Helper"}
232
+ )
233
+
234
+ # JSON data goes to graph
235
+ external_memory.save(
236
+ '{"project": "Alpha", "status": "active", "budget": 50000}',
237
+ metadata={"type": "json"}
238
+ )
239
+
240
+ # Text data goes to graph
241
+ external_memory.save(
242
+ "Project Alpha requires Python and React expertise",
243
+ metadata={"type": "text"}
244
+ )
245
+ ```
246
+
247
+ ## Examples
248
+
249
+ ### Complete Examples
250
+
251
+ - **[User Storage](examples/crewai_user.py)**: Personal assistant with conversation memory
252
+ - **[Graph Storage](examples/crewai_graph.py)**: Knowledge graph with ontology
253
+ - **[Tools Usage](examples/crewai_tools.py)**: Agents using search and add tools
254
+ - **[Simple Example](examples/simple_example.py)**: Basic setup and usage
255
+
256
+ ### Common Patterns
257
+
258
+ #### Personal Assistant
259
+ ```python
260
+ # Store user preferences and context
261
+ user_storage = ZepUserStorage(client=zep_client, user_id="user_123")
262
+ external_memory = ExternalMemory(storage=user_storage)
263
+
264
+ # Agent automatically retrieves relevant context
265
+ personal_assistant = Agent(
266
+ role="Personal Assistant",
267
+ backstory="You know the user's preferences and history"
268
+ )
269
+ ```
270
+
271
+ #### Knowledge Base Management
272
+ ```python
273
+ # Shared knowledge with search tools
274
+ knowledge_tools = [
275
+ create_search_tool(zep_client, graph_id="knowledge"),
276
+ create_add_data_tool(zep_client, graph_id="knowledge")
277
+ ]
278
+
279
+ curator = Agent(
280
+ role="Knowledge Curator",
281
+ tools=knowledge_tools,
282
+ backstory="You maintain the organization's knowledge base"
283
+ )
284
+ ```
285
+
286
+ #### Multi-Modal Memory
287
+ ```python
288
+ # Combine user and graph storage with tools
289
+ research_agent = Agent(
290
+ role="Research Analyst",
291
+ tools=[
292
+ create_search_tool(zep_client, user_id="user_123"),
293
+ create_search_tool(zep_client, graph_id="research_data")
294
+ ],
295
+ backstory="You analyze both personal and organizational data"
296
+ )
297
+ ```
298
+
299
+ ## Configuration
300
+
301
+ ### Environment Variables
302
+
303
+ ```bash
304
+ # Required: Your Zep Cloud API key
305
+ export ZEP_API_KEY="your-zep-api-key"
306
+ ```
307
+
308
+ ### Storage Parameters
309
+
310
+ #### ZepUserStorage
311
+ - `client`: Zep client instance (required)
312
+ - `user_id`: User identifier (required)
313
+ - `thread_id`: Thread identifier (optional)
314
+ - `search_filters`: Search filters (optional)
315
+ - `facts_limit`: Maximum facts for context (default: 20)
316
+ - `entity_limit`: Maximum entities for context (default: 5)
317
+ - `mode`: Context retrieval mode - "summary" or "raw_messages" (default: "summary")
318
+
319
+ #### ZepGraphStorage
320
+ - `client`: Zep client instance (required)
321
+ - `graph_id`: Graph identifier (required)
322
+ - `search_filters`: Search filters (optional)
323
+ - `facts_limit`: Maximum facts for context (default: 20)
324
+ - `entity_limit`: Maximum entities for context (default: 5)
325
+
326
+ ### Tool Parameters
327
+
328
+ #### Search Tool
329
+ - `query`: Search query string
330
+ - `limit`: Maximum results (default: 10)
331
+ - `scope`: Search scope - "edges", "nodes", "episodes", or "all"
332
+
333
+ #### Add Data Tool
334
+ - `data`: Content to store
335
+ - `data_type`: Type - "text", "json", or "message"
336
+
337
+ ## Development
338
+
339
+ ### Setup
340
+ ```bash
341
+ # Clone the repository
342
+ git clone https://github.com/getzep/zep.git
343
+ cd integrations/python/zep_crewai
344
+
345
+ # Install dependencies
346
+ pip install -e .
347
+ pip install -r requirements-dev.txt
348
+ ```
349
+
350
+ ### Testing
351
+ ```bash
352
+ # Run tests
353
+ pytest tests/
354
+
355
+ # Run with coverage
356
+ pytest --cov=zep_crewai tests/
357
+ ```
358
+
359
+ ### Type Checking
360
+ ```bash
361
+ mypy src/zep_crewai
362
+ ```
363
+
364
+ ## Requirements
365
+
366
+ - Python 3.10+
367
+ - `zep-cloud>=3.0.0`
368
+ - `crewai>=0.80.0`
369
+ - `pydantic>=2.0.0`
370
+
371
+ ## Best Practices
372
+
373
+ 1. **Storage Selection**
374
+ - Use `ZepUserStorage` for user-specific, personal data
375
+ - Use `ZepGraphStorage` for shared, organizational knowledge
376
+
377
+ 2. **Tool Usage**
378
+ - Bind tools to specific users or graphs at creation
379
+ - Use search scope "all" sparingly (more expensive)
380
+ - Add data with appropriate types for better organization
381
+
382
+ 3. **Memory Management**
383
+ - Set up ontologies for structured data
384
+ - Use search filters to improve relevance
385
+ - Combine storage types for comprehensive memory
386
+
387
+ 4. **Performance**
388
+ - Allow 10-20 seconds for data processing after additions
389
+ - Use parallel search for better performance
390
+ - Limit search results appropriately
391
+
392
+ ## Support
393
+
394
+ - [Zep Documentation](https://help.getzep.com)
395
+ - [CrewAI Documentation](https://docs.crewai.com)
396
+ - [GitHub Issues](https://github.com/getzep/zep/issues)
397
+
398
+ ## License
399
+
400
+ Apache 2.0 - see [LICENSE](LICENSE) for details.
401
+
402
+ ## Contributing
403
+
404
+ Contributions are welcome! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details.