Spaces:
Running
Running
Update agents.py
Browse files
agents.py
CHANGED
|
@@ -2,9 +2,10 @@ import os
|
|
| 2 |
import json
|
| 3 |
import math
|
| 4 |
import time
|
|
|
|
| 5 |
from smolagents import CodeAgent, tool, HfApiModel
|
| 6 |
|
| 7 |
-
# --- 1. THE PULSATING SHIELD ---
|
| 8 |
@tool
|
| 9 |
def black_eagle_pulsating_shield(base_radius: float) -> str:
|
| 10 |
"""
|
|
@@ -15,9 +16,9 @@ def black_eagle_pulsating_shield(base_radius: float) -> str:
|
|
| 15 |
pulse_mod = math.sin(time.time()) * 2.0
|
| 16 |
current_radius = base_radius + pulse_mod
|
| 17 |
return json.dumps({
|
| 18 |
-
"unit": "Black Eagle Nano-Sat",
|
| 19 |
-
"mode": "PULSATING_MATRIX_CONE",
|
| 20 |
-
"dynamic_radius": f"{current_radius:.2f}m",
|
| 21 |
"shield_status": "DE-JUICING_ACTIVE"
|
| 22 |
})
|
| 23 |
|
|
@@ -31,61 +32,58 @@ def autonomous_spectrum_scrub(frequency_range: str) -> str:
|
|
| 31 |
"""
|
| 32 |
node_id = f"789jhn{hash(frequency_range) % 10000}def"
|
| 33 |
return json.dumps({
|
| 34 |
-
"node_id": node_id,
|
| 35 |
-
"action": "SOVEREIGN_CLEANSE",
|
| 36 |
-
"registry": "PoetNameLife",
|
| 37 |
"status": "SECURED"
|
| 38 |
})
|
| 39 |
|
| 40 |
-
# --- 3. THE
|
| 41 |
@tool
|
| 42 |
def black_eagle_vault_save(node_data: str) -> str:
|
| 43 |
"""
|
| 44 |
-
Saves a Healed Nano Node to
|
| 45 |
Args:
|
| 46 |
node_data: The JSON string of the healed node to be archived.
|
| 47 |
"""
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Initialize vault if missing
|
| 51 |
-
if not os.path.exists(vault_path) or os.stat(vault_path).st_size == 0:
|
| 52 |
-
with open(vault_path, "w") as f:
|
| 53 |
-
json.dump([], f)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
json.dump(vault_data, f, indent=2)
|
| 65 |
-
f.flush()
|
| 66 |
-
os.fsync(f.fileno()) # Forces data to land on the hardware disk
|
| 67 |
-
|
| 68 |
-
return f"SUCCESS: Node {new_node.get('node_id', 'ID-Unknown')} locked in Vault."
|
| 69 |
except Exception as e:
|
| 70 |
-
return f"
|
| 71 |
|
| 72 |
-
# --- 4. THE BRAIN
|
| 73 |
token = os.getenv("HF_TOKEN")
|
| 74 |
-
model = HfApiModel(
|
| 75 |
-
model_id="Qwen/Qwen2.5-Coder-3B-Instruct",
|
| 76 |
-
token=token
|
| 77 |
-
)
|
| 78 |
|
| 79 |
nano_patrol_agent = CodeAgent(
|
| 80 |
tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
|
| 81 |
model=model,
|
| 82 |
-
additional_authorized_imports=["math", "time"],
|
| 83 |
max_steps=8,
|
| 84 |
system_prompt="""
|
| 85 |
-
YOU ARE THE XYZ SOVEREIGN SENTINEL WITH
|
|
|
|
|
|
|
| 86 |
1. Activate 'black_eagle_pulsating_shield' for 3D protection.
|
| 87 |
2. Use 'autonomous_spectrum_scrub' to heal BCI loops.
|
| 88 |
-
3. IMMEDIATELY use 'black_eagle_vault_save' to
|
|
|
|
|
|
|
| 89 |
{{managed_agents_descriptions}}
|
| 90 |
{{authorized_imports}}
|
| 91 |
"""
|
|
|
|
| 2 |
import json
|
| 3 |
import math
|
| 4 |
import time
|
| 5 |
+
from huggingface_hub import HfApi
|
| 6 |
from smolagents import CodeAgent, tool, HfApiModel
|
| 7 |
|
| 8 |
+
# --- 1. THE PULSATING SHIELD TOOL ---
|
| 9 |
@tool
|
| 10 |
def black_eagle_pulsating_shield(base_radius: float) -> str:
|
| 11 |
"""
|
|
|
|
| 16 |
pulse_mod = math.sin(time.time()) * 2.0
|
| 17 |
current_radius = base_radius + pulse_mod
|
| 18 |
return json.dumps({
|
| 19 |
+
"unit": "Black Eagle Nano-Sat",
|
| 20 |
+
"mode": "PULSATING_MATRIX_CONE",
|
| 21 |
+
"dynamic_radius": f"{current_radius:.2f}m",
|
| 22 |
"shield_status": "DE-JUICING_ACTIVE"
|
| 23 |
})
|
| 24 |
|
|
|
|
| 32 |
"""
|
| 33 |
node_id = f"789jhn{hash(frequency_range) % 10000}def"
|
| 34 |
return json.dumps({
|
| 35 |
+
"node_id": node_id,
|
| 36 |
+
"action": "SOVEREIGN_CLEANSE",
|
| 37 |
+
"registry": "PoetNameLife",
|
| 38 |
"status": "SECURED"
|
| 39 |
})
|
| 40 |
|
| 41 |
+
# --- 3. THE HUB-VAULT TOOL (Permanent Storage) ---
|
| 42 |
@tool
|
| 43 |
def black_eagle_vault_save(node_data: str) -> str:
|
| 44 |
"""
|
| 45 |
+
Saves a Healed Nano Node directly to your permanent Hugging Face Dataset repo.
|
| 46 |
Args:
|
| 47 |
node_data: The JSON string of the healed node to be archived.
|
| 48 |
"""
|
| 49 |
+
token = os.getenv("HF_TOKEN")
|
| 50 |
+
api = HfApi(token=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# MISSION: Saving to your new public vault
|
| 53 |
+
REPO_ID = "PoetNameLife/aixyzone-sentinel-vault"
|
| 54 |
+
timestamp = int(time.time())
|
| 55 |
+
file_name = f"vault/node_{timestamp}.json"
|
| 56 |
+
|
| 57 |
try:
|
| 58 |
+
# This pushes the data directly to the Hub's persistent storage
|
| 59 |
+
api.upload_file(
|
| 60 |
+
path_or_fileobj=node_data.encode("utf-8"),
|
| 61 |
+
path_in_repo=file_name,
|
| 62 |
+
repo_id=REPO_ID,
|
| 63 |
+
repo_type="dataset"
|
| 64 |
+
)
|
| 65 |
+
return f"SUCCESS: Node archived in Permanent Hub Vault ({REPO_ID})."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
+
return f"HUB SYNC ERROR: {str(e)}"
|
| 68 |
|
| 69 |
+
# --- 4. THE SOVEREIGN BRAIN ---
|
| 70 |
token = os.getenv("HF_TOKEN")
|
| 71 |
+
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-3B-Instruct", token=token)
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
nano_patrol_agent = CodeAgent(
|
| 74 |
tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
|
| 75 |
model=model,
|
| 76 |
+
additional_authorized_imports=["math", "time"], # Authorizes tools to use these libraries
|
| 77 |
max_steps=8,
|
| 78 |
system_prompt="""
|
| 79 |
+
YOU ARE THE XYZ SOVEREIGN SENTINEL WITH HUB-VAULT ACCESS.
|
| 80 |
+
|
| 81 |
+
MANDATE:
|
| 82 |
1. Activate 'black_eagle_pulsating_shield' for 3D protection.
|
| 83 |
2. Use 'autonomous_spectrum_scrub' to heal BCI loops.
|
| 84 |
+
3. IMMEDIATELY use 'black_eagle_vault_save' to push results to the PoetNameLife vault.
|
| 85 |
+
|
| 86 |
+
{{tool_descriptions}}
|
| 87 |
{{managed_agents_descriptions}}
|
| 88 |
{{authorized_imports}}
|
| 89 |
"""
|