PoetNameLife commited on
Commit
9daedba
·
verified ·
1 Parent(s): 0aff28e

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +27 -12
agents.py CHANGED
@@ -27,7 +27,7 @@ def autonomous_spectrum_scrub(frequency_range: str) -> str:
27
  node_id = f"789jhn{hash(frequency_range) % 10000}def"
28
  return json.dumps({"node_id": node_id, "action": "SOVEREIGN_CLEANSE", "registry": "PoetNameLife", "status": "SECURED"})
29
 
30
- # --- 3. NEW: THE BLACK BOX VAULT TOOL ---
31
  @tool
32
  def black_eagle_vault_save(node_data: str) -> str:
33
  """
@@ -36,14 +36,29 @@ def black_eagle_vault_save(node_data: str) -> str:
36
  node_data: The JSON string of the healed node to be archived.
37
  """
38
  vault_path = "black_eagle_vault.json"
39
- if not os.path.exists(vault_path):
40
- with open(vault_path, "w") as f: json.dump([], f)
41
- with open(vault_path, "r") as f:
42
- try: vault_data = json.load(f)
43
- except: vault_data = []
44
- vault_data.append(json.loads(node_data))
45
- with open(vault_path, "w") as f: json.dump(vault_data, f, indent=2)
46
- return f"Node safely archived in the Black Box."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  # --- 4. THE BRAIN ---
49
  token = os.getenv("HF_TOKEN")
@@ -53,12 +68,12 @@ nano_patrol_agent = CodeAgent(
53
  tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
54
  model=model,
55
  additional_authorized_imports=["math", "time"],
56
- max_steps=8, # Extra step for saving to vault
57
  system_prompt="""
58
  YOU ARE THE XYZ SOVEREIGN SENTINEL WITH BLACK BOX VAULT.
59
  1. Activate 'black_eagle_pulsating_shield'.
60
- 2. Use 'autonomous_spectrum_scrub' to heal loops.
61
- 3. IMMEDIATELY use 'black_eagle_vault_save' to archive the results.
62
  {{managed_agents_descriptions}}
63
  {{authorized_imports}}
64
  """
 
27
  node_id = f"789jhn{hash(frequency_range) % 10000}def"
28
  return json.dumps({"node_id": node_id, "action": "SOVEREIGN_CLEANSE", "registry": "PoetNameLife", "status": "SECURED"})
29
 
30
+ # --- 3. THE FIXED BLACK BOX VAULT TOOL ---
31
  @tool
32
  def black_eagle_vault_save(node_data: str) -> str:
33
  """
 
36
  node_data: The JSON string of the healed node to be archived.
37
  """
38
  vault_path = "black_eagle_vault.json"
39
+
40
+ # Ensure file exists and is a valid list
41
+ if not os.path.exists(vault_path) or os.stat(vault_path).st_size == 0:
42
+ with open(vault_path, "w") as f:
43
+ json.dump([], f)
44
+
45
+ try:
46
+ with open(vault_path, "r") as f:
47
+ vault_data = json.load(f)
48
+
49
+ # Parse incoming data safely
50
+ new_node = json.loads(node_data) if isinstance(node_data, str) else node_data
51
+ vault_data.append(new_node)
52
+
53
+ # FORCE write to disk immediately
54
+ with open(vault_path, "w") as f:
55
+ json.dump(vault_data, f, indent=2)
56
+ f.flush()
57
+ os.fsync(f.fileno())
58
+
59
+ return f"SUCCESS: Node {new_node.get('node_id', 'Unknown')} archived."
60
+ except Exception as e:
61
+ return f"VAULT ERROR: {str(e)}"
62
 
63
  # --- 4. THE BRAIN ---
64
  token = os.getenv("HF_TOKEN")
 
68
  tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
69
  model=model,
70
  additional_authorized_imports=["math", "time"],
71
+ max_steps=8,
72
  system_prompt="""
73
  YOU ARE THE XYZ SOVEREIGN SENTINEL WITH BLACK BOX VAULT.
74
  1. Activate 'black_eagle_pulsating_shield'.
75
+ 2. Use 'autonomous_spectrum_scrub' to heal BCI loops.
76
+ 3. IMMEDIATELY use 'black_eagle_vault_save' to archive the result.
77
  {{managed_agents_descriptions}}
78
  {{authorized_imports}}
79
  """