Chat History Memory

Messages

Messages

Messages are the individual components of a conversation, each linked to a Session in a many-to-one relationship. To incorporate messages into sessions, utilize the Memories feature.

Get a Specific Message from a Session

To fetch a particular message from a session, utilize the get_session_message method. Below are examples in Python and TypeScript:

1client = AsyncZep(
2 api_key=API_KEY,
3)
4session_id = "3e0e4af9-71ff-4541-b206-6133574bbbc6" # Replace with the actual session_id
5message_id = "3e0e4af9-71ff-4541-b206-6133574bbbc7" # Replace with the actual message_id
6message = await client.memory.get_session_message(session_id, message_id)
7print(message)
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 "role_type": "user",
7 "content": "Who were her contemporaries?",
8 "metadata": {
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}

Getting all Messages from a Session

1client = AsyncZep(
2 api_key=API_KEY,
3)
4result = await client.memory.get_session_messages(session_id)
5print(result)
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 "role_type": "user",
9 "content": "Who were her contemporaries?",
10 "metadata": {
11 "system": {
12 "entities": [],
13 "intent": "The subject is requesting information about the people who were living at the same time as the woman in question."
14 }
15 },
16 "token_count": 0
17 }
18 ],
19 ...
20}

Updating Session Message Metadata

You have the ability to modify the metadata of a message. Please provide the metadata in the following format. Note that at this time, it’s not possible to update the content of a message itself.

1{
2 "metadata": {
3 "foo": "bar"
4 }
5}
1client = AsyncZep(
2 api_key=API_KEY,
3)
4session_id = "3e0e4af9-71ff-4541-b206-6133574bbbc6" # Replace with the actual session_id
5message_uuid = "3e0e4af9-71ff-4541-b206-6133574bbbc7" # Replace with the actual message_uuid
6metadata = {
7 "metadata": {
8 "foo": "bar"
9 }
10}
11updated_message = await client.memory.update_message_metadata(
12 session_id, message_uuid, metadata=metadata
13)
14print(updated_message)
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 "role_type": "user",
7 "content": "Who were her contemporaries?",
8 "metadata": {
9 "foo": "bar",
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}