Building Multi-Agent Systems with CrewAI and Zep
For an introduction to Zep’s memory layer, Knowledge Graph, and other key concepts, see the Concepts Guide.
In this guide, we’ll walk through building a multi-agent system using CrewAI with Zep’s persistent memory capabilities. We’ll create specialized agents that can retain context and knowledge across conversations, enabling more sophisticated collaborative workflows.
CrewAI is a powerful framework for orchestrating multi-agent systems, and when combined with Zep’s memory layer, your agents can maintain persistent context, learn from past interactions, and provide more personalized responses.
Set Up Your Environment
-
Sign up for a Zep Cloud account.
-
Install the required dependencies for CrewAI and Zep integration:
- Ensure you have a
.env
file in your working directory with your API keys:
Zep API keys are specific to a project. You can create multiple keys for a
single project. Visit Project Settings
in the Zep dashboard to manage your
API keys.
Create User and Thread for Agent Memory
Before our agents can store and retrieve memories, we need to establish a user and thread context in Zep. This allows agents to maintain persistent memory across different conversation sessions.
Configure Zep Memory for CrewAI
Now we’ll set up the Zep memory integration for CrewAI. The ZepStorage
class bridges CrewAI’s external memory system with Zep’s persistent storage.
The ZepStorage
adapter automatically handles converting CrewAI memory operations
to Zep’s memory format, enabling seamless integration between the two systems.
Pre-populate Context Data
Before our agents start working, let’s add some initial context data to help them understand the user’s preferences and requirements. This demonstrates how you can seed agent memory with relevant information.
Create Specialized Agents
Now we’ll create specialized agents with distinct roles and capabilities. Each agent can access the shared Zep memory, allowing them to collaborate effectively while maintaining context.
Each agent has a specific role and expertise, allowing for specialized task handling while sharing access to the same memory context through Zep.
Define Agent Tasks
Create specific tasks for each agent that leverage the shared memory context. The agents will automatically access relevant information from Zep when executing these tasks.
Create and Execute the Crew
Now we’ll assemble our agents into a crew with shared Zep memory and execute the tasks collaboratively.
Understanding the Memory Integration
When you run this example, several important things happen:
-
Context Awareness: Each agent automatically accesses relevant information from Zep’s memory when executing their tasks, including user preferences, budget constraints, and dietary restrictions.
-
Persistent Storage: All interactions, decisions, and results are stored in Zep’s knowledge graph, creating a permanent record of the collaborative planning session.
-
Cross-Agent Learning: Future conversations can build upon this stored knowledge, enabling more sophisticated and personalized recommendations over time.
-
Memory Retrieval: The agents don’t need explicit instructions about user preferences - they retrieve this information automatically from Zep’s context-aware memory system.
Complete Example
Next Steps
This example demonstrates the foundation for building sophisticated multi-agent systems with persistent memory. You can extend this pattern by:
- Adding more specialized agents (research, booking, itinerary management)
- Implementing custom memory retrieval strategies
- Creating agent hierarchies with different access levels to memory
- Building conversational interfaces that leverage the stored context
- Integrating with external APIs and data sources
Monitor your agents’ memory usage in the Zep dashboard to understand how they’re storing and retrieving contextual information across conversations.
The combination of CrewAI’s multi-agent orchestration with Zep’s persistent memory creates a powerful foundation for building intelligent, context-aware agent systems that can learn and improve over time.