AgentOS-MVP / context_memory.py
Tpayne101's picture
Create context_memory.py
540c668 verified
raw
history blame contribute delete
879 Bytes
import json, os
class ContextMemoryGraph:
def __init__(self, file_path="context_graph.json"):
self.file_path = file_path
self._init_graph()
def _init_graph(self):
if not os.path.exists(self.file_path):
with open(self.file_path, "w") as f:
json.dump({"context_links": {}}, f)
def link_context(self, agent_id, key, value):
with open(self.file_path, "r") as f:
graph = json.load(f)
if agent_id not in graph["context_links"]:
graph["context_links"][agent_id] = {}
graph["context_links"][agent_id][key] = value
with open(self.file_path, "w") as f:
json.dump(graph, f, indent=2)
def get_context(self, agent_id):
with open(self.file_path, "r") as f:
graph = json.load(f)
return graph["context_links"].get(agent_id, {})