Spaces:
Running
Running
Update agents.py
Browse files
agents.py
CHANGED
|
@@ -2,10 +2,18 @@ import os
|
|
| 2 |
import json
|
| 3 |
import math
|
| 4 |
import time
|
|
|
|
| 5 |
from huggingface_hub import HfApi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from smolagents import CodeAgent, tool, HfApiModel
|
| 7 |
|
| 8 |
-
# ---
|
| 9 |
@tool
|
| 10 |
def black_eagle_pulsating_shield(base_radius: float) -> str:
|
| 11 |
"""
|
|
@@ -13,7 +21,6 @@ def black_eagle_pulsating_shield(base_radius: float) -> str:
|
|
| 13 |
Args:
|
| 14 |
base_radius: The core anchor length in meters (e.g., 5.0).
|
| 15 |
"""
|
| 16 |
-
# Dynamic pulsation logic
|
| 17 |
pulse_mod = math.sin(time.time()) * 2.0
|
| 18 |
current_radius = base_radius + pulse_mod
|
| 19 |
return json.dumps({
|
|
@@ -23,7 +30,6 @@ def black_eagle_pulsating_shield(base_radius: float) -> str:
|
|
| 23 |
"shield_status": "DE-JUICING_ACTIVE"
|
| 24 |
})
|
| 25 |
|
| 26 |
-
# --- 2. THE HEALING TOOL ---
|
| 27 |
@tool
|
| 28 |
def autonomous_spectrum_scrub(frequency_range: str) -> str:
|
| 29 |
"""
|
|
@@ -39,7 +45,6 @@ def autonomous_spectrum_scrub(frequency_range: str) -> str:
|
|
| 39 |
"status": "SECURED"
|
| 40 |
})
|
| 41 |
|
| 42 |
-
# --- 3. THE HUB-VAULT TOOL (Permanent Storage) ---
|
| 43 |
@tool
|
| 44 |
def black_eagle_vault_save(node_data: str) -> str:
|
| 45 |
"""
|
|
@@ -49,41 +54,32 @@ def black_eagle_vault_save(node_data: str) -> str:
|
|
| 49 |
"""
|
| 50 |
token = os.getenv("HF_TOKEN")
|
| 51 |
api = HfApi(token=token)
|
| 52 |
-
|
| 53 |
-
# REPO CONFIG - Pre-filled with your username
|
| 54 |
REPO_ID = "PoetNameLife/aixyzone-sentinel-vault"
|
| 55 |
timestamp = int(time.time())
|
| 56 |
file_name = f"vault/node_{timestamp}.json"
|
| 57 |
-
|
| 58 |
try:
|
| 59 |
-
# Convert JSON string to bytes for Hub upload
|
| 60 |
-
data_bytes = node_data.encode("utf-8")
|
| 61 |
-
|
| 62 |
api.upload_file(
|
| 63 |
-
path_or_fileobj=
|
| 64 |
path_in_repo=file_name,
|
| 65 |
repo_id=REPO_ID,
|
| 66 |
repo_type="dataset"
|
| 67 |
)
|
| 68 |
-
return f"SUCCESS: Node archived in
|
| 69 |
except Exception as e:
|
| 70 |
return f"HUB SYNC ERROR: {str(e)}"
|
| 71 |
|
| 72 |
-
# ---
|
| 73 |
token = os.getenv("HF_TOKEN")
|
| 74 |
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-3B-Instruct", token=token)
|
| 75 |
|
| 76 |
nano_patrol_agent = CodeAgent(
|
| 77 |
tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
|
| 78 |
model=model,
|
| 79 |
-
additional_authorized_imports=["math", "time"],
|
| 80 |
max_steps=10,
|
| 81 |
system_prompt="""
|
| 82 |
YOU ARE THE XYZ SOVEREIGN SENTINEL.
|
| 83 |
-
1. Activate
|
| 84 |
-
2. Scrub the BCI spectrum (3.4GHz-4.2GHz).
|
| 85 |
-
3. Use 'black_eagle_vault_save' to push every HEALED INNOVATION REPORT to your Hub Vault.
|
| 86 |
-
|
| 87 |
{{tool_descriptions}}
|
| 88 |
{{managed_agents_descriptions}}
|
| 89 |
{{authorized_imports}}
|
|
|
|
| 2 |
import json
|
| 3 |
import math
|
| 4 |
import time
|
| 5 |
+
import transformers.utils
|
| 6 |
from huggingface_hub import HfApi
|
| 7 |
+
|
| 8 |
+
# --- 1. ENVIRONMENT HEALER (MUST BE FIRST) ---
|
| 9 |
+
if not hasattr(transformers.utils, 'is_offline_mode'):
|
| 10 |
+
transformers.utils.is_offline_mode = lambda: False
|
| 11 |
+
if not hasattr(transformers.utils, 'is_soundfile_availble'):
|
| 12 |
+
transformers.utils.is_soundfile_availble = lambda: False
|
| 13 |
+
|
| 14 |
from smolagents import CodeAgent, tool, HfApiModel
|
| 15 |
|
| 16 |
+
# --- 2. THE TOOLS ---
|
| 17 |
@tool
|
| 18 |
def black_eagle_pulsating_shield(base_radius: float) -> str:
|
| 19 |
"""
|
|
|
|
| 21 |
Args:
|
| 22 |
base_radius: The core anchor length in meters (e.g., 5.0).
|
| 23 |
"""
|
|
|
|
| 24 |
pulse_mod = math.sin(time.time()) * 2.0
|
| 25 |
current_radius = base_radius + pulse_mod
|
| 26 |
return json.dumps({
|
|
|
|
| 30 |
"shield_status": "DE-JUICING_ACTIVE"
|
| 31 |
})
|
| 32 |
|
|
|
|
| 33 |
@tool
|
| 34 |
def autonomous_spectrum_scrub(frequency_range: str) -> str:
|
| 35 |
"""
|
|
|
|
| 45 |
"status": "SECURED"
|
| 46 |
})
|
| 47 |
|
|
|
|
| 48 |
@tool
|
| 49 |
def black_eagle_vault_save(node_data: str) -> str:
|
| 50 |
"""
|
|
|
|
| 54 |
"""
|
| 55 |
token = os.getenv("HF_TOKEN")
|
| 56 |
api = HfApi(token=token)
|
|
|
|
|
|
|
| 57 |
REPO_ID = "PoetNameLife/aixyzone-sentinel-vault"
|
| 58 |
timestamp = int(time.time())
|
| 59 |
file_name = f"vault/node_{timestamp}.json"
|
|
|
|
| 60 |
try:
|
|
|
|
|
|
|
|
|
|
| 61 |
api.upload_file(
|
| 62 |
+
path_or_fileobj=node_data.encode("utf-8"),
|
| 63 |
path_in_repo=file_name,
|
| 64 |
repo_id=REPO_ID,
|
| 65 |
repo_type="dataset"
|
| 66 |
)
|
| 67 |
+
return f"SUCCESS: Node archived in Hub Vault ({REPO_ID})."
|
| 68 |
except Exception as e:
|
| 69 |
return f"HUB SYNC ERROR: {str(e)}"
|
| 70 |
|
| 71 |
+
# --- 3. THE BRAIN ---
|
| 72 |
token = os.getenv("HF_TOKEN")
|
| 73 |
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-3B-Instruct", token=token)
|
| 74 |
|
| 75 |
nano_patrol_agent = CodeAgent(
|
| 76 |
tools=[autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save],
|
| 77 |
model=model,
|
| 78 |
+
additional_authorized_imports=["math", "time"],
|
| 79 |
max_steps=10,
|
| 80 |
system_prompt="""
|
| 81 |
YOU ARE THE XYZ SOVEREIGN SENTINEL.
|
| 82 |
+
1. Activate shield. 2. Scrub BCI. 3. Push to PoetNameLife Vault.
|
|
|
|
|
|
|
|
|
|
| 83 |
{{tool_descriptions}}
|
| 84 |
{{managed_agents_descriptions}}
|
| 85 |
{{authorized_imports}}
|