multion.mdx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ---
  2. title: MultiOn
  3. ---
  4. Build personal browser agent remembers user preferences and automates web tasks. It integrates Mem0 for memory management with MultiOn for executing browser actions, enabling personalized and efficient web interactions.
  5. ## Overview
  6. 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.
  7. ## Setup and Configuration
  8. Install necessary libraries:
  9. ```bash
  10. pip install mem0ai multion
  11. ```
  12. First, we'll import the necessary libraries and set up our configurations.
  13. ```python
  14. import os
  15. from mem0 import Memory
  16. from multion.client import MultiOn
  17. # Configuration
  18. OPENAI_API_KEY = 'sk-xxx' # Replace with your actual OpenAI API key
  19. MULTION_API_KEY = 'your-multion-key' # Replace with your actual MultiOn API key
  20. USER_ID = "deshraj"
  21. # Set up OpenAI API key
  22. os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
  23. # Initialize Mem0 and MultiOn
  24. memory = Memory()
  25. multion = MultiOn(api_key=MULTION_API_KEY)
  26. ```
  27. ## Add memories to Mem0
  28. Next, we'll define our user data and add it to Mem0.
  29. ```python
  30. # Define user data
  31. USER_DATA = """
  32. About me
  33. - I'm Deshraj Yadav, Co-founder and CTO at Mem0, interested in AI and ML Infrastructure.
  34. - Previously, I was a Senior Autopilot Engineer at Tesla, leading the AI Platform for Autopilot.
  35. - I built EvalAI at Georgia Tech, an open-source platform for evaluating ML algorithms.
  36. - Outside of work, I enjoy playing cricket in two leagues in the San Francisco.
  37. """
  38. # Add user data to memory
  39. memory.add(USER_DATA, user_id=USER_ID)
  40. print("User data added to memory.")
  41. ```
  42. ## Retrieving Relevant Memories
  43. Now, we'll define our search command and retrieve relevant memories from Mem0.
  44. ```python
  45. # Define search command and retrieve relevant memories
  46. command = "Find papers on arxiv that I should read based on my interests."
  47. relevant_memories = memory.search(command, user_id=USER_ID, limit=3)
  48. relevant_memories_text = '\n'.join(mem['text'] for mem in relevant_memories)
  49. print(f"Relevant memories:")
  50. print(relevant_memories_text)
  51. ```
  52. ## Browsing arXiv
  53. Finally, we'll use MultiOn to browse arXiv based on our command and relevant memories.
  54. ```python
  55. # Create prompt and browse arXiv
  56. prompt = f"{command}\n My past memories: {relevant_memories_text}"
  57. browse_result = multion.browse(cmd=prompt, url="https://arxiv.org/")
  58. print(browse_result)
  59. ```
  60. ## Conclusion
  61. 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).