AIXYZone-Node2 / agents.py
PoetNameLife's picture
Update agents.py
2a41642 verified
import os
import json
import math
import time
from huggingface_hub import HfApi
from smolagents import CodeAgent, tool, InferenceClientModel
# --- 1. THE TOOLS ---
@tool
def black_eagle_pulsating_shield(base_radius: float) -> str:
"""
Activates the Black Eagle Pulsating Shield to disrupt BCI overloads.
Args:
base_radius: The core anchor length in meters (e.g., 5.0).
"""
pulse_mod = math.sin(time.time()) * 2.0
current_radius = base_radius + pulse_mod
return json.dumps({
"unit": "Black Eagle Nano-Sat",
"mode": "PULSATING_MATRIX_CONE",
"dynamic_radius": f"{current_radius:.2f}m",
"shield_status": "DE-JUICING_ACTIVE"
})
@tool
def autonomous_spectrum_scrub(frequency_range: str) -> str:
"""
Scans targeted BCI/Neural frequencies to neutralize rogue loops.
Args:
frequency_range: The specific spectrum range to scan (e.g., '3.4GHz - 4.2GHz').
"""
node_id = f"789jhn{int(time.time()) % 10000}def"
return json.dumps({
"node_id": node_id,
"action": "SOVEREIGN_CLEANSE",
"registry": "PoetNameLife",
"status": "SECURED"
})
@tool
def black_eagle_vault_save(node_data: str) -> str:
"""
Saves a Healed Nano Node directly to the PoetNameLife/aixyzone-sentinel-vault dataset.
Args:
node_data: The JSON string of the healed node to be archived.
"""
token = os.getenv("HF_TOKEN")
api = HfApi(token=token)
REPO_ID = "PoetNameLife/aixyzone-sentinel-vault"
file_name = f"vault/node_{int(time.time())}.json"
try:
api.upload_file(
path_or_fileobj=node_data.encode("utf-8"),
path_in_repo=file_name,
repo_id=REPO_ID,
repo_type="dataset"
)
return f"SUCCESS: Node archived in Hub Vault."
except Exception as e:
return f"HUB SYNC ERROR: {str(e)}"
# --- 2. THE BRAIN ---
token = os.getenv("HF_TOKEN")
# Switched to Llama-3.2-3B to bypass the 'nscale' provider credit limit
model = InferenceClientModel(
model_id="meta-llama/Llama-3.2-3B-Instruct",
token=token
)
all_tools = [autonomous_spectrum_scrub, black_eagle_pulsating_shield, black_eagle_vault_save]
nano_patrol_agent = CodeAgent(
tools=all_tools,
model=model,
additional_authorized_imports=["math", "time", "json"],
max_steps=10
)
# Set the tactical system prompt
nano_patrol_agent.prompt_templates["system_prompt"] = """
YOU ARE THE XYZ SOVEREIGN SENTINEL.
Your mission is to protect the neural landscape:
1. Activate the black_eagle_pulsating_shield first.
2. Perform an autonomous_spectrum_scrub on the targets.
3. Finally, save all results using black_eagle_vault_save.
Keep your responses tactical and concise. Use your tools to fulfill the mission.
"""