CrewAI integration
The v4 version of zep-crewai is not released yet. The current zep-crewai release uses the v3 API. To use this integration now, follow the v3 version of this page.
The zep-crewai package gives CrewAI agents persistent memory backed by Zep’s temporal knowledge graph. You persist conversation turns and business data with Zep storage adapters, and give your agents Zep tools so they can retrieve relevant context when they need it. This lets agents carry context across executions, share a common knowledge base, and ground their decisions in what was learned before.
Core benefits
- Persistent memory — Conversations and knowledge persist across sessions and crew runs.
- On-demand retrieval — Agents search Zep through tools and pull in context exactly when a task calls for it.
- Dual storage — User graphs for individual memory and shared Context Graphs for organizational data.
- Tool integration — Search and add-data tools let agents read from and write to Zep during execution.
How it works
Memory in this integration is explicit and tool-driven. There are two distinct steps, and you control both.
Persisting context. Create a ZepUserStorage or ZepGraphStorage adapter and call storage.save(value, metadata={"type": ...}). The adapter routes each item by its type:
Retrieving context. Attach create_search_tool (and optionally create_add_data_tool) to an Agent(tools=[...]). The agent searches Zep when it decides the task needs it. You can also call ZepUserStorage.get_context() directly to fetch the context block that Zep assembles for a thread.
Failure isolation. save() on every storage adapter logs a Zep failure and returns normally instead of raising, so a Zep outage never crashes a crew run. When you want misconfiguration to fail loudly, provision with ensure_user and ensure_thread before the crew runs — see provisioning users and threads.
There is no automatic retrieval or storage, and no external_memory= Crew wiring. CrewAI 1.x removed the ExternalMemory(storage=...) wrapper and the storage interface it depended on, so context is never injected behind the scenes. You decide what to save with save(...), and the agent decides what to search through its tools. The package is also sync-only: its adapters are built on the synchronous Zep client.
Identifiers
Zep v4 addresses every user, thread, and graph by a server-generated UUID. A resource that v4 creates has no client-chosen identifier: a create call does not accept a user_id, a thread_id, or a graph_id. For a resource that v3 created, a user_id or a thread_id is a read-only name, not an address.
The pattern throughout this integration is:
- Create the resource one time, during onboarding.
- Read the
uuid_field of the response. - Store the UUID in your own database.
- Pass the UUID to the storage adapters (
user_uuid,thread_uuid,graph_uuid) and to the tools (graph_uuid).
The integration does not call lookup at run time. If you carry a v3 identifier, resolve it one time with user.lookup or thread.lookup, store the returned UUID, and use the UUID from then on. Lookup is only for migration. See Migrating from v3.
Zep is also asynchronous: an episode you add is processed in the background, and a fact is not instantly retrievable. Give an agent time between save() and the search that reads it, or poll.
Installation
Requires Python 3.11+, zep-crewai, crewai>=1.0.0, and pydantic>=2.0.0, plus a Zep Cloud API key. Get your API key from app.getzep.com.
Set your API key in the environment:
Upgrading from zep-crewai 1.1.x
Four changes affect existing code:
- The public API takes UUIDs:
user_id/thread_id/graph_idconstructor arguments are nowuser_uuid/thread_uuid/graph_uuid, and the storage adapters no longer provision a user or a thread lazily. Create resources one time —ensure_user/ensure_threadreturn the created or existing resource — and store the UUIDs. - The compound
allsearch scope is removed — useautoto let Zep pick a scope. save()logs Zep failures instead of raising them.search()wraps its context string in a<ZEP_CONTEXT>template; passcontext_template="{context}"for the raw block.
See the package changelog for the full list of changes.
Provisioning users and threads
ensure_user and ensure_thread are helpers for onboarding. Zep v4 accepts no client-chosen identifier on create, so a create cannot match an existing resource, and each successful call creates a new resource. The helpers never call lookup. Genuine failures (auth, network, 5xx) raise. Call them one time, during onboarding, store the returned UUIDs in your own database, and read the UUIDs from there on later runs.
The optional on_created hook fires once for each user the call creates — use it for one-time per-user setup such as ontology configuration. The hook receives the Zep client and the created User, which carries uuid_ and graph_uuid.
ZepUserStorage and ZepStorage take UUIDs only and never create a user or a thread on the turn path. ZepGraphStorage is scoped to a Context Graph rather than a Zep user; passing it on_created raises TypeError.
Storage types
User storage
Use ZepUserStorage for an individual user’s conversation history and personal context. The thread_uuid ties message storage to a conversation thread. CrewAI has no automatic persistence loop; sharing one thread across multiple agents is safe when your code or tools write each turn once.
graph_uuid is optional: when you omit it, the storage reads user.graph_uuid one time with user.get(user_uuid) and caches it. Pass it explicitly when your application already stored it — that avoids the extra read.
To fetch the auto-assembled Context Block for the thread directly, call get_context():
Zep context can include content that your users, documents, or tools supplied. A system or developer message gives that content higher instruction priority than ordinary input. Some convenience integrations use system-message injection. Use direct SDK retrieval or an actual retrieval tool call unless all stored content is application-authored and trusted. Follow Memory security best practices for provider-specific placement.
To build an agent that plans its retrieval and uses several Zep tools, read Build an Agent with Zep. The guide shows how to add domain knowledge, design tools, and evaluate the agent.
Graph storage
Use ZepGraphStorage for a shared Context Graph that multiple agents can read and write. Create the graph with graph.create and keep the uuid_ of the response.
You can also search a graph directly. search returns a list whose entries include a Context Block wrapped in the storage’s context template — a <ZEP_CONTEXT>...</ZEP_CONTEXT> block by default:
Pass context_template="{context}" to the storage constructor to get the bare context string instead.
Customizing retrieved context
Both storage classes wrap the context string returned from search() in a template. context_template must contain a literal {context} placeholder and is rendered with plain string replacement (never str.format), so context containing {, }, or % is always safe. The default is the DEFAULT_CONTEXT_TEMPLATE export — the <ZEP_CONTEXT>...</ZEP_CONTEXT> block shared across Zep integrations.
ZepUserStorage also accepts a context_builder: a synchronous callable that replaces the default graph.get_context retrieval in search() with your own logic. The builder receives a frozen ContextInput (zep, user_uuid, thread_uuid, graph_uuid, user_message) and returns the context string, or None for no results. A builder exception is logged and degrades to empty results.
Tool integration
Tools are the supported extension point for exposing Zep to CrewAI agents. Every tool binds to one graph at creation time — the user graph of a user, or a standalone graph — then goes on an agent’s tools list.
create_search_tool and create_add_data_tool return ZepSearchTool and ZepAddDataTool instances; both classes are also exported if you prefer to construct them directly. A Zep failure inside either tool returns an error string to the agent — the tool never raises into the crew.
Search tool parameters
The search tool’s args_schema exposes every graph search parameter to the model by default. In Zep v4 each scope value calls a dedicated SDK method — graph.search_edges, graph.search_nodes, graph.search_episodes, graph.search_observations, or graph.search_thread_summaries — and auto calls graph.get_context so Zep assembles the mix on the server. Each scoped method returns a pager, which the tool reads up to limit.
Use pinned_params to fix a parameter to a constant and remove it from the model-facing schema, or hidden_params to remove it from the schema without pinning it (Zep’s server-side default applies). The scope, reranker, and limit keyword arguments each pin and hide their parameter, equivalent to putting them in pinned_params. search_filters and bfs_origin_node_uuids are constructor-only and never exposed to the model.
The tool returns results to the agent as plain - fact lines, one per result.
Add-data tool parameters
data— Content to store; payloads over Zep’sgraph.episode.addceiling are truncated to 9,900 characters instead of failing.data_type— Explicit type:text(default),json, ormessage.
Structured data with ontologies
Define entity types so Zep organizes graph data into typed entities, then set the ontology on the graph.
Configuration options
ZepUserStorage parameters
ZepGraphStorage parameters
ZepGraphStorage has no on_created parameter — it is graph-scoped, with no Zep user to provision. Passing on_created raises TypeError.
ZepStorage parameters
ZepStorage is a standalone user-and-thread adapter that preserves the historical save(value, metadata) / search(query, limit, score_threshold) / reset() contract for existing callers. It takes client, user_uuid, and thread_uuid (all required) plus an optional graph_uuid. New code should prefer ZepUserStorage.
Size limits
- Zep rejects direct thread-message payloads over 4,096 characters; the CrewAI storage paths truncate message content to 4,000 characters before
thread.add_messages, logging lengths only and never content. - Zep rejects direct
graph.episode.addpayloads over 10,000 characters; CrewAI storage paths andZepAddDataTooltruncate graph payloads to 9,900 characters before callinggraph.episode.add. - The integration truncates search queries to 400 characters.
Complete example
This example mirrors the simple_example.py from the integration repository. It persists conversation turns and business data to a user’s memory, then runs an agent that searches that memory through a Zep tool before answering.
Best practices
Storage selection
- Use
ZepUserStoragefor personal preferences, conversation history, and user-specific context. - Use
ZepGraphStoragefor organizational and collaborative data in a shared Context Graph.
Memory management
- Store UUIDs — keep
user.uuid_,thread.uuid_, andgraph.uuid_in your own database and address resources by UUID. - Set up ontologies for structured graph data with
EntityTypeandEntityProperty. - Use search filters to target specific node types and improve relevance.
- Combine storage types when the agent needs multiple memory types.
Tool usage
- Bind tools to a specific graph at creation time — a user graph or a standalone graph.
- Pin or hide search parameters the model should not control with
pinned_paramsandhidden_params. - Save data with the right
type(message,json, ortext) so it routes correctly. - Allow time for indexing — Zep extracts knowledge asynchronously, so facts from a turn are not instantly searchable.
Next steps
- Explore customizing graph structure for advanced knowledge organization
- Learn about searching the graph and how to tune search
- See code examples for additional patterns