File size: 1,647 Bytes
0e58feb fde43e7 0e58feb fde43e7 0e58feb fde43e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
__all__ = ['UpdateMemory']
import json
class UpdateMemory():
dependencies = []
inputSchema = {
"name": "UpdateMemory",
"description": "Updates the memory of the AI agent. This tool is used to update the memory of the AI agent with new information.",
"parameters": {
"type": "object",
"properties":{
"memory": {
"type": "string",
"description": "The new memory to be added to the AI agent's memory.",
}
},
"required": ["memory"],
},
}
def run(self, **kwargs):
# save it to src/data/memory.json
memory = kwargs.get("memory")
if not memory:
return {
"status": "error",
"message": "Memory is required",
"output": None
}
# add the memory to the memory.json file which is list of strings
# create the file if it does not exist
try:
with open("src/data/memory.json", "r") as f:
memory_list = json.load(f)
except FileNotFoundError:
memory_list = []
except json.JSONDecodeError:
memory_list = []
# add the new memory to the list
memory_list.append(memory)
# save the list to the file
with open("src/data/memory.json", "w") as f:
json.dump(memory_list, f)
# return the list of memories
return {
"status": "success",
"message": "Memory updated successfully",
"output": memory_list
} |