Give Your Mem0 Agent Session-Scoped Memory in 15 Minutes (One Filter You're Probably Skipping) A developer warns that Mem0 agents can leak memory across users and sessions if the search() call is not scoped with the same user_id, agent_id, and run_id used during add(). The post demonstrates how failing to pass these identity filters on retrieval causes one user's memories to surface in another's context, and shows how to fix it with consistent scoping and metadata filters. You add memory to your agent with Mem0, ship it, and it works great in your dev environment where you're the only user. Then you go multi-tenant — real users, real sessions — and three weeks later someone reports that the agent "remembers" something they never told it. It's not a hallucination. It's another user's memory, served straight from your own vector store. This is the single most common Mem0 integration bug I run into, and the fix is one filter you're probably not passing consistently. Here's the 15-minute version. Most Mem0 quickstarts look like this: python from mem0 import Memory m = Memory m.add "I prefer flights with no layovers and I'm vegetarian", user id="alice", That looks scoped — you passed user id="alice" . The bug isn't in add . It's in search , three files away, written by a different part of the team or you, two sprints later without the same discipline: somewhere in the RAG/retrieval layer relevant = m.search query="what are the user's travel preferences?" No user id . No filters . Mem0 will happily return the closest semantic matches across every memory in the store — Alice's vegetarian preference bleeding into Bob's session, or worse, into an agent that's actively talking to Bob. The write path was scoped. The read path wasn't. Because both calls succeed and return plausible-looking data, this ships, passes QA one tester, one session , and only shows up once you have concurrent real users. Every search call needs the same scoping identity as the add call that created the memory. If you passed user id on write, pass it on every read: relevant = m.search query="what are the user's travel preferences?", user id="alice", That's the 80% fix. But scoping by user id alone isn't enough once you have more than one agent or more than one conversation thread per user — which is most real products within a month of launch. Mem0 supports three identity dimensions, not one: user id , agent id , and run id . If your product has multiple agents a support bot and a booking bot, say sharing the same user base, scoping by user id alone means the booking bot's memories leak into the support bot's context — technically the right user, wrong agent, still a correctness bug. m.add "User wants the booking bot to always confirm price before charging", user id="alice", agent id="booking-bot", m.add "User asked support to stop sending SMS notifications", user id="alice", agent id="support-bot", retrieval inside booking-bot's context relevant = m.search query="payment preferences", user id="alice", agent id="booking-bot", Without agent id on both calls, search from the booking bot can surface the SMS-notification memory that belongs to a completely different conversational context. It's not wrong data exactly — it's real, it's Alice's — but it's the wrong memory for this agent to be reasoning with, and it will show up in the prompt as if it's relevant. run id is the same idea one level down: scope to a single session or task run when you don't want memory to carry across unrelated conversations with the same agent a returning support ticket vs. an old, resolved one, for example . Once you're past simple identity scoping, Mem0's platform API accepts a filters dict with AND / OR logic on top of metadata you attach at write time — useful for things like "only memories from the last 30 days" or "only memories tagged billing ": m.add "Card ending 4242 declined for insufficient funds", user id="alice", agent id="billing-bot", metadata={"category": "payment issue", "resolved": False}, relevant = m.search query="payment issues", user id="alice", agent id="billing-bot", filters={ "AND": {"category": "payment issue"}, {"resolved": False}, }, This is what turns "the agent remembers everything about this user" into "the agent remembers the right thing for this exact context" — which is the actual goal, not raw recall. Go do this right now, it's faster than reading the rest of this article twice: .search call against your Mem0 client. user id and agent id / run id if you use them as the add calls that populate that memory space. search call missing scoping is a live cross-tenant leak — fix it before anything else on this list. agent id to every add/search pair, not just the ones you've noticed problems with. user id="test-a" , search as user id="test-b" , assert the result is empty. This is the regression test that catches the bug before your users do.The underlying lesson generalizes past Mem0: any memory or retrieval layer that supports scoping only prevents leaks if scoping is enforced symmetrically on both write and read. Write-side discipline without read-side discipline isn't partial protection — it's a false sense of security with a matching demo that works perfectly until a second user shows up.