Some checks failed
CI / build (push) Failing after 3s
PHASE 2.3 (AUDIT-2026-Q3.md):
Task 1 — Wire-in Wave 3 (1 router mounted, 2 deferred):
- app.routers.unified_scanner_router mounted at /api/v2/scanner/* (2 routes:
POST /api/v2/scanner/token/scan, POST /api/v2/scanner/wallet/scan).
Refactored prefix from /api/v2 -> /api/v2/scanner to avoid future conflicts
with the v1 /api/v1/scanner/ stub.
- app.routers.unified_wallet_scanner DEFERRED (no router APIRouter attribute;
library module consumed by unified_scanner_router via get_wallet_scanner()).
- app.routers.admin_extensions DEFERRED (DORMANT per audit; 25 routes at
/api/v1/admin/* would shadow /api/v1/admin/alerts_webhook).
Task 2 — Archive 136 dead-code files to app/_archive/legacy_2026_07/:
- 73 routers in app/routers/ (reach graph showed zero reach into mount.py).
- 63 flat app/*.py (domain modules never imported by live code).
- 1 file RESTORED post-archive: app/routers/x402_bridge_health.py (caught by
tests/unit/test_bridge_health.py which directly imports it; reach graph
considered tests/ only as transitive reach — to be patched in next cycle).
Forced-LIVE (NOT archived per user directive):
- app/ai_pipeline_v3.py (3 importers in audit window, importers themselves DEAD)
- app/splade_bm25.py (LIVE via app.rag_service)
- app/wallet_manager_v2.py (LIVE via x402_enforcement, x402_tools, sweep_all, sweep_now)
- app/crypto_embeddings.py (NOT in audit ARCHIVE list; heavy import graph)
Verification (forward-import closure from mount.py + main.py + factory.py + lifespan.py):
- imports = 348 app.* modules
- reached = 194 files reachable from roots
- archive set = audit_dead (186) - reached - forced_live (4) - test_live (1) = 136
- Net delta: 136 files moved, 44,932 LOC reduction, 293->295 active routes (+2 from Wave 3)
pyproject.toml updates:
- setuptools.packages.find: added exclude for app._archive*
- ruff.extend-exclude: added "app/_archive/"
- mypy.exclude: added "app/_archive/"
Smoke test: pytest tests/ — 817 passed, 3 pre-existing failures unchanged
(0 new failures; 0 routes lost; all 4 forced-LIVE files still importable).
Restoration: git mv app/_archive/legacy_2026_07/<name>.py <original-path>
and add the import to app/mount.py ROUTER_MODULES.
Refs: AUDIT-2026-Q3.md /home/dev/pry/rmi-final-deadcode-2026-07-06.md
167 lines
5.2 KiB
Python
167 lines
5.2 KiB
Python
"""
|
|
Agents Router - Agent Mesh listing, detail, commands
|
|
"""
|
|
|
|
import json
|
|
import logging
|
|
from datetime import datetime
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel, Field
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(prefix="/api/v1", tags=["agents"])
|
|
|
|
# ── Agent definitions ──
|
|
AGENTS = {
|
|
"nexus": {
|
|
"name": "NEXUS",
|
|
"role": "Strategic Coordinator",
|
|
"tier": "T0",
|
|
"models": ["gemini-2.5-pro", "nvidia/nemotron-4-340b"],
|
|
"triggers": ["strategize", "plan", "coordinate", "synthesize"],
|
|
},
|
|
"scout": {
|
|
"name": "SCOUT",
|
|
"role": "Alpha Hunter",
|
|
"tier": "T3",
|
|
"models": ["groq/llama-3.1-8b-instant", "gemini-2.5-flash"],
|
|
"triggers": ["find", "scan", "hunt", "alpha"],
|
|
},
|
|
"tracer": {
|
|
"name": "TRACER",
|
|
"role": "Forensic Investigator",
|
|
"tier": "T1",
|
|
"models": ["gemini-2.5-pro", "deepseek/deepseek-r1"],
|
|
"triggers": ["trace", "investigate", "follow", "wallet"],
|
|
},
|
|
"cipher": {
|
|
"name": "CIPHER",
|
|
"role": "Contract Auditor",
|
|
"tier": "T1",
|
|
"models": ["qwen/qwen2.5-coder-32b-instruct", "deepseek/deepseek-coder-v2"],
|
|
"triggers": ["audit", "security", "contract", "code"],
|
|
},
|
|
"sentinel": {
|
|
"name": "SENTINEL",
|
|
"role": "Rug Detector",
|
|
"tier": "T2",
|
|
"models": ["deepseek/deepseek-r1", "groq/llama-3.3-70b-versatile"],
|
|
"triggers": ["monitor", "watch", "alert", "rug"],
|
|
},
|
|
"chronicler": {
|
|
"name": "CHRONICLER",
|
|
"role": "Investigative Reporter",
|
|
"tier": "T2",
|
|
"models": ["deepseek/deepseek-r1", "gemini-2.5-flash"],
|
|
"triggers": ["write", "document", "report", "evidence"],
|
|
},
|
|
"forge": {
|
|
"name": "FORGE",
|
|
"role": "Implementation Architect",
|
|
"tier": "T1",
|
|
"models": ["qwen/qwen2.5-coder-32b-instruct", "deepseek/deepseek-coder-v2"],
|
|
"triggers": ["code", "implement", "build", "script"],
|
|
},
|
|
"relay": {
|
|
"name": "RELAY",
|
|
"role": "Communications Coordinator",
|
|
"tier": "T3",
|
|
"models": ["groq/llama-3.1-8b-instant", "gemini-2.5-flash"],
|
|
"triggers": ["format", "relay", "dispatch", "notify"],
|
|
},
|
|
}
|
|
|
|
|
|
class AgentCommandRequest(BaseModel):
|
|
agent: str = Field(
|
|
...,
|
|
description="Agent name: nexus, scout, tracer, cipher, sentinel, chronicler, forge, relay",
|
|
)
|
|
command: str
|
|
context: dict | None = None
|
|
priority: str = Field(default="normal")
|
|
|
|
|
|
from app.auth import get_redis # noqa: E402
|
|
|
|
|
|
# ── Static routes must comes before parameterized routes to avoid FastAPI matching issues ──
|
|
@router.get("/agents/specter")
|
|
async def specter_status():
|
|
"""SPECTER agent status and capabilities"""
|
|
import os
|
|
|
|
return {
|
|
"agent": "SPECTER",
|
|
"emoji": "👻",
|
|
"role": "OSINT & Social Forensics",
|
|
"provider": "Together AI",
|
|
"models": [
|
|
"meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
"mistralai/Mixtral-8x22B-Instruct-v0.1",
|
|
],
|
|
"free_credits": "$5",
|
|
"capabilities": [
|
|
"brave_web_search",
|
|
"website_forensics",
|
|
"firecrawl_scraping",
|
|
"dev_identity_hunting",
|
|
"social_media_analysis",
|
|
"litepaper_plagiarism_detection",
|
|
"sockpuppet_detection",
|
|
],
|
|
"integrations": {
|
|
"brave_search": bool(os.getenv("BRAVE_API_KEY")),
|
|
"firecrawl": bool(os.getenv("FIRECRAWL_API_KEY")),
|
|
"apify": bool(os.getenv("APIFY_API_KEY")),
|
|
"together_ai": bool(os.getenv("TOGETHER_API_KEY")),
|
|
},
|
|
"status": "online",
|
|
}
|
|
|
|
|
|
@router.get("/agents")
|
|
async def list_agents():
|
|
return {"agents": AGENTS, "total": len(AGENTS)}
|
|
|
|
|
|
# ── Helper to get Redis synchronously ──
|
|
def _get_redis_sync():
|
|
"""Get Redis instance synchronously (get_redis returns redis.Redis, not async)."""
|
|
return get_redis()
|
|
|
|
|
|
@router.get("/agents/{agent_id}")
|
|
async def get_agent(agent_id: str):
|
|
if agent_id not in AGENTS:
|
|
raise HTTPException(status_code=404, detail=f"Agent {agent_id} not found")
|
|
r = _get_redis_sync()
|
|
status_raw = r.hget("rmi:agents", agent_id)
|
|
status = json.loads(status_raw) if status_raw else {"status": "online", "last_ping": datetime.utcnow().isoformat()}
|
|
return {**AGENTS[agent_id], **status}
|
|
|
|
|
|
@router.post("/agents/{agent_id}/command")
|
|
async def agent_command(agent_id: str, req: AgentCommandRequest):
|
|
if agent_id not in AGENTS:
|
|
raise HTTPException(status_code=404, detail=f"Agent {agent_id} not found")
|
|
|
|
agent = AGENTS[agent_id]
|
|
r = _get_redis_sync()
|
|
|
|
task_id = f"task:{datetime.utcnow().timestamp():.0f}:{agent_id}"
|
|
task_data = {
|
|
"id": task_id,
|
|
"agent": agent_id,
|
|
"command": req.command,
|
|
"context": req.context or {},
|
|
"priority": req.priority,
|
|
"status": "queued",
|
|
"created": datetime.utcnow().isoformat(),
|
|
}
|
|
r.hset("rmi:tasks", task_id, json.dumps(task_data))
|
|
r.lpush("rmi:queue:" + req.priority, task_id)
|
|
|
|
return {"task_id": task_id, "agent": agent["name"], "status": "queued", "command": req.command}
|