diff --git a/cookbooks/multion_travel_agent.ipynb b/cookbooks/multion_travel_agent.ipynb new file mode 100644 index 00000000..19633707 --- /dev/null +++ b/cookbooks/multion_travel_agent.ipynb @@ -0,0 +1,306 @@ +{ + "cells": [ + { + "cell_type": "code", + "source": [ + "!pip install mem0ai" + ], + "metadata": { + "id": "fu3euPKZsbaC" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "U2VC_0FElQid" + }, + "outputs": [], + "source": [ + "import os\n", + "from openai import OpenAI\n", + "from mem0 import MemoryClient\n", + "from multion.client import MultiOn\n", + "\n", + "# Configuration\n", + "OPENAI_API_KEY = 'sk-xxx' # Replace with your actual OpenAI API key\n", + "MULTION_API_KEY = 'xx' # Replace with your actual MultiOn API key\n", + "MEM0_API_KEY = 'xx' # Replace with your actual Mem0 API key\n", + "USER_ID = \"test_travel_agent\"\n", + "\n", + "# Set up OpenAI API key\n", + "os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY\n", + "\n", + "# Initialize Mem0 and MultiOn\n", + "memory = MemoryClient(api_key=MEM0_API_KEY)\n", + "multion = MultiOn(api_key=MULTION_API_KEY)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "sq-OdPHKlQie", + "outputId": "1d605222-0bf5-4ac9-99b9-6059b502c20b" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'message': 'Memory added successfully!'}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add conversation to Mem0\n", + "conversation = [\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": \"What are the best travel destinations in the world?\"\n", + " },\n", + " {\n", + " \"role\": \"assistant\",\n", + " \"content\": \"Could you please specify your interests or the type of travel information you are looking for? This will help me find the most relevant information for you.\"\n", + " },\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": \"Sure, I want to travel to San Francisco.\"\n", + " },\n", + " {\n", + " \"role\": \"assistant\",\n", + " \"content\": \"\"\"\n", + " Based on the information gathered from TripAdvisor, here are some popular attractions, activities, and travel tips for San Francisco:\n", + "\n", + " 1. **Golden Gate Bridge**: A must-see iconic landmark.\n", + " 2. **Alcatraz Island**: Famous former prison offering tours.\n", + " 3. **Fisherman's Wharf**: Popular tourist area with shops, restaurants, and sea lions.\n", + " 4. **Chinatown**: The largest Chinatown outside of Asia.\n", + " 5. **Golden Gate Park**: Large urban park with gardens, museums, and recreational activities.\n", + " 6. **Cable Cars**: Historic streetcars offering a unique way to see the city.\n", + " 7. **Exploratorium**: Interactive science museum.\n", + " 8. **San Francisco Museum of Modern Art (SFMOMA)**: Modern and contemporary art museum.\n", + " 9. **Lombard Street**: Known for its steep, one-block section with eight hairpin turns.\n", + " 10. **Union Square**: Major shopping and cultural hub.\n", + "\n", + " Travel Tips:\n", + " - **Weather**: San Francisco has a mild climate, but it can be foggy and windy. Dress in layers.\n", + " - **Transportation**: Use public transportation like BART, Muni, and cable cars to get around.\n", + " - **Safety**: Be aware of your surroundings, especially in crowded tourist areas.\n", + " - **Dining**: Try local specialties like sourdough bread, seafood, and Mission-style burritos.\n", + " \"\"\"\n", + " },\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": \"Show me hotels around Golden Gate Bridge.\"\n", + " },\n", + " {\n", + " \"role\": \"assistant\",\n", + " \"content\": \"\"\"\n", + " The search results for hotels around Golden Gate Bridge in San Francisco include:\n", + "\n", + " 1. Hilton Hotels In San Francisco - Hotel Near Fishermans Wharf (hilton.com)\n", + " 2. The 10 Closest Hotels to Golden Gate Bridge (tripadvisor.com)\n", + " 3. Hotels near Golden Gate Bridge (expedia.com)\n", + " 4. Hotels near Golden Gate Bridge (hotels.com)\n", + " 5. Holiday Inn Express & Suites San Francisco Fishermans Wharf, an IHG Hotel $146 (1.8K) 3-star hotel Golden Gate Bridge • 3.5 mi DEAL 19% less than usual\n", + " 6. Holiday Inn San Francisco-Golden Gateway, an IHG Hotel $151 (3.5K) 3-star hotel Golden Gate Bridge • 3.7 mi Casual hotel with dining, a bar & a pool\n", + " 7. Hotel Zephyr San Francisco $159 (3.8K) 4-star hotel Golden Gate Bridge • 3.7 mi Nautical-themed lodging with bay views\n", + " 8. Lodge at the Presidio\n", + " 9. The Inn Above Tide\n", + " 10. Cavallo Point\n", + " 11. Casa Madrona Hotel and Spa\n", + " 12. Cow Hollow Inn and Suites\n", + " 13. Samesun San Francisco\n", + " 14. Inn on Broadway\n", + " 15. Coventry Motor Inn\n", + " 16. HI San Francisco Fisherman's Wharf Hostel\n", + " 17. Loews Regency San Francisco Hotel\n", + " 18. Fairmont Heritage Place Ghirardelli Square\n", + " 19. Hotel Drisco Pacific Heights\n", + " 20. Travelodge by Wyndham Presidio San Francisco\n", + " \"\"\"\n", + " }\n", + "]\n", + "\n", + "memory.add(conversation, user_id=USER_ID)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hO8z9aNTlQif" + }, + "outputs": [], + "source": [ + "def get_travel_info(question, use_memory=True):\n", + " \"\"\"\n", + " Get travel information based on user's question and optionally their preferences from memory.\n", + "\n", + " \"\"\"\n", + " if use_memory:\n", + " previous_memories = memory.search(question, user_id=USER_ID)\n", + " relevant_memories_text = \"\"\n", + " if previous_memories:\n", + " print(\"Using previous memories to enhance the search...\")\n", + " relevant_memories_text = '\\n'.join(mem[\"memory\"] for mem in previous_memories)\n", + "\n", + " command = \"Find travel information based on my interests:\"\n", + " prompt = f\"{command}\\n Question: {question} \\n My preferences: {relevant_memories_text}\"\n", + " else:\n", + " command = \"Find travel information based on my interests:\"\n", + " prompt = f\"{command}\\n Question: {question}\"\n", + "\n", + "\n", + " print(\"Searching for travel information...\")\n", + " browse_result = multion.browse(cmd=prompt)\n", + " return browse_result.message" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Wp2xpzMrlQig" + }, + "source": [ + "## Example 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bPRPwqsplQig" + }, + "outputs": [], + "source": [ + "question = \"Show me flight details for it.\"\n", + "answer_without_memory = get_travel_info(question, use_memory=False)\n", + "answer_with_memory = get_travel_info(question, use_memory=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "a76ifa2HlQig" + }, + "source": [ + "| Without Memory | With Memory |\n", + "|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n", + "| I have performed a Google search for \"flight details\" and reviewed the search results. Here are some relevant links and information: | Memorizing the following information: Flight details for San Francisco: |\n", + "| 1. **FlightStats Global Flight Tracker** - Track the real-time flight status of your flight. See if your flight has been delayed or cancelled and track the live status.
[Flight Tracker - FlightStats](https://www.flightstats.com/flight-tracker/search) | 1. Prices from $232. Depart Thursday, August 22. Return Thursday, August 29.
2. Prices from $216. Depart Friday, August 23. Return Friday, August 30.
3. Prices from $236. Depart Saturday, August 24. Return Saturday, August 31.
4. Prices from $215. Depart Sunday, August 25. Return Sunday, September 1. |\n", + "| 2. **FlightAware - Flight Tracker** - Track live flights worldwide, see flight cancellations, and browse by airport.
[FlightAware - Flight Tracker](https://www.flightaware.com) | 5. Prices from $218. Depart Monday, August 26. Return Monday, September 2.
6. Prices from $211. Depart Tuesday, August 27. Return Tuesday, September 3.
7. Prices from $198. Depart Wednesday, August 28. Return Wednesday, September 4.
8. Prices from $218. Depart Thursday, August 29. Return Thursday, September 5. |\n", + "| 3. **Google Flights** - Show flights based on your search.
[Google Flights](https://www.google.com/flights) | 9. Prices from $194. Depart Friday, August 30. Return Friday, September 6.
10. Prices from $218. Depart Saturday, August 31. Return Saturday, September 7.
11. Prices from $212. Depart Sunday, September 1. Return Sunday, September 8.
12. Prices from $247. Depart Monday, September 2. Return Monday, September 9. |\n", + "| | 13. Prices from $212. Depart Tuesday, September 3. Return Tuesday, September 10.
14. Prices from $203. Depart Wednesday, September 4. Return Wednesday, September 11.
15. Prices from $242. Depart Thursday, September 5. Return Thursday, September 12.
16. Prices from $191. Depart Friday, September 6. Return Friday, September 13. |\n", + "| | 17. Prices from $215. Depart Saturday, September 7. Return Saturday, September 14.
18. Prices from $229. Depart Sunday, September 8. Return Sunday, September 15.
19. Prices from $183. Depart Monday, September 9. Return Monday, September 16.
65. Prices from $194. Depart Friday, October 25. Return Friday, November 1. |\n", + "| | 66. Prices from $205. Depart Saturday, October 26. Return Saturday, November 2.
67. Prices from $241. Depart Sunday, October 27. Return Sunday, November 3. |\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0cXpiAwMlQig" + }, + "source": [ + "## Example 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "LpprKfpslQih" + }, + "outputs": [], + "source": [ + "question = \"What places to visit there?\"\n", + "answer_without_memory = get_travel_info(question, use_memory=False)\n", + "answer_with_memory = get_travel_info(question, use_memory=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kpfjeY1_lQih" + }, + "source": [ + "| Without Memory | With Memory |\n", + "|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n", + "| Based on the information gathered, here are some top travel destinations to consider visiting: | Based on the information gathered, here are some top places to visit in San Francisco: |\n", + "| 1. **Paris**: Known for its iconic attractions like the Eiffel Tower and the Louvre, Paris offers quaint cafes, trendy shopping districts, and beautiful Haussmann architecture. It's a city where you can always discover something new with each visit. | 1. **Golden Gate Bridge** - An iconic symbol of San Francisco, perfect for walking, biking, or simply enjoying the view.
2. **Alcatraz Island** - The historic former prison offers tours and insights into its storied past.
3. **Fisherman's Wharf** - A bustling waterfront area known for its seafood, shopping, and attractions like Pier 39.
4. **Golden Gate Park** - A large urban park with gardens, museums, and recreational activities.
5. **Chinatown San Francisco** - One of the oldest and most famous Chinatowns in North America, offering unique shops and delicious food.
6. **Coit Tower** - Offers panoramic views of the city and murals depicting San Francisco's history.
7. **Lands End** - A beautiful coastal trail with stunning views of the Pacific Ocean and the Golden Gate Bridge.
8. **Palace of Fine Arts** - A picturesque structure and park, perfect for a leisurely stroll or photo opportunities.
9. **Crissy Field & The Presidio Tunnel Tops** - Great for outdoor activities and scenic views of the bay. |\n", + "| 2. **Bora Bora**: This small island in French Polynesia is famous for its stunning turquoise waters, luxurious overwater bungalows, and vibrant coral reefs. It's a popular destination for honeymooners and those seeking a tropical paradise. | |\n", + "| 3. **Glacier National Park**: Located in Montana, USA, this park is known for its breathtaking landscapes, including rugged mountains, pristine lakes, and diverse wildlife. It's a haven for outdoor enthusiasts and hikers. | |\n", + "| 4. **Rome**: The capital of Italy, Rome is rich in history and culture, featuring landmarks such as the Colosseum, the Vatican, and the Pantheon. It's a city where ancient history meets modern life. | |\n", + "| 5. **Swiss Alps**: Renowned for their stunning natural beauty, the Swiss Alps offer opportunities for skiing, hiking, and enjoying picturesque mountain villages. | |\n", + "| 6. **Maui**: One of Hawaii's most popular islands, Maui is known for its beautiful beaches, lush rainforests, and the scenic Hana Highway. It's a great destination for both relaxation and adventure. | |\n", + "| 7. **London, England**: A vibrant city with a mix of historical landmarks like the Tower of London and modern attractions such as the London Eye. London offers diverse cultural experiences, world-class museums, and a bustling nightlife. | |\n", + "| 8. **Maldives**: This tropical paradise in the Indian Ocean is famous for its crystal-clear waters, luxurious resorts, and abundant marine life. It's an ideal destination for snorkeling, diving, and relaxation. | |\n", + "| 9. **Turks & Caicos**: Known for its pristine beaches and turquoise waters, this Caribbean destination is perfect for water sports, beach lounging, and exploring coral reefs. | |\n", + "| 10. **Tokyo**: Japan's bustling capital offers a unique blend of traditional and modern attractions, from ancient temples to futuristic skyscrapers. Tokyo is also known for its vibrant food scene and shopping districts. | |\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XdpkcMrclQih" + }, + "source": [ + "## Example 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Nntl2FxulQih" + }, + "outputs": [], + "source": [ + "question = \"What the weather there?\"\n", + "answer_without_memory = get_travel_info(question, use_memory=False)\n", + "answer_with_memory = get_travel_info(question, use_memory=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yt2pj1irlQih" + }, + "source": [ + "| Without Memory | With Memory |\n", + "|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n", + "| The current weather in Paris is light rain with a temperature of 67°F. The precipitation is at 50%, humidity is 95%, and the wind speed is 5 mph. | The current weather in San Francisco is as follows:
- **Temperature**: 59°F
- **Condition**: Clear with periodic clouds
- **Precipitation**: 3%
- **Humidity**: 87%
- **Wind**: 12 mph |\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + }, + "colab": { + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/docs/integrations/multion.mdx b/docs/integrations/multion.mdx index e3d4c908..de05a812 100644 --- a/docs/integrations/multion.mdx +++ b/docs/integrations/multion.mdx @@ -6,42 +6,48 @@ Build personal browser agent remembers user preferences and automates web tasks. ## Overview -In this example, we will create a Browser based AI Agent that searches [arxiv.org](https://arxiv.org) for research papers relevant to user's research interests. +In this guide, we'll explore two examples of creating Browser-based AI Agents: +1. An agent that searches [arxiv.org](https://arxiv.org) for research papers relevant to user's research interests. +2. A travel agent that provides personalized travel information based on user preferences. ## Setup and Configuration Install necessary libraries: ```bash -pip install mem0ai multion +pip install mem0ai multion openai ``` First, we'll import the necessary libraries and set up our configurations. ```python import os -from mem0 import Memory +from mem0 import Memory, MemoryClient from multion.client import MultiOn +from openai import OpenAI # Configuration OPENAI_API_KEY = 'sk-xxx' # Replace with your actual OpenAI API key MULTION_API_KEY = 'your-multion-key' # Replace with your actual MultiOn API key -USER_ID = "deshraj" +MEM0_API_KEY = 'your-mem0-key' # Replace with your actual Mem0 API key +USER_ID = "your-user-id" # Set up OpenAI API key os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY # Initialize Mem0 and MultiOn -memory = Memory() +memory = Memory() # For local usage +memory_client = MemoryClient(api_key=MEM0_API_KEY) # For API usage multion = MultiOn(api_key=MULTION_API_KEY) ``` -## Add memories to Mem0 +## Example 1: Research Paper Search Agent -Next, we'll define our user data and add it to Mem0. +### Add memories to Mem0 + +Define user data and add it to Mem0. ```python -# Define user data USER_DATA = """ About me - I'm Deshraj Yadav, Co-founder and CTO at Mem0, interested in AI and ML Infrastructure. @@ -50,17 +56,15 @@ About me - Outside of work, I enjoy playing cricket in two leagues in the San Francisco. """ -# Add user data to memory memory.add(USER_DATA, user_id=USER_ID) print("User data added to memory.") ``` -## Retrieving Relevant Memories +### Retrieving Relevant Memories -Now, we'll define our search command and retrieve relevant memories from Mem0. +Define search command and retrieve relevant memories from Mem0. ```python -# Define search command and retrieve relevant memories command = "Find papers on arxiv that I should read based on my interests." relevant_memories = memory.search(command, user_id=USER_ID, limit=3) @@ -69,22 +73,139 @@ print(f"Relevant memories:") print(relevant_memories_text) ``` -## Browsing arXiv +### Browsing arXiv -Finally, we'll use MultiOn to browse arXiv based on our command and relevant memories. +Use MultiOn to browse arXiv based on the command and relevant memories. ```python -# Create prompt and browse arXiv prompt = f"{command}\n My past memories: {relevant_memories_text}" browse_result = multion.browse(cmd=prompt, url="https://arxiv.org/") print(browse_result) ``` +## Example 2: Travel Agent + +### Get Travel Information + +Add conversation to Mem0 and create a function to get travel information based on user's question and optionally their preferences from memory. + + +```python Code +def get_travel_info(question, use_memory=True): + if use_memory: + previous_memories = memory_client.search(question, user_id=USER_ID) + relevant_memories_text = "" + if previous_memories: + print("Using previous memories to enhance the search...") + relevant_memories_text = '\n'.join(mem["memory"] for mem in previous_memories) + + command = "Find travel information based on my interests:" + prompt = f"{command}\n Question: {question} \n My preferences: {relevant_memories_text}" + else: + command = "Find travel information based on my interests:" + prompt = f"{command}\n Question: {question}" + + print("Searching for travel information...") + browse_result = multion.browse(cmd=prompt) + return browse_result.message + +# Example usage +question = "Show me flight details for it." +answer_without_memory = get_travel_info(question, use_memory=False) +answer_with_memory = get_travel_info(question, use_memory=True) + +print("Answer without memory:", answer_without_memory) +print("Answer with memory:", answer_with_memory) + +# Another example +question = "What is the best place to eat there?" +answer_without_memory = get_travel_info(question, use_memory=False) +answer_with_memory = get_travel_info(question, use_memory=True) + +print("Answer without memory:", answer_without_memory) +print("Answer with memory:", answer_with_memory) +``` + +```json Conversation +# Add conversation to Mem0 +conversation = [ + { + "role": "user", + "content": "What are the best travel destinations in the world?" + }, + { + "role": "assistant", + "content": "Could you please specify your interests or the type of travel information you are looking for? This will help me find the most relevant information for you." + }, + { + "role": "user", + "content": "Sure, I want to travel to San Francisco." + }, + { + "role": "assistant", + "content": """ + Based on the information gathered from TripAdvisor, here are some popular attractions, activities, and travel tips for San Francisco: \ + + 1. **Golden Gate Bridge**: A must-see iconic landmark. \ + 2. **Alcatraz Island**: Famous former prison offering tours. \ + 3. **Fisherman's Wharf**: Popular tourist area with shops, restaurants, and sea lions. \ + 4. **Chinatown**: The largest Chinatown outside of Asia. \ + 5. **Golden Gate Park**: Large urban park with gardens, museums, and recreational activities. \ + 6. **Cable Cars**: Historic streetcars offering a unique way to see the city. \ + 7. **Exploratorium**: Interactive science museum. \ + 8. **San Francisco Museum of Modern Art (SFMOMA)**: Modern and contemporary art museum. \ + 9. **Lombard Street**: Known for its steep, one-block section with eight hairpin turns. \ + 10. **Union Square**: Major shopping and cultural hub. \ + + Travel Tips: \ + - **Weather**: San Francisco has a mild climate, but it can be foggy and windy. Dress in layers. \ + - **Transportation**: Use public transportation like BART, Muni, and cable cars to get around. \ + - **Safety**: Be aware of your surroundings, especially in crowded tourist areas. \ + - **Dining**: Try local specialties like sourdough bread, seafood, and Mission-style burritos. \ + """ + }, + { + "role": "user", + "content": "Show me hotels around Golden Gate Bridge." + }, + { + "role": "assistant", + "content": """The search results for hotels around Golden Gate Bridge in San Francisco include: \ + + 1. Hilton Hotels In San Francisco - Hotel Near Fishermans Wharf (hilton.com) \ + 2. The 10 Closest Hotels to Golden Gate Bridge (tripadvisor.com) \ + 3. Hotels near Golden Gate Bridge (expedia.com) \ + 4. Hotels near Golden Gate Bridge (hotels.com) \ + 5. Holiday Inn Express & Suites San Francisco Fishermans Wharf, an IHG Hotel $146 (1.8K) 3-star hotel Golden Gate Bridge • 3.5 mi DEAL 19% less than usual \ + 6. Holiday Inn San Francisco-Golden Gateway, an IHG Hotel $151 (3.5K) 3-star hotel Golden Gate Bridge • 3.7 mi Casual hotel with dining, a bar & a pool \ + 7. Hotel Zephyr San Francisco $159 (3.8K) 4-star hotel Golden Gate Bridge • 3.7 mi Nautical-themed lodging with bay views \ + 8. Lodge at the Presidio \ + 9. The Inn Above Tide \ + 10. Cavallo Point \ + 11. Casa Madrona Hotel and Spa \ + 12. Cow Hollow Inn and Suites \ + 13. Samesun San Francisco \ + 14. Inn on Broadway \ + 15. Coventry Motor Inn \ + 16. HI San Francisco Fisherman's Wharf Hostel \ + 17. Loews Regency San Francisco Hotel \ + 18. Fairmont Heritage Place Ghirardelli Square \ + 19. Hotel Drisco Pacific Heights \ + 20. Travelodge by Wyndham Presidio San Francisco \ + """ + } +] +``` + + ## Conclusion -By integrating Mem0 with MultiOn, you've created a personalized browser agent that remembers user preferences and automates web tasks. For more details and advanced usage, refer to the full [cookbook here](https://github.com/mem0ai/mem0/blob/main/cookbooks/mem0-multion.ipynb). +By integrating Mem0 with MultiOn, you've created personalized browser agents that remember user preferences and automate web tasks. The first example demonstrates a research-focused agent, while the second example shows a travel agent capable of providing personalized recommendations. + +These examples illustrate how combining memory management with web browsing capabilities can create powerful, context-aware AI agents for various applications. ## Help +- For more details and advanced usage, refer to the full [cookbooks here](https://github.com/mem0ai/mem0/blob/main/cookbooks). - Feel free to visit our [Github](https://github.com/mem0ai/mem0) or [Mem0 Platform](https://app.mem0.ai/). - For any questions or assistance, please reach out to `taranjeetio` on [Discord](https://mem0.ai/discord). \ No newline at end of file diff --git a/docs/platform/quickstart.mdx b/docs/platform/quickstart.mdx index 27617c8c..68182a5e 100644 --- a/docs/platform/quickstart.mdx +++ b/docs/platform/quickstart.mdx @@ -80,6 +80,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ "user_id": "alex" }' ``` + +```json Output +{'message': 'ok'} +``` #### Short-term memory for a user session @@ -123,6 +127,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ "session_id": "trip-planning-2024" }' ``` + +```json Output +{'message': 'ok'} +``` #### Long-term memory for agents @@ -159,6 +167,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ "agent_id": "travel-assistant" }' ``` + +```json Output +{'message': 'ok'} +``` You can monitor memory operations on the platform: @@ -239,6 +251,29 @@ client.getAll({ agent_id: "travel-assistant" }) curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=travel-assistant" \ -H "Authorization: Token your-api-key" ``` + +```json Output +[ + { + "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", + "memory":"是素食主义者,对坚果过敏。", + "agent_id":"travel-assistant", + "hash":"62bc074f56d1f909f1b4c2b639f56f6a", + "metadata":"None", + "created_at":"2024-07-25T23:57:00.108347-07:00", + "updated_at":"2024-07-25T23:57:00.108367-07:00" + }, + { + "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", + "created_at":"2024-07-26T00:31:03.543759-07:00", + "updated_at":"2024-07-26T00:31:03.543778-07:00" + } +] +``` #### Get all memories of user @@ -259,6 +294,29 @@ client.getAll({ user_id: "alex" }) curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex" \ -H "Authorization: Token your-api-key" ``` + +```json Output +[ + { + "id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7", + "memory":"是素食主义者,对坚果过敏。", + "agent_id":"travel-assistant", + "hash":"62bc074f56d1f909f1b4c2b639f56f6a", + "metadata":"None", + "created_at":"2024-07-25T23:57:00.108347-07:00", + "updated_at":"2024-07-25T23:57:00.108367-07:00" + }, + { + "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", + "created_at":"2024-07-26T00:31:03.543759-07:00", + "updated_at":"2024-07-26T00:31:03.543778-07:00" + } +] +``` #### Get short-term memories for a session @@ -279,6 +337,38 @@ client.getAll({ user_id: "alex123", session_id: "trip-planning-2024" }) curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex123&session_id=trip-planning-2024" \ -H "Authorization: Token your-api-key" ``` + +```json Output +[ + { + "id":"06d8df63-7bd2-4fad-9acb-60871bcecee0", + "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.", + "user_id":"alex123", + "hash":"d2088c936e259f2f5d2d75543d31401c", + "metadata":"None", + "created_at":"2024-07-26T00:25:16.566471-07:00", + "updated_at":"2024-07-26T00:25:16.566492-07:00" + }, + { + "id":"b4229775-d860-4ccb-983f-0f628ca112f5", + "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.", + "user_id":"alex123", + "hash":"d2088c936e259f2f5d2d75543d31401c", + "metadata":"None", + "created_at":"2024-07-26T00:33:20.350542-07:00", + "updated_at":"2024-07-26T00:33:20.350560-07:00" + }, + { + "id":"df1aca24-76cf-4b92-9f58-d03857efcb64", + "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.", + "user_id":"alex123", + "hash":"d2088c936e259f2f5d2d75543d31401c", + "metadata":"None", + "created_at":"2024-07-26T00:51:09.642275-07:00", + "updated_at":"2024-07-26T00:51:09.642295-07:00" + } +] +``` #### Get specific memory @@ -299,6 +389,18 @@ client.get("582bbe6d-506b-48c6-a4c6-5df3b1e63428") curl -X GET "https://api.mem0.ai/v1/memories/582bbe6d-506b-48c6-a4c6-5df3b1e63428" \ -H "Authorization: Token your-api-key" ``` + +```json Output +{ + "id":"06d8df63-7bd2-4fad-9acb-60871bcecee0", + "memory":"Planning a trip to Japan next month. Interested in vegetarian restaurants in Tokyo.", + "user_id":"alex123", + "hash":"d2088c936e259f2f5d2d75543d31401c", + "metadata":"None", + "created_at":"2024-07-26T00:25:16.566471-07:00", + "updated_at":"2024-07-26T00:25:16.566492-07:00" +} +``` ### 4.4 Memory History @@ -319,7 +421,6 @@ client.add(messages, user_id="alex") # Get history of how memory changed over time memory_id = "" history = client.history(memory_id) -print(history) ``` ```javascript JavaScript @@ -366,6 +467,32 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ curl -X GET "https://api.mem0.ai/v1/memories//history/" \ -H "Authorization: Token your-api-key" ``` + +```json Output +[ + { + "id":"d6306e85-eaa6-400c-8c2f-ab994a8c4d09", + "memory_id":"b163df0e-ebc8-4098-95df-3f70a733e198", + "input":[ + { + "role":"user", + "content":"I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.." + }, + { + "role":"user", + "content":"I turned vegetarian now." + } + ], + "old_memory":"None", + "new_memory":"Turned vegetarian.", + "user_id":"alex123456", + "event":"ADD", + "metadata":"None", + "created_at":"2024-07-26T01:02:41.737310-07:00", + "updated_at":"2024-07-26T01:02:41.726073-07:00" + } +] +``` ### 4.5 Delete Memory @@ -388,6 +515,10 @@ client.delete("memory-id-here") curl -X DELETE "https://api.mem0.ai/v1/memories/memory-id-here" \ -H "Authorization: Token your-api-key" ``` + +```json Output +{'message': 'Memory deleted successfully'} +``` Delete all memories of a user: @@ -408,6 +539,10 @@ client.deleteAll({ user_id: "alex" }) curl -X DELETE "https://api.mem0.ai/v1/memories/?user_id=alex" \ -H "Authorization: Token your-api-key" ``` + +```json Output +{'message': 'Memories deleted successfully!'} +``` Fun fact: You can also delete the memory using the `add()` method by passing a natural language command: @@ -433,6 +568,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \ "user_id": "alex" }' ``` + +```json Output +{'message': 'ok'} +``` If you have any questions, please feel free to reach out to us using one of the following methods: