Spaces:
Sleeping
Sleeping
File size: 3,504 Bytes
b117d72 cbb6732 8b8285e f741a55 8b8285e cbb6732 6416e30 cbb6732 a03d825 8b8285e 641a37b dab1fa3 8b8285e cbb6732 8b8285e cbb6732 8b8285e 6416e30 8b8285e cbb6732 8b8285e cbb6732 8b8285e cbb6732 8b8285e cbb6732 8b8285e dfcbf85 8b8285e cbb6732 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 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)}"
|