Skip to main content

CrewAI integration for Zep

Project description

Zep CrewAI Integration Tutorial

Learn how to add persistent memory to your CrewAI agents using Zep's powerful memory platform.

Installation

Install the Zep CrewAI integration package:

pip install zep-crewai

Setup

1. Get Your API Key

Sign up at Zep Cloud and get your API key.

2. Set Environment Variable

export ZEP_API_KEY="your-zep-api-key"

Basic Usage

1. Initialize Zep Client

import os
from zep_cloud.client import Zep

# Initialize Zep client
zep_client = Zep(api_key=os.getenv("ZEP_API_KEY"))

2. Create User and Thread

Important: You must create a user and thread in Zep before using ZepStorage.

# Create a user 
user_id = "john_doe_123"
zep_client.user.add(
    user_id=user_id,
    first_name="John",
    last_name="Doe",
    email="john.doe@example.com"
)

# Create a thread 
thread_id = "project_alpha_456"
zep_client.thread.create(
    user_id=user_id,
    thread_id=thread_id
)

3. Initialize ZepStorage

from zep_crewai import ZepStorage
from crewai.memory.external.external_memory import ExternalMemory

# Create storage for your project
zep_storage = ZepStorage(
    client=zep_client,
    user_id=user_id,   
    thread_id=thread_id
)

# Wrap in CrewAI's external memory
external_memory = ExternalMemory(storage=zep_storage)

4. Create Crew with Persistent Memory

from crewai import Agent, Crew, Task, Process

# Create your agents
research_agent = Agent(
    role='Research Analyst',
    goal='Analyze market trends and provide insights',
    backstory='You are an expert at finding and analyzing market data...',
)

# Create crew with Zep memory
crew = Crew(
    agents=[research_agent],
    tasks=[...],
    external_memory=external_memory,  # This enables the crew to search Zep
    process=Process.sequential,
)

# Run your crew - memories will be automatically saved and retrieved
result = crew.kickoff()

How Memory Works

Zep stores different types of content using metadata-based routing.

Messages (Conversation Context)

Stored in Zep threads for conversation history:

external_memory.save(
    "I need help planning a business trip to New York",
    metadata={"type": "message", "role": "user", "name": "John Doe"}
)

external_memory.save(
    "I'd be happy to help you plan your trip!",
    metadata={"type": "message", "role": "assistant", "name": "Travel Agent"}
)

Structured Data

Added as episodes to the user knowledge graph in Zep:

# JSON data
external_memory.save(
    '{"destination": "New York", "duration": "3 days", "budget": 2000}',
    metadata={"type": "json"}
)

# Text facts and insights
external_memory.save(
    "User prefers mid-range hotels with business amenities",
    metadata={"type": "text"}
)

Automatic Memory Retrieval

CrewAI automatically searches your memories when agents need context:

# When agents run, they automatically get relevant context from Zep
results = crew.kickoff()

# You can also search manually
memory_results = zep_storage.search("hotel preferences", limit=5)
for result in memory_results:
    print(result['memory'])

Complete Example

For a full working example, check out examples/simple_example.py in this repository. This example demonstrates:

  • Setting up Zep user and thread
  • Saving different types of memory (messages, JSON data, text)
  • Creating CrewAI agents with access to Zep memory
  • Automatic context retrieval during agent execution

Requirements

  • Python 3.10+
  • zep-cloud>=3.0.0rc1
  • crewai>=0.80.0

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

zep_crewai-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zep_crewai-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file zep_crewai-0.1.0.tar.gz.

File metadata

  • Download URL: zep_crewai-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zep_crewai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b6b657944c1465d397034e9af9d0a988416a2364e611d83ae52b362980f99b01
MD5 1041504f2a118c610734e04a1ced10bf
BLAKE2b-256 834cd81f39a53eb2cbeba3f3927e080fd60366830107e3dbe2c4a5a2db570f2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zep_crewai-0.1.0.tar.gz:

Publisher: release-integrations.yml on getzep/zep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zep_crewai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zep_crewai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for zep_crewai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0183466ed76eb9d8dfae90457cf03b11e1975fa939fba4e3831ecf9b573f746a
MD5 18e3b41d3db6f9a860214647043474d9
BLAKE2b-256 578a9c8c4c41e34b2980048f0f8565e62fed4295967d650ca0d103419b920ab9

See more details on using hashes here.

Provenance

The following attestation bundles were made for zep_crewai-0.1.0-py3-none-any.whl:

Publisher: release-integrations.yml on getzep/zep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page