Mem0mem0ai 2.0.20 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
24 small wins to finish your pathNext lesson

user_id, agent_id and run_id

Every memory so far has belonged to Ravi. A real system has thousands of customers, several assistants and a conversation that ends. Mem0 has one identifier for each of those.

IdentifierTies the memory toUse it for
user_ida person or accountpreferences, facts about them
agent_idone assistant or personawhat this assistant learned to do
run_idone session or taskfacts that expire with the conversation

At least one is required. More than one narrows the memory further, so it is found only when all of them match.

Example
from pretend_mem0 import memory

shop = memory()
shop.add("Deliver to my office.", user_id="ravi")
shop.add("The customer sounded annoyed.", user_id="ravi", run_id="chat-42")

print(len(shop.get_all(filters={"user_id": "ravi"})["results"]), "for ravi")
print(len(shop.get_all(filters={"run_id": "chat-42"})["results"]), "for this chat")

Both memories belong to Ravi, and only one belongs to this conversation. Filter by the user and you get everything; filter by the run and you get what was true just now.

Why run_id earns its place

Some things are worth remembering for ten minutes and not for a year. That the customer is in a hurry, that they are asking about the order they mentioned two messages ago, that they already tried restarting it. Store those under a run_id and they stay out of next month's search results without anyone having to clean up.

Narrowing with two

Example
from pretend_mem0 import memory

shop = memory()
shop.add("Deliver to my office.", user_id="ravi")
shop.add("The customer sounded annoyed.", user_id="ravi", run_id="chat-42")

both = shop.get_all(filters={"user_id": "ravi", "run_id": "chat-42"})
for stored in both["results"]:
    print(stored["memory"])

Only the memory carrying both identifiers comes back. This is how one assistant serving many people in many sessions keeps them apart with no work of its own.

Pick the identifier by how long the fact should live. A delivery address is a user_id fact. A mood is a run_id fact. Getting this wrong is not an error you will see: it shows up months later as an assistant confidently telling somebody they were annoyed, once.
Try it yourself
  • Add a memory under a second user_id and confirm Ravi's filter never returns it.
  • Store the same sentence under a run_id and under a user_id, then search with each filter.
  • Try delete_all(run_id="chat-42") and check what survives.

You understood something today that you didn't yesterday.