-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8e8b0e
commit 80ec8ae
Showing
3 changed files
with
29 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import json | ||
|
||
from crewai_tools import tool | ||
from mem0 import Memory | ||
from mem0 import MemoryClient | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
load_dotenv() | ||
|
||
# Optionally configure mem0 to use any other store | ||
# https://docs.mem0.ai/components/vectordbs/config#config | ||
config = { | ||
"graph_store": { | ||
"provider": "neo4j", | ||
"config": { | ||
"url": os.getenv("NEO4J_URL"), | ||
"username": os.getenv("NEO4J_USERNAME", 'neo4j'), | ||
"password": os.getenv("NEO4J_PASSWORD"), | ||
} | ||
}, | ||
"version": "v1.1" | ||
} | ||
|
||
memory = Memory.from_config(config) | ||
# These functions can be extended by changing the user_id parameter | ||
# Memories are sorted by user_id | ||
|
||
# These functions can be extended by taking an optional user_id parameter | ||
# https://docs.mem0.ai/integrations/multion#add-memories-to-mem0 | ||
MEM0_API_KEY = os.getenv('MEM0_API_KEY') | ||
client = MemoryClient(api_key=MEM0_API_KEY) | ||
|
||
# These tools will only save information about the user | ||
# "Potato is a vegetable" is not a memory | ||
# "My favorite food is potatoes" IS a memory | ||
|
||
@tool("Write to Memory") | ||
def write_to_memory(data: str) -> str: | ||
"""Writes data to the memory store""" | ||
result = memory.add(data) | ||
return f"Memory added with ID: {result['id']}" | ||
def write_to_memory(user_message: str) -> str: | ||
""" | ||
Writes data to the memory store for a user. The tool will decide what | ||
specific information is important to store as memory. | ||
""" | ||
messages = [ | ||
{"role": "user", "content": user_message}, | ||
] | ||
result = client.add(messages, user_id='default') # configure user | ||
return json.dumps(result) | ||
|
||
|
||
@tool("Read from Memory") | ||
def read_from_memory(query: str) -> str: | ||
"""Reads memories based on a query.""" | ||
memories = memory.search(query=query) | ||
if memories["memories"]: | ||
return "\n".join([mem["data"] for mem in memories["memories"]]) | ||
""" | ||
Reads memories related to user based on a query. | ||
""" | ||
memories = client.search(query=query, user_id='default') | ||
if memories: | ||
return "\n".join([mem['memory'] for mem in memories]) | ||
else: | ||
return "No relevant memories found." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "mem0", | ||
"package": "poetry add mem0ai", | ||
"env": "NEO4J_URL=...\nNEO4J_USERNAME=...\nNEO4J_PASSWORD=...", | ||
"env": "MEM0_API_KEY=...", | ||
"tools": ["write_to_memory", "read_from_memory"], | ||
"cta": "Optionally: setup your graph db hosting at https://app.mem0.ai/login" | ||
"cta": "Create your mem0 API key at https://mem0.ai/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "agentstack" | ||
version = "0.1.7-rc2" | ||
version = "0.1.7-rc3" | ||
description = "The fastest way to build robust AI agents" | ||
authors = [ | ||
{ name="Braelyn Boynton", email="[email protected]" } | ||
|