{"slug": "agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per", "title": "Agno's clear_memory tool wipes every user's memories: how to scope Agno agent memory per user", "summary": "Mohammed, founder of MemorySync, reported that Agno's model-facing clear_memory tool calls db.clear_memories() without a user filter, so a call made inside one user's session deletes every user's memories across SQLite, PostgreSQL, MySQL and MongoDB drivers. He reproduced the bug on agno 3.1.10, the latest PyPI release as of Oct 26, 2026, showing that a clear_memory call in Alice's session left Bob's stored memories empty; a fix routing the tool through the scoped clear_user_memories(user_id=...) is open as PR #9986. He recommends checking whether MemoryManager is configured with clear_memories=True, using delete_memories=True for per-user 'forget everything' requests, and adding a guard around the tool.", "body_md": "*Disclosure: I'm Mohammed, founder of MemorySync. I drafted this article with AI assistance and reviewed it for accuracy against the official Agno and MemorySync docs. Code status: on Oct 26, 2026 I ran the same calls as Steps 1, 3 and 4 (the reproduction, the per-user delete and the guard) in scratch scripts on agno 3.1.10 (Python 3.13, a local SQLite file), with no model and no API keys. In Step 5 I only constructed the agent and called `clear_memories()` with a placeholder key, which raised before any request. No LLM was called and no MemorySync request was made, so memory extraction and recall were not run. The rest is adapted from the docs.*\n\nIf you run one Agno agent for many users, you probably keep every user's memories in one database and separate them with `user_id`. [agno-agi/agno#9983](https://github.com/agno-agi/agno/issues/9983) shows where that breaks: the `clear_memory` tool that `MemoryManager` can hand to the model calls `db.clear_memories()` with no user filter. One user's session can delete every user's memories.\n\nBelow: how to check whether your setup can reach that tool, the settings that keep it away from the model, a per-user wipe that stays scoped, and a small guard you can add today. Agno behaviour comes from the [Agno memory docs](https://docs.agno.com/memory/overview), the MemoryManager reference and the installed package. I'm building MemorySync, a hosted memory layer, and it gets one short section near the end (if you want it with Agno, see the [MemorySync Agno guide](https://docs.memorysync.io/guides/agno?utm_source=devto&utm_medium=social&utm_campaign=pivot_oct19&utm_content=agno-clear-memory-per-user-memory-scoping-docs)).\n\n`MemoryManager` builds a set of memory tools for model-driven memory work: `add_memory`, `update_memory`, `delete_memory` and `clear_memory`. The first three pass the current `user_id`. `clear_memory` doesn't:\n\n``` php\ndef clear_memory() -> str:\n    db.clear_memories()\n    ...\n```\n\nThe reporter says `clear_memories()` deletes the whole memories table in every database driver (SQLite, PostgreSQL, MySQL and MongoDB). A fix that routes the tool through the scoped `clear_user_memories(user_id=...)` is up as PR #9986. On Oct 26, 2026 the issue and the PR were both still open, and agno 3.1.10, the latest release on PyPI that day, still has the unscoped tool.\n\nThis follows the issue's reproduction. `_get_db_tools` is a private method; it's used here only to call the tool exactly as the agent would:\n\n``` python\nfrom agno.db.sqlite import SqliteDb\nfrom agno.memory import MemoryManager, UserMemory\n\ndb = SqliteDb(db_file=\"memories.db\")\ndb.upsert_user_memory(UserMemory(user_id=\"user-alice\", memory=\"Alice books window seats.\"))\ndb.upsert_user_memory(UserMemory(user_id=\"user-bob\", memory=\"Bob prefers aisle seats.\"))\n\nmanager = MemoryManager(db=db)\ntools = {f.__name__: f for f in manager._get_db_tools(\n    \"user-alice\", db, \"fixture\",\n    enable_add_memory=True, enable_update_memory=True,\n    enable_delete_memory=True, enable_clear_memory=True,\n)}\ntools[\"clear_memory\"]()  # a tool call inside Alice's session\n\nprint([m.memory for m in db.get_user_memories(user_id=\"user-bob\")])\n```\n\nOn agno 3.1.10 this printed `Memory cleared successfully` and then `[]`. Bob's memory was gone after a call made in Alice's session.\n\n`clear_memory`\nIn agno 3.1.10, the model only gets this tool in one situation:\n\n`update_memory_on_run=True`): the background memory call is built with `enable_clear_memory=False`, so `enable_agentic_memory=True`): the agent gets an `update_user_memory` tool, and the nested memory call offers the tools your `MemoryManager` flags allow. `MemoryManager(clear_memories=True)`.\nThe [MemoryManager reference](https://docs.agno.com/reference/memory/memory) lists `clear_memories` as \"Allow the manager to clear all memories\", default `False`. So the setting to look for is `clear_memories=True`. If you need users to be able to say \"forget everything about me\", use `delete_memories=True` instead. The [agentic memory docs](https://docs.agno.com/memory/agent/agentic-memory) say it lets the tool delete memories for the current `user_id`:\n\n``` python\nfrom agno.agent import Agent\nfrom agno.memory import MemoryManager\n\nagent = Agent(\n    model=...,  # your model\n    db=db,\n    memory_manager=MemoryManager(delete_memories=True),  # leave clear_memories at False\n    enable_agentic_memory=True,\n)\n```\n\nWith these flags, I checked the tool list the memory call would get: `add_memory`, `delete_memory`, `update_memory`, and no `clear_memory`.\n\nAlso look through your own code for `MemoryManager.clear()` and `db.clear_memories()`. The reference says `clear()` \"has no user scope and clears the entire memory store\".\n\nFor an admin action or a \"delete my data\" endpoint, call the scoped method with the authenticated user's ID:\n\n```\nmanager.clear_user_memories(user_id=\"user-alice\")\n# async database: await manager.aclear_user_memories(user_id=\"user-alice\")\n```\n\nIn my run, Alice had no memories left afterwards and Bob still had his. Always pass `user_id` explicitly. Per the reference, user-scoped methods fall back to a user called `\"default\"` when it's omitted, and the best practices page says not to rely on it.\n\nIf you want the global wipe gone no matter which flags someone sets later, subclass your database and make `clear_memories()` refuse. This is my addition, not something from the Agno docs:\n\n``` python\nfrom agno.db.sqlite import SqliteDb\n\nclass NoGlobalClearSqliteDb(SqliteDb):\n    def clear_memories(self) -> None:\n        raise RuntimeError(\n            \"Global memory wipe is disabled. Use clear_user_memories(user_id=...).\"\n        )\n\ndb = NoGlobalClearSqliteDb(db_file=\"memories.db\")\n```\n\nWith this in place, running Step 1 again made the `clear_memory` tool raise instead of deleting, and Bob's memory stayed. `clear_user_memories(user_id=...)` still worked, because it deletes one user's memories by ID and never calls `clear_memories()`. The same override works for the PostgreSQL, MySQL or MongoDB classes. I only ran it on SQLite.\n\nMemorySync's [Agno guide](https://docs.memorysync.io/guides/agno?utm_source=devto&utm_medium=social&utm_campaign=pivot_oct19&utm_content=agno-clear-memory-per-user-memory-scoping) plugs a `MemorySyncDb` into Agno's own `MemoryManager`. Sessions stay in your database, and memories go to MemorySync. Its `clear_memories()` always raises, and the per-user wipe is an explicit `forget_user_memories(user_id)`:\n\n```\npip install agno-memorysync\npython\nfrom agno.agent import Agent\nfrom agno.db.sqlite import SqliteDb\nfrom agno.memory import MemoryManager\nfrom agno_memorysync import MemorySyncDb\n\nmemory_db = MemorySyncDb()  # reads MEMORYSYNC_API_KEY\n\nagent = Agent(\n    db=SqliteDb(db_file=\"agent.db\"),                # sessions: local\n    memory_manager=MemoryManager(db=memory_db),     # memories: MemorySync\n    update_memory_on_run=True,\n    user_id=\"customer-42\",\n)\n\nmemory_db.forget_user_memories(\"customer-42\")      # one user's memories, returns the count\n```\n\nThe guide requires Python 3.10+ and agno 2.8 or newer, and you create the API key in the dashboard under Settings → API Keys. `MemorySyncDb` only handles memory. If you point sessions or knowledge at it, it raises `MemorySyncMemoryOnlyError`, so keep those on your own database. In my run, constructing the agent worked, and `clear_memories()` raised `MemorySyncClearAllError` before sending anything. You don't need MemorySync for Steps 1 to 4.\n\n`clear()` or `clear_memories()` calls in your code. Then add the Step 4 guard.`user_id` on every run and every `\"default\"`.` clear_user_memories()` raises with an async database.`aclear_user_memories()`. The reference says the sync version requires a synchronous database.`MemorySyncMemoryOnlyError`.` MemorySyncDb`. Only `memory_manager=` should use it.\n**Does Agno's clear_memory tool delete only the current user's memories?**\n\nNot in agno 3.1.10. The tool calls `db.clear_memories()`, which isn't filtered by user ([agno#9983](https://github.com/agno-agi/agno/issues/9983)). A fix that scopes it to the calling user is proposed in PR #9986, which was still open on Oct 26, 2026.\n\n**How do I delete all memories for one user in Agno?**\n\nCall `MemoryManager.clear_user_memories(user_id=...)`, or `aclear_user_memories(...)` with an async database. The reference describes both as clearing only the selected user's memories ([MemoryManager reference](https://docs.agno.com/reference/memory/memory)).\n\n**Is Agno memory isolated per user by default?**\n\nMemories are stored and read by `user_id`. The [multi-user chat example](https://docs.agno.com/memory/agent/multi-user-multi-session-chat) scopes history by `session_id` and memory by `user_id`. If you omit the ID, Agno uses `\"default\"`, and `clear()` / `clear_memories()` ignore user scope entirely.\n\n**Can I use MemorySync as Agno's memory backend?**\n\nYes. `MemorySyncDb` from `agno-memorysync` goes into `MemoryManager(db=...)`, while sessions stay in your own database. Its `clear_memories()` always raises, and per-user wipes use `forget_user_memories(user_id)` ([MemorySync Agno guide](https://docs.memorysync.io/guides/agno?utm_source=devto&utm_medium=social&utm_campaign=pivot_oct19&utm_content=agno-clear-memory-per-user-memory-scoping)).\n\n`agno/memory/manager.py`: `_get_db_tools`, `create_user_memories`, `update_memory_task`) and PyPI (agno 3.1.10, agno-memorysync 1.1.0)\nIf you want to see a memory survive a full page reload before wiring up an agent, the MemorySync playground runs the save, reload and recall loop in your browser: [memorysync.io/try](https://memorysync.io/try?utm_source=devto&utm_medium=social&utm_campaign=pivot_oct19&utm_content=agno-clear-memory-per-user-memory-scoping).", "url": "https://wpnews.pro/news/agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per", "canonical_source": "https://dev.to/memorysync_rafay/agnos-clearmemory-tool-wipes-every-users-memories-how-to-scope-agno-agent-memory-per-user-3nk", "published_at": "2026-10-27 16:39:03+00:00", "updated_at": "2026-10-27 16:42:06.139587+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-safety", "developer-tools"], "entities": ["Agno", "MemorySync", "Mohammed", "agno-agi/agno#9983", "PR #9986", "SQLite", "PostgreSQL", "MongoDB"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per", "markdown": "https://wpnews.pro/news/agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per.md", "text": "https://wpnews.pro/news/agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per.txt", "jsonld": "https://wpnews.pro/news/agno-s-clear-memory-tool-wipes-every-user-s-memories-how-to-scope-agno-agent-per.jsonld"}}