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.
| Identifier | Ties the memory to | Use it for |
|---|---|---|
| user_id | a person or account | preferences, facts about them |
| agent_id | one assistant or persona | what this assistant learned to do |
| run_id | one session or task | facts 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.
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
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.
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.- Add a memory under a second
user_idand confirm Ravi's filter never returns it. - Store the same sentence under a
run_idand under auser_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.