Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix(cli): keep every result in `entity delete`, not just the last (#5936)

Abhay Singhad57cbb8d61d
diff --git a/cli/python/src/mem0_cli/backend/platform.py b/cli/python/src/mem0_cli/backend/platform.py
index c1a908053..a0e5badd9 100644
--- a/cli/python/src/mem0_cli/backend/platform.py
+++ b/cli/python/src/mem0_cli/backend/platform.py
@@ -296,13 +296,15 @@ class PlatformBackend(Backend):
entities = {t: v for t, v in type_map.items() if v}
if not entities:
raise ValueError("At least one entity ID is required for delete_entities.")
- # Delete each provided entity via the v2 path-based endpoint
- result: dict = {}
+ # Delete each provided entity via the v2 path-based endpoint. Key each
+ # response by entity type so a multi-entity delete (e.g. --user-id and
+ # --agent-id together) doesn't discard everything but the last result.
+ results: dict = {}
for entity_type, entity_id in entities.items():
- result = self._request(
+ results[entity_type] = self._request(
"DELETE", f"/v2/entities/{entity_type}/{entity_id}/", params={"source": "CLI"}
)
- return result
+ return results
def ping(self, timeout: float | None = None) -> dict:
"""Call the ping endpoint and return the raw response.
diff --git a/cli/python/tests/test_platform_backend.py b/cli/python/tests/test_platform_backend.py
new file mode 100644
index 000000000..51238d21b
--- /dev/null
+++ b/cli/python/tests/test_platform_backend.py
@@ -0,0 +1,46 @@
+"""Tests for the Platform backend (mem0 Platform API client)."""
+
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from mem0_cli.backend.platform import PlatformBackend
+from mem0_cli.config import PlatformConfig
+
+
+def _make_backend() -> PlatformBackend:
+ # api_key/base_url are only used to build the httpx client; every test here
+ # patches _request, so no real network calls are made.
+ return PlatformBackend(PlatformConfig(api_key="test-key", base_url="https://api.mem0.ai"))
+
+
+class TestDeleteEntities:
+ def test_multiple_entities_returns_all_results(self):
+ backend = _make_backend()
+ responses = {
+ "/v2/entities/user/alice/": {"message": "user deleted"},
+ "/v2/entities/agent/bob/": {"message": "agent deleted"},
+ }
+ with patch.object(backend, "_request") as mock_request:
+ mock_request.side_effect = lambda method, path, **kw: responses[path]
+ result = backend.delete_entities(user_id="alice", agent_id="bob")
+
+ # Regression: previously only the last entity's response survived.
+ assert result == {
+ "user": {"message": "user deleted"},
+ "agent": {"message": "agent deleted"},
+ }
+ assert mock_request.call_count == 2
+
+ def test_single_entity_keyed_by_type(self):
+ backend = _make_backend()
+ with patch.object(backend, "_request", return_value={"message": "user deleted"}):
+ result = backend.delete_entities(user_id="alice")
+ assert result == {"user": {"message": "user deleted"}}
+
+ def test_no_entities_raises(self):
+ backend = _make_backend()
+ import pytest
+
+ with pytest.raises(ValueError):
+ backend.delete_entities()