Represent individual messages in a conversation

You are viewing the Zep Open Source v0.x documentation. This version is no longer supported, and documentation is provided as a reference only.

The current documentation for Zep Community Edition is available here.

Messages represent individual messages in a conversation. Messages are associated with Sessions in a M:1 relationship.

Messages must be added to sessions using Memories.

Get a Specific Message from a Session

To retrieve a specific message from a session, you can use the get_session_message method. Here are examples in Python and TypeScript:

Python

Get Message from Session
1async with ZepClient(base_url, api_key) as client:
2 try:
3 session_id = "3e0e4af9-71ff-4541-b206-6133574bbbc6" # Replace with the actual session_id
4 message_id = "3e0e4af9-71ff-4541-b206-6133574bbbc7" # Replace with the actual message_id
5 message = await client.message.aget_session_message(session_id, message_id)
6 print(message.to_dict())
7 except NotFoundError:
8 print("Message not found")
Output
1{
2 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
3 "created_at": "2023-12-08T22:17:33.185756Z",
4 "updated_at": "0001-01-01T00:00:00Z",
5 "role": "human",
6 "content": "Who were her contemporaries?",
7 "metadata": {
8 "system": {
9 "entities": [],
10 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
11 }
12 }
13}

TypeScript

Get message from Session
1const sessionID = "3e0e4af9-71ff-4541-b206-6133574bbbc6"; // Replace with the actual session ID
2const messageID = "3e0e4af9-71ff-4541-b206-6133574bbbc7"; // Replace with the actual message ID
3
4try {
5 const message = await zepClient.message.getSessionMessage(
6 sessionID,
7 messageID
8 );
9 console.debug(JSON.stringify(message));
10} catch (error) {
11 console.debug("Message not found");
12}
Output
1{
2 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
3 "created_at": "2023-12-08T22:17:33.185756Z",
4 "updated_at": "0001-01-01T00:00:00Z",
5 "role": "human",
6 "content": "Who were her contemporaries?",
7 "metadata": {
8 "system": {
9 "entities": [],
10 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
11 }
12 }
13}

Getting all Messages from a Session

Python

Get all Messages from a Session
1async with ZepClient(base_url, api_key) as client:
2 try:
3 messages = await client.message.aget_session_messages(session_id)
4 for message in messages:
5 print(message.to_dict())
6 except NotFoundError:
7 print("Sesssion not found")
Output
1{
2 "messages": [
3 {
4 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
5 "created_at": "2023-12-08T22:17:33.185756Z",
6 "updated_at": "0001-01-01T00:00:00Z",
7 "role": "human",
8 "content": "Who were her contemporaries?",
9 "metadata": {
10 "system": {
11 "entities": [],
12 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
13 }
14 },
15 "token_count": 0
16 }
17 ],
18 ...
19}

TypeScript

Get all Messages from a Session
1try {
2 const sessionID = "3e0e4af9-71ff-4541-b206-6133574bbbc6"; // Replace with the actual session ID
3 const messagesForSession = await zepClient.message.getSessionMessages(
4 sessionID
5 );
6
7 messagesForSession.messages.forEach((message) => {
8 console.debug(JSON.stringify(message));
9 });
10} catch (error) {
11 console.error("An error occurred:", error);
12}
Output
1{
2 "messages": [
3 {
4 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
5 "created_at": "2023-12-08T22:17:33.185756Z",
6 "updated_at": "0001-01-01T00:00:00Z",
7 "role": "human",
8 "content": "Who were her contemporaries?",
9 "metadata": {
10 "system": {
11 "entities": [],
12 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
13 }
14 },
15 "token_count": 0
16 }
17 ],
18 ...
19}

Update Session Message Metadata

Below are examples on how to update the metadata on a message. Currently, updating message content is not supported. You may, however, update a message’s metadata. The metadata should be provided in the following format:

metadata
1{
2 "metadata": {
3 "foo": "bar"
4 }
5}

Python

Update Metadata on a Message
1async with ZepClient(base_url, api_key) as client:
2 try:
3 session_id = "3e0e4af9-71ff-4541-b206-6133574bbbc6" # Replace with the actual session_id
4 message_uuid = "3e0e4af9-71ff-4541-b206-6133574bbbc7" # Replace with the actual message_id
5 metadata = {
6 "metadata": {
7 "foo": "bar"
8 }
9 }
10 await client.message.update_session_message_metadata(session_id, message_id, metadata)
11 except NotFoundError:
12 print("Session not found")
Output
1{
2 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
3 "created_at": "2023-12-08T22:17:33.185756Z",
4 "updated_at": "0001-01-01T00:00:00Z",
5 "role": "human",
6 "content": "Who were her contemporaries?",
7 "metadata": {
8 "foo": "bar",
9 "system": {
10 "entities": [],
11 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
12 }
13 }
14}

TypeScript

Update Metadata on a Message
1const sessionID = "3e0e4af9-71ff-4541-b206-6133574bbbc6"; // Replace with the actual session ID
2const messageID = "3e0e4af9-71ff-4541-b206-6133574bbbc7"; // Replace with the actual message ID
3const metadataUpdate = {
4 metadata: {
5 foo: "bar",
6 },
7};
8
9try {
10 const messagesForSession =
11 await zepClient.message.updateSessionMessageMetadata(
12 sessionID,
13 messageID,
14 metadataUpdate
15 );
16 console.debug(JSON.stringify(message));
17} catch (error) {
18 console.error("An error occurred:", error);
19}
Output
1{
2 "uuid": "3e0e4af9-71ff-4541-b206-6133574bbbc7",
3 "created_at": "2023-12-08T22:17:33.185756Z",
4 "updated_at": "0001-01-01T00:00:00Z",
5 "role": "human",
6 "content": "Who were her contemporaries?",
7 "metadata": {
8 "foo": "bar",
9 "system": {
10 "entities": [],
11 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
12 }
13 }
14}