Unify customer and account context
A customer task can require personal context and information that belongs to the customer’s account. Keep each source in its correct scope:
- A user graph stores a person’s conversations, activity, and preferences. Zep
creates the user graph when you create the user. The application addresses
the graph with the
graph_uuidfrom the user create response. - A shared account Context Graph stores account records and support events. The
Context Graph also stores contracts, product documents, and other shared
data. The application addresses the graph with the
uuidfrom the graph create response.
This recipe creates both scopes and retrieves from them for one authorized support task.
Set up the user, thread, and account graph
Zep generates the UUID of each user, thread, and graph. Store each UUID in your
application database next to your own identifier, for example in
zep_user_uuid, zep_thread_uuid, and zep_account_graph_uuid columns. Use
the stored UUIDs on all later calls. This example uses one user, one
conversation thread, and one account Context Graph.
To protect a create call against retries, you can send an idempotency key with the call. See Create a graph.
Add shared account sources
Add each shared source to the account Context Graph. The example combines an account record, a support event, and a product document.
Wait until the account context is searchable
Zep processes episodes asynchronously. Poll the last submitted account episode, and then retry a query that is specific to the imported data. The ingestion status guide explains the processing order and production alternatives to polling.
Retrieve personal and account context
Authorize the account in your application before you request its Context Graph. Then record the current user message, retrieve its Context Block in the same request, and search the authorized account graph.
Put the two context values in the model request as untrusted reference data. Keep stable application instructions in a higher-priority message. Do not put retrieved context in a developer or system message.
After the model returns a response, add the assistant message to the thread so that later tasks can retrieve it as agent memory.
Apply governance
Your application must validate the relationship between the user and the account. You can also use policy-based access control to limit an API key to permitted account graphs and sources.
Retain the source episode references from account search results when you must trace retrieved facts to their sources.