Tpayne101 commited on
Commit
f062f85
·
verified ·
1 Parent(s): 8f143f0

Create 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, {})

Browse files
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, {}) ADDED
File without changes