Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/python/zep_crewai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mypy src/zep_crewai
- Combine storage types for comprehensive memory

4. **Performance**
- Allow 10-20 seconds for data indexing after additions
- Allow 10-20 seconds for data processing after additions
- Use parallel search for better performance
- Limit search results appropriately

Expand Down
10 changes: 7 additions & 3 deletions integrations/python/zep_crewai/examples/crewai_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from crewai import Agent, Crew, Process, Task
from crewai.memory.external.external_memory import ExternalMemory
from pydantic import Field
from zep_cloud import SearchFilters
from zep_cloud.client import Zep
from zep_cloud.external_clients.ontology import EntityModel, EntityText

Expand Down Expand Up @@ -53,13 +54,16 @@ def main():

# Create a unique graph ID for this example
graph_id = f"tech_knowledge_{uuid.uuid4().hex[:8]}"
zep_client.graph.create(
graph_id=graph_id,
)
print(f"📊 Graph ID: {graph_id}")

# Set up ontology for the graph
print("\n📚 Setting up graph ontology...")
try:
zep_client.graph.set_ontology(
graph_id=graph_id,
graph_ids=[graph_id],
entities={
"Technology": TechnologyEntity,
"Company": CompanyEntity,
Expand All @@ -74,7 +78,7 @@ def main():
graph_storage = ZepGraphStorage(
client=zep_client,
graph_id=graph_id,
search_filters={"node_labels": ["Technology", "Company"]},
search_filters=SearchFilters(node_labels=["Technology", "Company"]),
)
external_memory = ExternalMemory(storage=graph_storage)

Expand Down Expand Up @@ -135,7 +139,7 @@ def main():
print(" • Technology entities with categories and use cases")
print(" • Company entities with industry and tech stack")
print(" • Relationships and facts about technologies and companies")
print(" (Waiting 20 seconds for data indexing...)")
print(" (Waiting 20 seconds for data processing...)")
time.sleep(20)

# Create specialized agents
Expand Down
34 changes: 13 additions & 21 deletions integrations/python/zep_crewai/examples/crewai_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,18 @@ def main():
print(f"👤 User ID: {user_id}")
print(f"📊 Graph ID: {graph_id}")

# Create user
print("\n👥 Setting up user...")
try:
zep_client.user.add(
user_id=user_id,
first_name="Bob",
last_name="Smith",
email="bob.smith@example.com",
metadata={
"role": "Data Scientist",
"department": "Analytics",
"skills": ["Python", "SQL", "Machine Learning"],
},
)
print("✅ User created")
except Exception as e:
if "already exists" in str(e).lower():
print("✅ User already exists")
else:
print(f"⚠️ User creation issue: {e}")
zep_client.user.add(
user_id=user_id,
first_name="Bob",
last_name="Smith",
email="bob.smith@example.com",
)
print("✅ User created")

zep_client.graph.create(
graph_id=graph_id,
)
print("✅ Graph created")

# Create tools for user-specific storage
user_search_tool = create_search_tool(zep_client, user_id=user_id)
Expand Down Expand Up @@ -147,7 +139,7 @@ def main():
print(f"Setup failed: {e}")
return

print("\n⏳ Waiting 20 seconds for data indexing...")
print("\n⏳ Waiting 20 seconds for data processing...")
time.sleep(20)

# Task 3: Search and analyze
Expand Down
2 changes: 1 addition & 1 deletion integrations/python/zep_crewai/examples/crewai_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def main():
print(" • Conversation history → Thread API")
print(" • User preferences → User Graph")
print(" • Project information → User Graph")
print(" (Waiting 20 seconds for data indexing...)")
print(" (Waiting 20 seconds for data processing...)")
time.sleep(20)

# Create specialized agents
Expand Down
4 changes: 2 additions & 2 deletions integrations/python/zep_crewai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "zep-crewai"
version = "0.1.0"
version = "1.0.0"
description = "CrewAI integration for Zep"
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -10,7 +10,7 @@ dependencies = [
"python-dotenv>=1.0.0",
"python-slugify>=8.0.4",
"rich>=14.0.0",
"zep-cloud>=3.0.0rc1",
"zep-cloud>=3.4.1",
]

[project.urls]
Expand Down
43 changes: 24 additions & 19 deletions integrations/python/zep_crewai/src/zep_crewai/graph_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,30 @@ def search(
Returns:
List with a single dict containing the composed context string
"""
# Use the shared utility function for graph search and context composition
context = search_graph_and_compose_context(
client=self._client,
query=query,
graph_id=self._graph_id,
facts_limit=self._facts_limit,
entity_limit=self._entity_limit,
episodes_limit=limit,
search_filters=self._search_filters,
)

if context:
self._logger.info(f"Composed context for query: {query}")
return [
{"context": context, "type": "graph_context", "source": "graph", "query": query}
]

self._logger.info(f"No results found for query: {query}")
return []
try:
# Use the shared utility function for graph search and context composition
context = search_graph_and_compose_context(
client=self._client,
query=query,
graph_id=self._graph_id,
facts_limit=self._facts_limit,
entity_limit=self._entity_limit,
episodes_limit=limit,
search_filters=self._search_filters,
)

if context:
self._logger.info(f"Composed context for query: {query}")
return [
{"memory": context, "type": "graph_context", "source": "graph", "query": query}
]

self._logger.info(f"No results found for query: {query}")
return []

except Exception as e:
self._logger.error(f"Error searching graph: {e}")
return []

def reset(self) -> None:
"""Reset is not implemented for graph storage as graphs should persist."""
Expand Down
53 changes: 29 additions & 24 deletions integrations/python/zep_crewai/src/zep_crewai/user_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,35 @@ def search(
Returns:
List with context results from user storage
"""
# Use the shared utility function for graph search and context composition
context = search_graph_and_compose_context(
client=self._client,
query=query,
user_id=self._user_id,
facts_limit=self._facts_limit,
entity_limit=self._entity_limit,
episodes_limit=limit,
search_filters=self._search_filters,
)

if context:
self._logger.info(f"Composed context for query: {query}")
return [
{
"context": context,
"type": "user_graph_context",
"source": "user_graph",
"query": query,
}
]

self._logger.info(f"No results found for query: {query}")
return []
try:
# Use the shared utility function for graph search and context composition
context = search_graph_and_compose_context(
client=self._client,
query=query,
user_id=self._user_id,
facts_limit=self._facts_limit,
entity_limit=self._entity_limit,
episodes_limit=limit,
search_filters=self._search_filters,
)

if context:
self._logger.info(f"Composed context for query: {query}")
return [
{
"memory": context,
"type": "user_graph_context",
"source": "user_graph",
"query": query,
}
]

self._logger.info(f"No results found for query: {query}")
return []

except Exception as e:
self._logger.error(f"Error searching user graph: {e}")
return []

def get_context(self) -> str | None:
"""
Expand Down
2 changes: 1 addition & 1 deletion integrations/python/zep_crewai/tests/test_graph_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_search_with_results(self, mock_search_compose):
assert len(results) == 1 # Single composed result

# Check the composed result
assert results[0]["context"] == (
assert results[0]["memory"] == (
"Facts:\n- Python is used for AI\n\n"
"Entities:\n- Python: A programming language\n\n"
"Episodes:\n- Discussion about Python"
Expand Down
6 changes: 3 additions & 3 deletions integrations/python/zep_crewai/tests/test_user_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_search_with_thread_context(self, mock_executor, mock_compose):
assert isinstance(results, list)
assert len(results) == 1
assert results[0]["type"] == "user_graph_context"
assert results[0]["context"] == "Context: User likes Python"
assert results[0]["memory"] == "Context: User likes Python"

@patch("zep_crewai.utils.compose_context_string")
@patch("zep_crewai.utils.ThreadPoolExecutor")
Expand Down Expand Up @@ -256,8 +256,8 @@ def test_search_user_graph(self, mock_executor, mock_compose):
# Verify results
assert len(results) == 1
assert results[0]["type"] == "user_graph_context"
assert "User prefers Python" in results[0]["context"]
assert "UserPreference" in results[0]["context"]
assert "User prefers Python" in results[0]["memory"]
assert "UserPreference" in results[0]["memory"]

def test_get_context_with_thread(self):
"""Test get_context retrieves context using thread.get_user_context."""
Expand Down