Skip to content

Commit 80ec8ae

Browse files
committed
mem0 upgrade
1 parent f8e8b0e commit 80ec8ae

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1+
import json
2+
13
from crewai_tools import tool
2-
from mem0 import Memory
4+
from mem0 import MemoryClient
35
from dotenv import load_dotenv
46
import os
57

68
load_dotenv()
79

8-
# Optionally configure mem0 to use any other store
9-
# https://docs.mem0.ai/components/vectordbs/config#config
10-
config = {
11-
"graph_store": {
12-
"provider": "neo4j",
13-
"config": {
14-
"url": os.getenv("NEO4J_URL"),
15-
"username": os.getenv("NEO4J_USERNAME", 'neo4j'),
16-
"password": os.getenv("NEO4J_PASSWORD"),
17-
}
18-
},
19-
"version": "v1.1"
20-
}
21-
22-
memory = Memory.from_config(config)
10+
# These functions can be extended by changing the user_id parameter
11+
# Memories are sorted by user_id
2312

24-
# These functions can be extended by taking an optional user_id parameter
25-
# https://docs.mem0.ai/integrations/multion#add-memories-to-mem0
13+
MEM0_API_KEY = os.getenv('MEM0_API_KEY')
14+
client = MemoryClient(api_key=MEM0_API_KEY)
2615

16+
# These tools will only save information about the user
17+
# "Potato is a vegetable" is not a memory
18+
# "My favorite food is potatoes" IS a memory
2719

2820
@tool("Write to Memory")
29-
def write_to_memory(data: str) -> str:
30-
"""Writes data to the memory store"""
31-
result = memory.add(data)
32-
return f"Memory added with ID: {result['id']}"
21+
def write_to_memory(user_message: str) -> str:
22+
"""
23+
Writes data to the memory store for a user. The tool will decide what
24+
specific information is important to store as memory.
25+
"""
26+
messages = [
27+
{"role": "user", "content": user_message},
28+
]
29+
result = client.add(messages, user_id='default') # configure user
30+
return json.dumps(result)
3331

3432

3533
@tool("Read from Memory")
3634
def read_from_memory(query: str) -> str:
37-
"""Reads memories based on a query."""
38-
memories = memory.search(query=query)
39-
if memories["memories"]:
40-
return "\n".join([mem["data"] for mem in memories["memories"]])
35+
"""
36+
Reads memories related to user based on a query.
37+
"""
38+
memories = client.search(query=query, user_id='default')
39+
if memories:
40+
return "\n".join([mem['memory'] for mem in memories])
4141
else:
4242
return "No relevant memories found."

agentstack/tools/mem0.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mem0",
33
"package": "poetry add mem0ai",
4-
"env": "NEO4J_URL=...\nNEO4J_USERNAME=...\nNEO4J_PASSWORD=...",
4+
"env": "MEM0_API_KEY=...",
55
"tools": ["write_to_memory", "read_from_memory"],
6-
"cta": "Optionally: setup your graph db hosting at https://app.mem0.ai/login"
6+
"cta": "Create your mem0 API key at https://mem0.ai/"
77
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "agentstack"
7-
version = "0.1.7-rc2"
7+
version = "0.1.7-rc3"
88
description = "The fastest way to build robust AI agents"
99
authors = [
1010
{ name="Braelyn Boynton", email="bboynton97@gmail.com" }

0 commit comments

Comments
 (0)