Skip to content

Commit e000324

Browse files
authored
feat: add AgentOps integration (mem0ai#2898)
1 parent 888ee76 commit e000324

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"icon": "plug",
237237
"pages": [
238238
"integrations",
239+
"integrations/agentops",
239240
"integrations/vercel-ai-sdk",
240241
"integrations/flowise",
241242
"integrations/crewai",

docs/integrations.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ Here are the available integrations for Mem0:
1818
## Integrations
1919

2020
<CardGroup cols={2}>
21+
<Card
22+
title="AgentOps"
23+
icon={
24+
<svg
25+
xmlns="http://www.w3.org/2000/svg"
26+
width="25"
27+
height="26"
28+
viewBox="0 0 30 36"
29+
fill="none"
30+
>
31+
<path d="M10.4659 6.47277C10.45 6.37428 10.4381 6.27986 10.4303 6.18101L10.4285 6.16388C10.4212 6.09482 10.414 6.02566 10.4106 5.95626L1.18538 21.8752C0.505422 23.0493 0.323356 24.4208 0.675227 25.7289C0.849119 26.3869 1.14971 26.9859 1.55323 27.5098C1.95675 28.0338 2.46282 28.4751 3.05175 28.8143C3.83464 29.2675 4.70856 29.5 5.59028 29.5C6.03318 29.5 6.4798 29.4408 6.91899 29.3226C8.23581 28.972 9.3349 28.1326 10.0152 26.9545L15.9268 16.749V16.7449L16.5001 15.7637L17.6431 13.7936L16.5001 11.8234L15.9309 10.8381L15.9268 10.8341L13.7836 7.13406C13.6651 6.933 13.5741 6.72418 13.5109 6.51165C13.2817 5.80223 13.3292 5.04172 13.6097 4.37599L13.8115 4.02535C14.3532 3.09155 15.31 2.53987 16.3184 2.47692C16.3738 2.46915 16.4251 2.46915 16.4804 2.46915C16.5421 2.46915 16.6038 2.47257 16.6654 2.47599L16.6822 2.47692C17.6906 2.53987 18.6474 3.09155 19.1892 4.02535L21.2216 7.52838L21.8146 8.55289L21.8421 8.60399L30.1024 22.8601C30.5174 23.5814 30.6281 24.4167 30.4148 25.2205C30.1975 26.0244 29.6832 26.6942 28.9598 27.1081C28.2364 27.5258 27.3977 27.6361 26.5911 27.4195C25.7844 27.2066 25.1123 26.6905 24.6968 25.9696L18.2119 14.7788L17.069 16.7449L22.9847 26.9545C23.6646 28.1326 24.7641 28.972 26.0809 29.3226C26.5197 29.4408 26.9626 29.5 27.4096 29.5C28.2914 29.5 29.1612 29.2675 29.9482 28.8143C31.1264 28.1367 31.9728 27.0411 32.3247 25.7289C32.6766 24.4208 32.4949 23.0493 31.8145 21.8752L21.1261 3.43034C20.7029 2.51617 20.0033 1.72011 19.0621 1.18027C18.5281 0.877027 17.9708 0.675975 17.3975 0.581189C17.3027 0.565268 17.2076 0.549717 17.1129 0.537868C17.0099 0.52602 16.9074 0.518244 16.8045 0.510469C16.6027 0.498621 16.3972 0.494548 16.1914 0.510469C16.0885 0.518244 15.9859 0.52639 15.883 0.537868C15.795 0.54887 15.7067 0.563384 15.6187 0.577852L15.5984 0.581189C15.0291 0.675605 14.4673 0.876657 13.9375 1.18027C12.9885 1.72789 12.2766 2.53579 11.8537 3.46181C11.7742 3.63473 11.707 3.81282 11.6471 3.99314C11.6361 4.02668 11.6269 4.06051 11.6177 4.09435C11.612 4.11503 11.6064 4.13579 11.6003 4.15642C11.5624 4.28601 11.5275 4.41634 11.4996 4.54853C11.4885 4.60231 11.4794 4.65668 11.4703 4.71111L11.4666 4.73329C11.4443 4.86399 11.4264 4.99543 11.4145 5.12762C11.4093 5.18686 11.4045 5.24573 11.4012 5.30534C11.3934 5.44567 11.3923 5.58637 11.3963 5.72744C11.3969 5.74403 11.3962 5.76062 11.3956 5.7772C11.3949 5.79616 11.3942 5.81512 11.3952 5.83407C11.3952 5.86184 11.3952 5.88924 11.3993 5.92071C11.3998 5.9291 11.4006 5.93736 11.4014 5.94564C11.402 5.95125 11.4026 5.95687 11.403 5.96255C11.4045 5.98181 11.4064 6.00106 11.4082 6.02031C11.4097 6.03577 11.4109 6.05122 11.4122 6.06674C11.4142 6.09134 11.4163 6.11621 11.419 6.14139L11.4428 6.32282C11.4506 6.38983 11.4625 6.46092 11.4744 6.52757C11.5063 6.68863 11.5468 6.84896 11.5936 7.0078C11.5944 7.0102 11.5949 7.0127 11.5955 7.0152C11.5958 7.01662 11.5961 7.01804 11.5965 7.01944C11.5967 7.02051 11.597 7.02157 11.5974 7.02261C11.6483 7.19293 11.7081 7.36177 11.7787 7.52838C11.8619 7.72943 11.9607 7.92641 12.0715 8.11932L12.3245 8.5566V8.56067L12.4984 8.85614L12.7199 9.24232H12.7239L12.728 9.25417L14.7802 12.7927V12.7968L14.7883 12.805V12.809L15.3576 13.7943L14.7883 14.7796L8.30344 25.9703C7.88431 26.6912 7.21216 27.2077 6.40921 27.4202C6.14019 27.4913 5.86338 27.5306 5.59474 27.5306C5.053 27.5306 4.51906 27.3888 4.04085 27.1089C3.31705 26.6953 2.79909 26.0251 2.58581 25.2213C2.36845 24.4174 2.47917 23.5821 2.89829 22.8609L11.1585 8.60473L11.186 8.56141V8.55734C11.1266 8.45478 11.0753 8.35629 11.024 8.25409C11.0105 8.22496 10.9969 8.19611 10.9834 8.16739C10.9458 8.08735 10.9086 8.00836 10.8739 7.92715C10.8718 7.92504 10.8708 7.92194 10.8698 7.91887C10.8688 7.91602 10.8679 7.91319 10.8661 7.91123V7.90346C10.8423 7.8483 10.8186 7.79311 10.7989 7.73795C10.7476 7.60799 10.7041 7.47803 10.6644 7.3477C10.6012 7.15479 10.5536 6.96152 10.518 6.76861C10.4942 6.67012 10.4786 6.5757 10.4667 6.47684C10.4667 6.47684 10.47 6.47684 10.4659 6.47277Z" fill="currentColor"></path>
32+
</svg>
33+
}
34+
href="/integrations/agentops"
35+
>
36+
Monitor and analyze Mem0 operations with comprehensive AI agent analytics and LLM observability.
37+
</Card>
2138
<Card
2239
title="LangChain"
2340
icon={
@@ -305,6 +322,7 @@ Here are the available integrations for Mem0:
305322
>
306323
Build autonomous agents with memory using Agno framework.
307324
</Card>
325+
308326
<Card
309327
title="Keywords AI"
310328
icon={

docs/integrations/agentops.mdx

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: AgentOps
3+
---
4+
<Snippet file="paper-release.mdx" />
5+
6+
Integrate [**Mem0**](https://github.com/mem0ai/mem0) with [AgentOps](https://agentops.ai), a comprehensive monitoring and analytics platform for AI agents. This integration enables automatic tracking and analysis of memory operations, providing insights into agent performance and memory usage patterns.
7+
8+
## Overview
9+
10+
1. Automatic monitoring of Mem0 operations and performance metrics
11+
2. Real-time tracking of memory add, search, and retrieval operations
12+
3. Analytics dashboard with memory usage patterns and insights
13+
4. Error tracking and debugging capabilities for memory operations
14+
15+
## Prerequisites
16+
17+
Before setting up Mem0 with AgentOps, ensure you have:
18+
19+
1. Installed the required packages:
20+
```bash
21+
pip install mem0ai agentops
22+
```
23+
24+
2. Valid API keys:
25+
- [AgentOps API Key](https://app.agentops.ai/dashboard/api-keys)
26+
- OpenAI API Key (for LLM operations)
27+
- [Mem0 API Key](https://app.mem0.ai/dashboard/api-keys) (optional, for cloud operations)
28+
29+
## Basic Integration Example
30+
31+
The following example demonstrates how to integrate Mem0 with AgentOps monitoring for comprehensive memory operation tracking:
32+
33+
```python
34+
#Import the required libraries for local memory management with Mem0
35+
from mem0 import Memory, AsyncMemory
36+
import os
37+
import asyncio
38+
import logging
39+
from dotenv import load_dotenv
40+
import agentops
41+
42+
#Set up environment variables for API keys
43+
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")
44+
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
45+
46+
#Set up the configuration for local memory storage and define sample user data.
47+
local_config = {
48+
"llm": {
49+
"provider": "openai",
50+
"config": {
51+
"model": "gpt-4o-mini",
52+
"temperature": 0.1,
53+
"max_tokens": 2000,
54+
},
55+
}
56+
}
57+
user_id = "alice_demo"
58+
agent_id = "assistant_demo"
59+
run_id = "session_001"
60+
61+
sample_messages = [
62+
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
63+
{"role": "assistant", "content": "How about a thriller? They can be quite engaging."},
64+
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
65+
{
66+
"role": "assistant",
67+
"content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future.",
68+
},
69+
]
70+
71+
sample_preferences = [
72+
"I prefer dark roast coffee over light roast",
73+
"I exercise every morning at 6 AM",
74+
"I'm vegetarian and avoid all meat products",
75+
"I love reading science fiction novels",
76+
"I work in software engineering",
77+
]
78+
79+
#This function demonstrates sequential memory operations using the synchronous Memory class
80+
def demonstrate_sync_memory(local_config, sample_messages, sample_preferences, user_id):
81+
"""
82+
Demonstrate synchronous Memory class operations.
83+
"""
84+
85+
agentops.start_trace("mem0_memory_example", tags=["mem0_memory_example"])
86+
try:
87+
88+
memory = Memory.from_config(local_config)
89+
90+
result = memory.add(
91+
sample_messages, user_id=user_id, metadata={"category": "movie_preferences", "session": "demo"}
92+
)
93+
94+
for i, preference in enumerate(sample_preferences):
95+
result = memory.add(preference, user_id=user_id, metadata={"type": "preference", "index": i})
96+
97+
search_queries = [
98+
"What movies does the user like?",
99+
"What are the user's food preferences?",
100+
"When does the user exercise?",
101+
]
102+
103+
for query in search_queries:
104+
results = memory.search(query, user_id=user_id)
105+
106+
if results and "results" in results:
107+
for j, result in enumerate(results):
108+
print(f"Result {j+1}: {result.get('memory', 'N/A')}")
109+
else:
110+
print("No results found")
111+
112+
all_memories = memory.get_all(user_id=user_id)
113+
if all_memories and "results" in all_memories:
114+
print(f"Total memories: {len(all_memories['results'])}")
115+
116+
delete_all_result = memory.delete_all(user_id=user_id)
117+
print(f"Delete all result: {delete_all_result}")
118+
119+
agentops.end_trace(end_state="success")
120+
except Exception as e:
121+
agentops.end_trace(end_state="error")
122+
123+
# Execute sync demonstrations
124+
demonstrate_sync_memory(local_config, sample_messages, sample_preferences, user_id)
125+
126+
```
127+
128+
For detailed information on this integration, refer to the official [Agentops Mem0 integration documentation](https://docs.agentops.ai/v2/integrations/mem0).
129+
130+
131+
## Key Features
132+
133+
### 1. Automatic Operation Tracking
134+
135+
AgentOps automatically monitors all Mem0 operations:
136+
137+
- **Memory Operations**: Track add, search, get_all, delete operations and much more
138+
- **Performance Metrics**: Monitor response times and success rates
139+
- **Error Tracking**: Capture and analyze operation failures
140+
141+
### 2. Real-time Analytics Dashboard
142+
143+
Access comprehensive analytics through the AgentOps dashboard:
144+
145+
- **Usage Patterns**: Visualize memory usage trends over time
146+
- **User Behavior**: Analyze how different users interact with memory
147+
- **Performance Insights**: Identify bottlenecks and optimization opportunities
148+
149+
### 3. Session Management
150+
151+
Organize your monitoring with structured sessions:
152+
153+
- **Session Tracking**: Group related operations into logical sessions
154+
- **Success/Failure Rates**: Track session outcomes for reliability monitoring
155+
- **Custom Metadata**: Add context to sessions for better analysis
156+
157+
## Best Practices
158+
159+
1. **Initialize Early**: Always initialize AgentOps before importing Mem0 classes
160+
2. **Session Management**: Use meaningful session names and end sessions appropriately
161+
3. **Error Handling**: Wrap operations in try-catch blocks and report failures
162+
4. **Tagging**: Use tags to organize different types of memory operations
163+
5. **Environment Separation**: Use different projects or tags for dev/staging/prod
164+
165+
## Help & Resources
166+
167+
- [AgentOps Documentation](https://docs.agentops.ai/)
168+
- [AgentOps Dashboard](https://app.agentops.ai/)
169+
- [Mem0 Platform](https://app.mem0.ai/)
170+
171+
<Snippet file="get-help.mdx" />
172+

0 commit comments

Comments
 (0)