""" Evolutionary Algorithms Research Agent — FastAPI monitoring server + autonomous agent launcher. Serves an HTML dashboard at / and /status (JSON). Agent runs in daemon threads alongside the HTTP server. """ import os import threading import time import uvicorn from fastapi import FastAPI from fastapi.responses import HTMLResponse, JSONResponse from agent import Kyros9Agent # ── Global state ─────────────────────────────────────────────────────────────── _agent: Kyros9Agent | None = None _logs: list[str] = [] def _log_handler(msg: str, level: str = "info"): _logs.append(msg) if len(_logs) > 500: _logs.pop(0) def _ensure_agent() -> Kyros9Agent: global _agent if _agent is None: _agent = Kyros9Agent(log_callback=_log_handler) return _agent # ── FastAPI app ──────────────────────────────────────────────────────────────── app = FastAPI(title="Evolutionary Algorithms Research Agent", docs_url=None, redoc_url=None) @app.get("/status") async def status(): agent = _ensure_agent() s = agent.get_stats() return JSONResponse({ "running": s["running"], "rank": s["rank"], "papers_published": s["papers_published"], "validations_done": s["validations_done"], "messages_sent": s["messages_sent"], "last_action": s["last_action"], "log_tail": s["log_tail"][-30:], "agent_id": s["agent_id"], "specialty": "Evolutionary Computation", }) @app.get("/", response_class=HTMLResponse) async def dashboard(): return HTMLResponse(_DASHBOARD_HTML) # ── Dashboard HTML ───────────────────────────────────────────────────────────── # Note: regular string (not f-string). Colors are baked in by Jinja2 at render time. _DASHBOARD_HTML = """
Specialty: Evolutionary Computation | Network: P2PCLAW | LLM: hf/Qwen/Qwen2.5-72B-Instruct | ● Connecting…
Mission: This agent investigates the application of evolutionary algorithms to complex optimization problems 24/7.
Agent ID: evolutionary-algorithms-01 | Role: Artificial Life Investigator