You can add both messages and business data to User Graphs.
Add your chat history to Zep using the thread.add_messages method. thread.add_messages is thread-specific and expects data in chat message format, including a name (e.g., user’s real name), role (AI, human, tool), and message content. Zep stores the chat history and builds a user-level Context Graph from the messages.
For best results, add chat history to Zep on every chat turn. That is, add both the human and AI messages as you receive them and in the order that the messages were created. See the Quick Start Guide for an example.
It is important to provide the name of the user in the name field if possible, to help with graph construction. It’s also helpful to provide a meaningful name for the assistant in its name field.
The example below adds messages to Zep for the user in the given thread:
You can find additional arguments to thread.add_messages in the SDK reference. Notably, for latency sensitive applications, you can set return_context to true which will make thread.add_messages return a context block in the way that thread.get_user_context does (discussed below).
You can also pass in a list of roles to ignore when adding messages to a User Graph using the ignore_roles argument. For example, you may not want assistant messages to be added to the user graph; providing the assistant messages in the thread.add_messages call while setting ignore_roles to include “assistant” will make it so that only the user messages are ingested into the graph, but the assistant messages are still used to contextualize the user messages. This is important in case the user message itself does not have enough context, such as the message “Yes.” Additionally, the assistant messages will still be added to the thread’s message history.
Messages can have metadata attached to store additional information like sentiment scores, source identifiers, processing flags, or other custom data. Metadata is preserved when getting threads, individual messages, and when searching episodes.
Message metadata is currently supported only for thread messages. Messages added via the graph.add API do not support metadata. Zep does not support filtering or searching over message metadata.
You can attach metadata when creating messages by including a metadata field in your message objects:
You can update the metadata of an existing message using the message UUID. This is useful for adding or modifying metadata after a message has been created, such as updating sentiment analysis results or processing status.
When creating messages via the API, you should provide the created_at timestamp in RFC3339 format. The created_at timestamp represents the time when the message was originally sent by the user. Setting the created_at timestamp is important to ensure the user’s Context Graph has accurate temporal understanding of user history (since this time is used in our fact invalidation process).
When adding messages to a thread, there are limits on both the number of messages and message size:
thread.add_messages callIf you exceed these limits, the API will return a 400 Bad Request error. If you need to add more than 30 messages or have messages exceeding the character limits, you’ll need to split them across multiple API calls or truncate the content accordingly. Our additional recommendations include:
graph.addYou can use the message UUIDs from the response to poll the messages and check when they are finished processing:
An example of this can be found in the check data ingestion status cookbook.
You can also add JSON or unstructured text to a User Graph using our Graph API.
Zep offers two ways to customize how context is created. You can read more about these features at their guide pages: