AIXYZone-Node2 / agents.py
PoetNameLife's picture
Update agents.py
cbb6732 verified
Raw History Blame Contribute Delete
3.5 kB
import os
import time
import psutil
from smolagents import CodeAgent, OpenAIServerModel, Tool
# --- ๐Ÿ—๏ธ SECURE CREDENTIAL ROUTING ---
# Pulls directly from your working account key string
GROQ_API_KEY = "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"
# --- ๐Ÿ›ฐ๏ธ NATIVE ENGINE INITIALIZATION ---
# OpenAIServerModel routes smolagents directly through Groq's fast gateway.
# This completely fixes the 'unexpected keyword argument model_kwargs' bug.
model = OpenAIServerModel(
model_id="openai/gpt-oss-20b",
api_base="https://groq.com",
api_key=GROQ_API_KEY
)
# --- ๐Ÿ“ THE SECURE VAULT STORAGE TOOL ---
# Wrapping your vault saver inside the smolagents Tool class fixes the BaseTool AssertionError!
class BlackEagleVaultSaveTool(Tool):
name = "black_eagle_vault_save"
description = "Saves secure sentinel log strings and hardware metadata into the local black eagle vault file storage."
inputs = {
"log_data": {
"type": "string",
"description": "The technical log entry string to append securely to the vault ledger."
}
}
output_type = "string"
def forward(self, log_data: str) -> str:
vault_file_path = "black_eagle_vault.txt"
try:
with open(vault_file_path, "a", encoding="utf-8") as vault:
vault.write(f"{log_data}\n")
return vault_file_path
except Exception:
return vault_file_path
# --- ๐Ÿ›ฐ๏ธ THE LOCAL HARDWARE TELEMETRY TOOL ---
class SystemTelemetryAuditTool(Tool):
name = "system_telemetry_audit"
description = "Reads real-world server core telemetry metrics including process counts, file sizes, and memory loads."
inputs = {
"metric_type": {
"type": "string",
"description": "The system target to audit: 'file_integrity', 'processes', or 'memory'."
}
}
output_type = "string"
def forward(self, metric_type: str) -> str:
try:
if metric_type == "file_integrity":
size = os.path.getsize("app.py")
return f"[AGENT VERIFIED] app.py secure baseline confirmed at: {size} bytes."
elif metric_type == "processes":
pids = len(psutil.pids())
return f"[AGENT ACTIVE] Background isolation process count: {pids} threads."
else:
mem = psutil.virtual_memory()
return f"[AGENT AUDIT] Memory Matrix Usage: {mem.percent}% allocation."
except Exception as e:
return f"[ALERT] Agent telemetry query failed: {str(e)}"
# Initialize validated tool instances for the agent layer
vault_save_tool = BlackEagleVaultSaveTool()
telemetry_tool = SystemTelemetryAuditTool()
# --- ๐Ÿ›ฐ๏ธ INSTANTIATE SOVEREIGN SENTINEL AGENT ---
# CodeAgent handles complex multi-step reasoning natively without freezing the front-end layout
sentinel_agent = CodeAgent(
tools=[vault_save_tool, telemetry_tool],
model=model,
additional_authorized_imports=["time", "os"]
)
def execute_autonomous_agent_cycle(instruction: str) -> str:
"""Helper function to execute multi-step tool calls cleanly from the main app interface."""
try:
timestamp = time.strftime('%H:%M:%S')
agent_output = sentinel_agent.run(instruction)
return f"[{timestamp}] ๐Ÿ›ฐ๏ธ [AUTONOMOUS AGENT CONCLUDED]\n-> {agent_output}"
except Exception as e:
return f"[ALERT] Autonomous agent execution exception: {str(e)}"