MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / delete_users

Method delete_users

methods/mem0/client/main.py:804–856  ·  view source on GitHub ↗

Delete specific entities or all entities if no filters provided. Args: user_id: Optional user ID to delete specific user agent_id: Optional agent ID to delete specific agent app_id: Optional app ID to delete specific app run_id: Optional run I

(
        self,
        user_id: Optional[str] = None,
        agent_id: Optional[str] = None,
        app_id: Optional[str] = None,
        run_id: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

802
803 @api_error_handler
804 async def delete_users(
805 self,
806 user_id: Optional[str] = None,
807 agent_id: Optional[str] = None,
808 app_id: Optional[str] = None,
809 run_id: Optional[str] = None,
810 ) -> Dict[str, str]:
811 """Delete specific entities or all entities if no filters provided.
812
813 Args:
814 user_id: Optional user ID to delete specific user
815 agent_id: Optional agent ID to delete specific agent
816 app_id: Optional app ID to delete specific app
817 run_id: Optional run ID to delete specific run
818
819 Returns:
820 Dict with success message
821
822 Raises:
823 ValueError: If specified entity not found
824 APIError: If deletion fails
825 """
826 params = self.sync_client._prepare_params()
827 entities = await self.users()
828
829 # Filter entities based on provided IDs using list comprehension
830 to_delete = [
831 entity
832 for entity in entities["results"]
833 if (user_id and entity["type"] == "user" and entity["name"] == user_id)
834 or (agent_id and entity["type"] == "agent" and entity["name"] == agent_id)
835 or (app_id and entity["type"] == "app" and entity["name"] == app_id)
836 or (run_id and entity["type"] == "run" and entity["name"] == run_id)
837 ]
838
839 # If filters provided but no matches found, raise error
840 if not to_delete and (user_id or agent_id or app_id or run_id):
841 raise ValueError("No entity found with the provided ID.")
842 # If no filters provided, delete all entities
843 elif not to_delete:
844 to_delete = entities["results"]
845
846 # Delete entities and check response immediately
847 for entity in to_delete:
848 response = await self.async_client.delete(f"/v1/entities/{entity['type']}/{entity['id']}/", params=params)
849 response.raise_for_status()
850
851 capture_client_event("async_client.delete_users", self.sync_client)
852 return {
853 "message": "Entity deleted successfully."
854 if (user_id or agent_id or app_id or run_id)
855 else "All users, agents, apps and runs deleted."
856 }
857
858 @api_error_handler
859 async def reset(self) -> Dict[str, str]:

Callers 1

resetMethod · 0.95

Calls 4

usersMethod · 0.95
capture_client_eventFunction · 0.90
_prepare_paramsMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected