From 5b9be679a836bfafc048a8527022d4cb13ba4b2d Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Mon, 16 Sep 2024 09:30:21 +0530 Subject: [PATCH] Migrate session_id -> run_id (#1864) Co-authored-by: Deshraj Yadav --- docs/platform/quickstart.mdx | 26 ++++++++++++++------------ mem0/client/main.py | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index 95d34605..6732253f 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -130,10 +130,10 @@ messages = [ ] # The default output_format is v1.0 -client.add(messages, user_id="alex123", session_id="trip-planning-2024", output_format="v1.0") +client.add(messages, user_id="alex123", run_id="trip-planning-2024", output_format="v1.0") # To use the latest output_format, set the output_format parameter to "v1.1" -client.add(messages, user_id="alex123", session_id="trip-planning-2024", output_format="v1.1") +client.add(messages, user_id="alex123", run_id="trip-planning-2024", output_format="v1.1") ``` ```javascript JavaScript @@ -143,7 +143,7 @@ const messages = [ {"role": "user", "content": "Yes, please! Especially in Tokyo."}, {"role": "assistant", "content": "Great! I'll remember that you're interested in vegetarian restaurants in Tokyo for your upcoming trip. I'll prepare a list for you in our next interaction."} ]; -client.add(messages, { user_id: "alex123", session_id: "trip-planning-2024", output_format: "v1.1" }) +client.add(messages, { user_id: "alex123", run_id: "trip-planning-2024", output_format: "v1.1" }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` @@ -160,7 +160,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ {"role": "assistant", "content": "Great! I'll remember that you're interested in vegetarian restaurants in Tokyo for your upcoming trip. I'll prepare a list for you in our next interaction."} ], "user_id": "alex123", - "session_id": "trip-planning-2024", + "run_id": "trip-planning-2024", "output_format": "v1.1" }' ``` @@ -186,7 +186,9 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ - + + Please use `run_id` instead of `session_id`. The `session_id` parameter is deprecated and will be removed in version 0.1.20. + #### Long-term memory for agents @@ -527,7 +529,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \ ### 4.3 Get All Users -Get all users, agents, and sessions which have memories associated with them. +Get all users, agents, and runs which have memories associated with them. @@ -579,7 +581,7 @@ curl -X GET "https://api.mem0.ai/v1/entities/" \ ### 4.4 Get All Memories -Fetch all memories for a user, agent, or session using the getAll() method. +Fetch all memories for a user, agent, or run using the getAll() method. The `get_all` method supports two output formats: `v1.0` (default) and `v1.1`. To use the latest format, which provides more detailed information about each memory operation, set the `output_format` parameter to `v1.1`: @@ -735,20 +737,20 @@ curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=travel-assistant&output_f ```python Python # The default output_format is v1.0 -short_term_memories = client.get_all(user_id="alex123", session_id="trip-planning-2024", output_format="v1.0") +short_term_memories = client.get_all(user_id="alex123", run_id="trip-planning-2024", output_format="v1.0") # To use the latest output_format (v1.1), set the output_format parameter to "v1.1" -short_term_memories = client.get_all(user_id="alex123", session_id="trip-planning-2024", output_format="v1.1") +short_term_memories = client.get_all(user_id="alex123", run_id="trip-planning-2024", output_format="v1.1") ``` ```javascript JavaScript -client.getAll({ user_id: "alex123", session_id: "trip-planning-2024", output_format: "v1.1" }) +client.getAll({ user_id: "alex123", run_id: "trip-planning-2024", output_format: "v1.1" }) .then(memories => console.log(memories)) .catch(error => console.error(error)); ``` ```bash cURL -curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex123&session_id=trip-planning-2024&output_format=v1.1" \ +curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex123&run_id=trip-planning-2024&output_format=v1.1" \ -H "Authorization: Token your-api-key" ``` @@ -1050,7 +1052,7 @@ client.delete_users() ``` ```json Output -{'message': 'All users, agents, and sessions deleted.'} +{'message': 'All users, agents, and runs deleted.'} ``` diff --git a/mem0/client/main.py b/mem0/client/main.py index 737c96e8..ae0519b9 100644 --- a/mem0/client/main.py +++ b/mem0/client/main.py @@ -1,5 +1,6 @@ import logging import os +import warnings from functools import wraps from typing import Any, Dict, List, Optional, Union @@ -9,6 +10,7 @@ from mem0.memory.setup import setup_config from mem0.memory.telemetry import capture_client_event logger = logging.getLogger(__name__) +warnings.filterwarnings('always', category=DeprecationWarning, message="The 'session_id' parameter is deprecated. User 'run_id' instead.") # Setup user config setup_config() @@ -303,6 +305,17 @@ class MemoryClient: payload["messages"] = [{"role": "user", "content": messages}] elif isinstance(messages, list): payload["messages"] = messages + + # Handle session_id deprecation + if "session_id" in kwargs: + warnings.warn( + "The 'session_id' parameter is deprecated and will be removed in version 0.1.20. " + "Use 'run_id' instead.", + DeprecationWarning, + stacklevel=2 + ) + kwargs["run_id"] = kwargs.pop("session_id") + payload.update({k: v for k, v in kwargs.items() if v is not None}) return payload @@ -315,4 +328,15 @@ class MemoryClient: Returns: A dictionary containing the prepared parameters. """ + + # Handle session_id deprecation + if "session_id" in kwargs: + warnings.warn( + "The 'session_id' parameter is deprecated and will be removed in version 0.1.20. " + "Use 'run_id' instead.", + DeprecationWarning, + stacklevel=2 + ) + kwargs["run_id"] = kwargs.pop("session_id") + return {k: v for k, v in kwargs.items() if v is not None}