You’ll use this when…
- You run assistants for multiple customers who each need private memory spaces
- Different agents (like a planner and a critic) need separate context for the same user
- Sessions should expire on their own schedule, making debugging and data removal more precise
Configure access
client.project.get() to verify your connection. It should return your project details including org_id and project_id. If you get a 401 error, generate a new API key in the Mem0 dashboard.
Feature anatomy
| Dimension | Field | When to use it | Example value |
|---|---|---|---|
| User | user_id | Persistent persona or account | "customer_6412" |
| Agent | agent_id | Distinct agent persona or tool | "meal_planner" |
| Application | app_id | White-label app or product surface | "ios_retail_demo" |
| Session | run_id | Short-lived flow, ticket, or conversation thread | "ticket-9241" |
- Writes (
client.add) accept any combination of these fields. Absent fields default tonull. - Reads (
client.search,client.get_all, exports, deletes) accept the same identifiers inside thefiltersJSON object. - Implicit null scoping: Passing only
{"user_id": "alice"}automatically restricts results to records whereagent_id,app_id, andrun_idarenull. Add wildcards ("*"), explicit lists, or additional filters when you need broader joins.
Choose the right identifier
| Identifier | Purpose | Example Use Cases |
|---|---|---|
user_id | Store preferences, profile details, and historical actions that follow a person everywhere | Dietary restrictions, seat preferences, meeting habits |
agent_id | Keep an agent’s personality, operating modes, or brand voice in one place | Travel agent vs concierge vs customer support personas |
app_id | Tag every write from a partner app or deployment for tenant separation | White-label deployments, partner integrations |
run_id | Isolate temporary flows that should reset or expire independently | Support tickets, chat sessions, experiments |
Configure it
The example below adds memories with entity tags:POST /v1/memories/ with the same identifiers in the JSON body. See the Add Memories API reference for REST details.
See it in action
1. Store scoped memoriesWildcards (
"*") include only non-null values. Use them when you want “any agent” or “any user” without limiting results to null-only records.A successful delete returns
{"message": "Memories deleted successfully!"}. Run the previous get_all call again to confirm the session memories were removed.Verify the feature is working
- Run
client.searchwith your filters and confirm only expected memories appear. Mismatched identifiers usually mean a typo in your scoping. - Check the Mem0 dashboard filter pills. User, agent, app, and run should all show populated values for your memory entry.
- Call
client.delete_allwith a uniquerun_idand confirm other sessions remain intact (the count inget_allshould only drop for that run).
Best practices
- Use consistent identifier formats (like
team-alphaorapp-ios-retail) so you can query or delete entire groups later - When debugging, print your filters before each call to verify wildcards (
"*"), lists, and run IDs are spelled correctly - Combine entity filters with metadata filters (categories, created_at) for precise exports or audits
- Use
run_idfor temporary sessions like support tickets or experiments, then schedule cleanup jobs to delete them