The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Set output_format='v1.1' and update docs (#2480)
Dev Khant1db1105caded
diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdxindex c26d6be10..c049acb22 100644--- a/docs/platform/quickstart.mdx+++ b/docs/platform/quickstart.mdx@@ -86,11 +86,7 @@ messages = [{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}]-# The default output_format is v1.0-client.add(messages, user_id="alex", output_format="v1.0", version="v2")--# To use the latest output_format, set the output_format parameter to "v1.1"-client.add(messages, user_id="alex", output_format="v1.1", metadata={"food": "vegan"}, version="v2")+client.add(messages, user_id="alex", metadata={"food": "vegan"})``````javascript JavaScript@@ -98,7 +94,7 @@ const messages = [{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}];-client.add(messages, { user_id: "alex", output_format: "v1.1", metadata: { food: "vegan" }, version: "v2" })+client.add(messages, { user_id: "alex", metadata: { food: "vegan" } }).then(response => console.log(response)).catch(error => console.error(error));```@@ -113,40 +109,13 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}],"user_id": "alex",- "output_format": "v1.1","metadata": {"food": "vegan"- },- "version": "v2"+ }}'```-```json Output (v1.0)-[- {- "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",- "data": {- "memory": "Name is Alex"- },- "event": "ADD"- },- {- "id": "b2c3d4e5-f6g7-8h9i-j0k1-l2m3n4o5p6q7",- "data": {- "memory": "Is a vegetarian"- },- "event": "ADD"- },- {- "id": "c3d4e5f6-g7h8-9i0j-k1l2-m3n4o5p6q7r8",- "data": {- "memory": "Is allergic to nuts"- },- "event": "ADD"- }-]-```-```json Output (v1.1)+```json Output{"results": [{@@ -167,9 +136,6 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \</CodeGroup>--<Note> The `add` method offers support for two output formats: `v1.0` (default) and `v1.1`. To enable the latest format, which provides enhanced detail for each memory operation, set the `output_format` parameter to `v1.1`. </Note>-<Note>Messages passed along with `user_id`, `run_id`, or `app_id` are stored as user memories, while messages from the assistant are excluded from memory. To store messages for the assistant, use `agent_id` exclusively and avoid including other IDs, such as user_id, alongside it. This ensures the memory is properly attributed to the assistant.</Note>@@ -191,11 +157,7 @@ messages = [{"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."}]-# The default output_format is v1.0-client.add(messages, user_id="alex", run_id="trip-planning-2024", output_format="v1.0", version="v2")--# To use the latest output_format, set the output_format parameter to "v1.1"-client.add(messages, user_id="alex", run_id="trip-planning-2024", output_format="v1.1", version="v2")+client.add(messages, user_id="alex", run_id="trip-planning-2024")``````javascript JavaScript@@ -205,7 +167,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: "alex", run_id: "trip-planning-2024", output_format: "v1.1", version: "v2" })+client.add(messages, { user_id: "alex", run_id: "trip-planning-2024" }).then(response => console.log(response)).catch(error => console.error(error));```@@ -222,32 +184,11 @@ 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": "alex",- "run_id": "trip-planning-2024",- "output_format": "v1.1",- "version": "v2"+ "run_id": "trip-planning-2024"}'```-```json Output (v1.0)-[- {- "id": "f2968654-5cd8-4d58-9f40-57ee339846b6",- "data": {- "memory": "Interested in vegetarian restaurants in Tokyo"- },- "event": "ADD"- },- {- "id": "f2968654-5cd8-4d58-9f40-57ee339846b6",- "data": {- "memory": "Planning a trip to Japan next month"- },- "event": "ADD"- }-]-```--```json Output (v1.1)+```json Output{"results": [{@@ -275,11 +216,7 @@ messages = [{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}]-# The default output_format is v1.0-client.add(messages, agent_id="ai-tutor", output_format="v1.0", version="v2")--# To use the latest output_format, set the output_format parameter to "v1.1"-client.add(messages, agent_id="ai-tutor", output_format="v1.1", version="v2")+client.add(messages, agent_id="ai-tutor")``````javascript JavaScript@@ -287,7 +224,7 @@ const messages = [{"role": "system", "content": "You are an AI tutor with a personality. Give yourself a name for the user."},{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}];-client.add(messages, { agent_id: "ai-tutor", output_format: "v1.1", version: "v2" })+client.add(messages, { agent_id: "ai-tutor" }).then(response => console.log(response)).catch(error => console.error(error));```@@ -301,39 +238,11 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \{"role": "system", "content": "You are an AI tutor with a personality. Give yourself a name for the user."},{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}],- "agent_id": "ai-tutor",- "output_format": "v1.1",- "version": "v2"+ "agent_id": "ai-tutor"}'```-```json Output (v1.0)-[- {- "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",- "data": {- "memory": "Name is Alex"- },- "event": "ADD"- },- {- "id": "b2c3d4e5-f6g7-8h9i-j0k1-l2m3n4o5p6q7",- "data": {- "memory": "Is a vegetarian"- },- "event": "ADD"- },- {- "id": "c3d4e5f6-g7h8-9i0j-k1l2-m3n4o5p6q7r8",- "data": {- "memory": "Is allergic to nuts"- },- "event": "ADD"- }-]-```--```json Output (v1.1)+```json Output{"results": [{@@ -371,7 +280,7 @@ messages = [{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},]-client.add(messages=messages, user_id="user1", agent_id="agent1", version="v2")+client.add(messages=messages, user_id="user1", agent_id="agent1")``````javascript JavaScript@@ -380,7 +289,7 @@ const messages = [{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},]-client.add(messages, { user_id: "user1", agent_id: "agent1", version: "v2" })+client.add(messages, { user_id: "user1", agent_id: "agent1" }).then(response => console.log(response)).catch(error => console.error(error));```@@ -395,23 +304,25 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},],"user_id": "user1",- "agent_id": "agent1",- "version": "v2"+ "agent_id": "agent1"}'``````json Output-[- {- 'id': 'c57abfa2-f0ac-48af-896a-21728dbcecee0',- 'data': {'memory': 'Travelling to San Francisco'},- 'event': 'ADD'- },- { 'id': '0e8c003f-7db7-426a-9fdc-a46f9331a0c2',- 'data': {'memory': 'Going to Dubai next month'},- 'event': 'ADD'- }-]+{+ "results": [+ {+ "id": "c57abfa2-f0ac-48af-896a-21728dbcecee0",+ "data": {"memory": "Travelling to San Francisco"},+ "event": "ADD"+ },+ {+ "id": "0e8c003f-7db7-426a-9fdc-a46f9331a0c2",+ "data": {"memory": "Going to Dubai next month"},+ "event": "ADD"+ }+ ]+}```</CodeGroup>@@ -483,15 +394,17 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \``````json Output-[- {- "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",- "data": {- "memory": "In San Francisco until August 31st"- },- "event": "ADD"- }-]+{+ "results": [+ {+ "id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",+ "data": {+ "memory": "In San Francisco until August 31st"+ },+ "event": "ADD"+ }+ ]+}```</CodeGroup>@@ -519,11 +432,7 @@ Pass user messages, interactions, and queries into our search method to retrieve```python Pythonquery = "What should I cook for dinner today?"-# The default output_format is v1.0-client.search(query, user_id="alex", output_format="v1.0")--# To use the latest output_format, set the output_format parameter to "v1.1"-client.search(query, user_id="alex", output_format="v1.1")+client.search(query, user_id="alex")``````javascript JavaScript@@ -544,23 +453,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \}'```-```json Output (v1.0)-[- {- "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",- "memory": "Vegetarian. Allergic to nuts.",- "user_id": "alex",- "metadata": {"food": "vegan"},- "categories": ["food_preferences"],- "immutable": false,- "expiration_date": null,- "created_at": "2024-07-20T01:30:36.275141-07:00",- "updated_at": "2024-07-20T01:30:36.275172-07:00"- }-]-```--```json Output (v1.1)+```json Output{"results": [{@@ -608,19 +501,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \``````json Output-[- {- "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",- "memory": "Name: Alex. Vegetarian. Allergic to nuts.",- "user_id": "alex",- "metadata": {"food": "vegan"},- "categories": ["food_preferences"],- "immutable": false,- "expiration_date": null,- "created_at": "2024-07-20T01:30:36.275141-07:00",- "updated_at": "2024-07-20T01:30:36.275172-07:00"- }-]+{+ "results": [+ {+ "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",+ "memory": "Name: Alex. Vegetarian. Allergic to nuts.",+ "user_id": "alex",+ "metadata": {"food": "vegan"},+ "categories": ["food_preferences"],+ "immutable": false,+ "expiration_date": null,+ "created_at": "2024-07-20T01:30:36.275141-07:00",+ "updated_at": "2024-07-20T01:30:36.275172-07:00"+ }+ ]+}```</CodeGroup>@@ -699,19 +594,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \``````json Output-[- {- "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",- "memory": "Name: Alex. Vegetarian. Allergic to nuts.",- "user_id": "alex",- "metadata": null,- "categories": ["food_preferences"],- "immutable": false,- "expiration_date": null,- "created_at": "2024-07-20T01:30:36.275141-07:00",- "updated_at": "2024-07-20T01:30:36.275172-07:00"- }-]+{+ "results": [+ {+ "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",+ "memory": "Name: Alex. Vegetarian. Allergic to nuts.",+ "user_id": "alex",+ "metadata": null,+ "categories": ["food_preferences"],+ "immutable": false,+ "expiration_date": null,+ "created_at": "2024-07-20T01:30:36.275141-07:00",+ "updated_at": "2024-07-20T01:30:36.275172-07:00"+ }+ ]+}```</CodeGroup>@@ -765,19 +662,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \``````json Output-[- {- "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",- "memory": "Name: Alex. Vegetarian. Allergic to nuts.",- "user_id": "alex",- "metadata": null,- "categories": ["food_preferences"],- "immutable": false,- "expiration_date": null,- "created_at": "2024-07-20T01:30:36.275141-07:00",- "updated_at": "2024-07-20T01:30:36.275172-07:00"- }-]+{+ "results": [+ {+ "id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",+ "memory": "Name: Alex. Vegetarian. Allergic to nuts.",+ "user_id": "alex",+ "metadata": null,+ "categories": ["food_preferences"],+ "immutable": false,+ "expiration_date": null,+ "created_at": "2024-07-20T01:30:36.275141-07:00",+ "updated_at": "2024-07-20T01:30:36.275172-07:00"+ }+ ]+}```</CodeGroup>@@ -840,19 +739,21 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \``````json Output-[- {- "id": "654fee-b411-4afe-b7e5-35789b72c4a5",- "memory": "Name: Alex. Vegetarian. Allergic to nuts.",- "user_id": "alex",- "metadata": {"food": "vegan"},- "categories": ["food_preferences"],- "immutable": false,- "expiration_date": null,- "created_at": "2024-07-20T01:30:36.275141-07:00",- "updated_at": "2024-07-20T01:30:36.275172-07:00"- }-]+{+ "results": [+ {+ "id": "654fee-b411-4afe-b7e5-35789b72c4a5",+ "memory": "Name: Alex. Vegetarian. Allergic to nuts.",+ "user_id": "alex",+ "metadata": {"food": "vegan"},+ "categories": ["food_preferences"],+ "immutable": false,+ "expiration_date": null,+ "created_at": "2024-07-20T01:30:36.275141-07:00",+ "updated_at": "2024-07-20T01:30:36.275172-07:00"+ }+ ]+}```</CodeGroup>@@ -936,48 +837,13 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex&page=1&page_size=50"-H "Authorization: Token your-api-key"```-```json Output (v1.0)-{- "count": 204,- "next": "https://api.mem0.ai/v1/memories/?user_id=alex&page=2&page_size=50",- "previous": null,- "results": [- {- "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",- "memory":"是素食主义者,对坚果过敏。",- "agent_id":"travel-assistant",- "hash":"62bc074f56d1f909f1b4c2b639f56f6a",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-25T23:57:00.108347-07:00",- "updated_at":"2024-07-25T23:57:00.108367-07:00",- "categories":None- },- {- "id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",- "memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.",- "agent_id":"travel-assistant",- "hash":"35a305373d639b0bffc6c2a3e2eb4244",- "metadata":"None",- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-26T00:31:03.543759-07:00",- "updated_at":"2024-07-26T00:31:03.543778-07:00",- "categories":None- }- ... (remaining 48 memories)- ]-}-```-```json Output (v1.1){"count": 204,"next": "https://api.mem0.ai/v1/memories/?user_id=alex&output_format=v1.1&page=2&page_size=50","previous": null,- "results": {- "results": [+ "results":+ [{"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7","memory":"是素食主义者,对坚果过敏。",@@ -1003,8 +869,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex&page=1&page_size=50""categories":None}... (remaining 48 memories)- ]- }+ ]}```@@ -1029,48 +894,13 @@ curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=ai-tutor&page=1&page_size-H "Authorization: Token your-api-key"```-```json Output (v1.0)-{- "count": 78,- "next": "https://api.mem0.ai/v1/memories/?agent_id=ai-tutor&page=2&page_size=50",- "previous": null,- "results": [- {- "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",- "memory":"是素食主义者,对坚果过敏。",- "agent_id":"ai-tutor",- "hash":"62bc074f56d1f909f1b4c2b639f56f6a",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-25T23:57:00.108347-07:00",- "updated_at":"2024-07-25T23:57:00.108367-07:00",- "categories":None- },- {- "id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",- "memory":"My name is Alice.",- "agent_id":"ai-tutor",- "hash":"35a305373d639b0bffc6c2a3e2eb4244",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-26T00:31:03.543759-07:00",- "updated_at":"2024-07-26T00:31:03.543778-07:00",- "categories":None- }- ... (remaining 48 memories)- ]-}-```-```json Output (v1.1){"count": 78,"next": "https://api.mem0.ai/v1/memories/?agent_id=ai-tutor&output_format=v1.1&page=2&page_size=50","previous": null,- "results": {- "results": [+ "results":+ [{"id": "f38b689d-6b24-45b7-bced-17fbb4d8bac7","memory": "是素食主义者,对坚果过敏。",@@ -1094,8 +924,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=ai-tutor&page=1&page_size"updated_at": "2024-07-26T00:31:03.543778-07:00"}... (remaining 48 memories)- ]- }+ ]}```</CodeGroup>@@ -1119,60 +948,13 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex&run_id=trip-planning--H "Authorization: Token your-api-key"```-```json Output (v1.0)-{- "count": 18,- "next": null,- "previous": null,- "results": [- {- "id":"06d8df63-7bd2-4fad-9acb-60871bcecee0",- "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.",- "user_id":"alex",- "hash":"d2088c936e259f2f5d2d75543d31401c",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-26T00:25:16.566471-07:00",- "updated_at":"2024-07-26T00:25:16.566492-07:00",- "categories":None- },- {- "id":"b4229775-d860-4ccb-983f-0f628ca112f5",- "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.",- "user_id":"alex",- "hash":"d2088c936e259f2f5d2d75543d31401c",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-26T00:33:20.350542-07:00",- "updated_at":"2024-07-26T00:33:20.350560-07:00",- "categories":None- },- {- "id":"df1aca24-76cf-4b92-9f58-d03857efcb64",- "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.",- "user_id":"alex",- "hash":"d2088c936e259f2f5d2d75543d31401c",- "metadata":None,- "immutable": false,- "expiration_date": null,- "created_at":"2024-07-26T00:51:09.642275-07:00",- "updated_at":"2024-07-26T00:51:09.642295-07:00",- "categories":None- }- ... (remaining 15 memories)- ]-}-```--```json Output (v1.1)+```json Output{"count": 18,"next": null,"previous": null,- "results": {- "results": [+ "results":+ [{"id": "06d8df63-7bd2-4fad-9acb-60871bcecee0","memory": "Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.",@@ -1211,7 +993,6 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex&run_id=trip-planning-}... (remaining 15 memories)]- }}```</CodeGroup>diff --git a/mem0/client/main.py b/mem0/client/main.pyindex 346096188..bff698ab1 100644--- a/mem0/client/main.py+++ b/mem0/client/main.py@@ -130,13 +130,14 @@ class MemoryClient:"""kwargs = self._prepare_params(kwargs)if kwargs.get("output_format") != "v1.1":+ kwargs["output_format"] = "v1.1"warnings.warn(- "Using default output format 'v1.0' is deprecated and will be removed in version 0.1.70. "- "Please use output_format='v1.1' for enhanced memory details. "+ "output_format='v1.0' is deprecated therefore setting it to 'v1.1' by default.""Check out the docs for more information: https://docs.mem0.ai/platform/quickstart#4-1-create-memories",DeprecationWarning,stacklevel=2,)+ kwargs["version"] = "v2"payload = self._prepare_payload(messages, kwargs)response = self.client.post("/v1/memories/", json=payload)response.raise_for_status()