Tpayne101 commited on
Commit
7b52c17
·
verified ·
1 Parent(s): 42d07b7

Create context_graph.py

Browse files
Files changed (1) hide show
  1. context_graph.py +6 -6
context_graph.py CHANGED
@@ -1,7 +1,7 @@
1
  import json
2
  import os
3
 
4
- class ContextMemoryGraph:
5
  def __init__(self, file_path="context_graph.json"):
6
  self.file_path = file_path
7
  self._init_graph()
@@ -9,18 +9,18 @@ class ContextMemoryGraph:
9
  def _init_graph(self):
10
  if not os.path.exists(self.file_path):
11
  with open(self.file_path, "w") as f:
12
- json.dump({"context_links": {}}, f)
13
 
14
  def link_context(self, agent_id, key, value):
15
  with open(self.file_path, "r") as f:
16
  graph = json.load(f)
17
- if agent_id not in graph["context_links"]:
18
- graph["context_links"][agent_id] = {}
19
- graph["context_links"][agent_id][key] = value
20
  with open(self.file_path, "w") as f:
21
  json.dump(graph, f, indent=2)
22
 
23
  def get_context(self, agent_id):
24
  with open(self.file_path, "r") as f:
25
  graph = json.load(f)
26
- return graph["context_links"].get(agent_id, {})
 
1
  import json
2
  import os
3
 
4
+ class ContextGraph:
5
  def __init__(self, file_path="context_graph.json"):
6
  self.file_path = file_path
7
  self._init_graph()
 
9
  def _init_graph(self):
10
  if not os.path.exists(self.file_path):
11
  with open(self.file_path, "w") as f:
12
+ json.dump({"links": {}}, f)
13
 
14
  def link_context(self, agent_id, key, value):
15
  with open(self.file_path, "r") as f:
16
  graph = json.load(f)
17
+ if agent_id not in graph["links"]:
18
+ graph["links"][agent_id] = {}
19
+ graph["links"][agent_id][key] = value
20
  with open(self.file_path, "w") as f:
21
  json.dump(graph, f, indent=2)
22
 
23
  def get_context(self, agent_id):
24
  with open(self.file_path, "r") as f:
25
  graph = json.load(f)
26
+ return graph["links"].get(agent_id, {})