Custom instructions
Available to Flex Plus and Enterprise customers.
Why use custom instructions
Zep’s graph extraction uses general-purpose logic by default. Custom instructions let you describe the domain your application operates in, including specialized terminology and concepts that Zep might not otherwise understand. This domain context helps Zep interpret data more accurately during extraction.
Custom instructions describe your domain — the terminology, concepts, and context Zep needs to understand your data. If you need to define specific entity types or relationship types for your graph, use custom ontology instead.
How custom instructions work
Custom instructions are applied automatically in the background whenever data is added to a graph. There is no parameter on thread.add_messages, graph.episode.add, or any other ingestion method to select which instructions to use — Zep fetches and applies the relevant instructions based on the target graph.
Resolution order
When data is ingested into a graph, Zep determines which instructions to use in the following order:
- Graph-specific instructions — If the target graph has its own instructions, set with
graph.set_instructions, those are used. - Project-wide defaults — If no graph-specific instructions exist, Zep falls back to project-wide default instructions.
- Built-in extraction logic — If no custom instructions are defined at all, Zep uses its general-purpose extraction logic.
This means you can set broad project-wide instructions as a baseline and override them for specific graphs when needed.
Defining custom instructions
Project-wide instructions
Use project.set_instructions to set the project-wide defaults. These apply to all graphs that don’t have their own graph-specific instructions. Each set call replaces the full set of instructions at that scope.
When you add data to any graph, Zep automatically applies these project-wide instructions. No extra parameters are needed. The examples use the uuid that graph.create returns, which you store in your application database:
Graph-specific instructions
To set instructions for one graph, use graph.set_instructions with the UUID of the graph. For a user graph, use the graph_uuid that user.create returns. These instructions override any project-wide defaults for that graph. To apply the same instructions to more than one graph, send the call once for each graph.
When you add messages to a thread of this user, Zep automatically applies the healthcare_domain instructions. No extra parameters are needed. The examples use the uuid that thread.create returns:
Important behaviors
Whole-set writes
A set call replaces the full set of instructions at its scope. An instruction that is not in the request is removed from that scope. To add or change one instruction, read the current set, change the list, and write the full list back. To remove all instructions at a scope, write an empty list.
graph.get_instructions returns the effective instructions of a graph. When the graph has no instructions of its own, the response contains the project-wide defaults and inherited is true.