Context templates
Context templates allow you to customize how context is formatted and returned when calling thread.get_context(). Templates are reusable configurations that you set once for your project and can use across all your threads. They let you specify what information goes into your context block and how much of it to include, while Zep handles the automatic relevance detection and retrieval.
Template control
Context templates let you reuse one format across threads and users in a project:
- More control than the default Context Block: you set the contents and format.
- Less control than Advanced Context Block construction: Zep still creates the query.
- Use it when you need a consistent custom format and keep automatic relevance detection.
See Choosing a retrieval method for a comparison of all three methods.
Define a template
Templates use variables to specify what data to include. Available variables:
%{edges}- Graph edges (facts / relationships)%{entities}- Graph entities (nodes)%{episodes}- Episode data%{observations}- Observations (cross-entity context derived from the graph)%{thread_summaries}- Thread summaries for the user’s threads%{user_summary}- User summary information
Variables (except user_summary) accept optional parameters:
limit=N- Limit number of results (max 1000)types=[type1,type2]- Filter by entity or edge typesinclude_attributes=true/false- Include/exclude attributes
%{observations} and %{thread_summaries} only support limit.
%{observations} and %{thread_summaries} are each capped at 20 items per render. A template limit=N greater than 20 can only truncate further; it cannot raise the count above this ceiling.
Example template definition:
Create a template
Create a new template with a name and template content. The name must be unique in the project and can contain at most 100 characters. Zep generates a UUID for each template and returns it in the uuid field. Store the UUID in your application configuration, because the other template operations and context retrieval use the UUID. Templates are validated when created—Zep checks for valid variable names, proper bracket balancing, valid parameter syntax, and limit values within range.
To make a create safe to retry, you can pass an idempotency key: idempotency_key in Python, requestOptions in TypeScript, or option.WithIdempotencyKey in Go.
Use a template
Pass the template UUID as the template_uuid parameter when retrieving context:
Resulting context block
When you use the template above, Zep returns a formatted context block like this:
Update a template
Update an existing template’s content. Pass the template UUID. The update request sends the complete template, so include each section that you want to keep:
Read a template
Retrieve a specific template by its UUID, or list the templates in the project. The list is paginated. To find a template by its name, pass the name filter, which selects the template with that exact name:
Delete a template
Delete a template when it’s no longer needed: