Adding Messages
You can add both messages and business data to User Graphs.
Adding Messages
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), a role of user, assistant, system, function, tool, or norole, 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.
thread.add_messages is the recommended path for live conversation turns. To backfill past conversations, use zep-ingest. For an individual business-data write, use graph.add. Ingest compares the paths.
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.
Basic example
The example below adds messages to Zep for the user in the given thread:
The SDK reference lists all thread.add_messages arguments. Set return_context to true to ingest messages and retrieve a Context Block in one request.
Ignore assistant messages
Use ignore_roles to exclude specified roles from graph ingestion. For example, set ignore_roles=["assistant"] to ingest only user messages.
Excluded assistant messages remain in the thread history. Zep also uses them to provide context for user messages such as “Yes.”
Creating messages with metadata
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 separate from episode metadata. Zep stores it on the message and returns it when you read messages or search episodes, but does not project it onto the graph or support filtering over it. For metadata that projects onto derived facts and entities and can be filtered in graph search, attach it when adding data via graph.add.
You can attach metadata when creating messages by including a metadata field in your message objects:
Updating message metadata
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.
Setting message timestamps
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).
Message limits
When adding messages to a thread, there are limits on both the number of messages and message size:
- Messages per call: You can add at most 30 messages in a single
thread.add_messagescall - Message size limit: Each message can contain 4,096 characters by default. Accounts with the larger-message entitlement can send up to 14,000 characters.
If 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:
- Have users attach documents rather than paste them into the message, and then process documents separately with
graph.add - Reduce the max message size for your users to match our max message size
- Optional: allow users to paste in documents with an auto detection algorithm that turns it into an attachment as opposed to part of the message
Check when messages are finished processing
You can use the message UUIDs from the response to poll the messages and check when they are finished processing:
The check data ingestion status cookbook provides an example.
Adding Business Data
You can also add JSON or unstructured text to a User Graph using our Graph API.
Customizing Graph Creation
Zep offers two ways to customize how context is created. You can read more about these features at their guide pages:
- Custom entity and edge types: Feature allowing use of Pydantic-like classes to customize creation/retrieval of entities and relations in the Context Graph.
- User summary instructions: Specify how Zep generates user summaries with up to five instructions per user.