fix: DAGI Router agents logic, MicroDAO logo URL handling

This commit is contained in:
Apple
2025-12-01 06:03:08 -08:00
parent e3accd4df0
commit 909258fdcb
3 changed files with 35 additions and 42 deletions

View File

@@ -4167,8 +4167,9 @@ async def get_dagi_router_health(node_id: str):
@router.get("/internal/node/{node_id}/dagi-router/agents")
async def get_dagi_router_agents(node_id: str):
"""
Get list of agents registered with DAGI Router for a node.
Compares with DB to identify phantom/stale agents.
Get list of agents for a node.
Since DAGI Router doesn't expose /agents endpoint, we use DB agents
and check router health to determine status.
"""
import httpx
@@ -4178,68 +4179,54 @@ async def get_dagi_router_agents(node_id: str):
}
base_url = NODE_ROUTER_URLS.get(node_id)
router_agents = []
router_healthy = False
# Try to get agents from router
# Check if router is healthy
if base_url:
try:
async with httpx.AsyncClient(timeout=5.0) as client:
resp = await client.get(f"{base_url}/agents")
async with httpx.AsyncClient(timeout=3.0) as client:
resp = await client.get(f"{base_url}/health")
if resp.status_code == 200:
data = resp.json()
router_agents = data.get("agents", [])
router_healthy = data.get("status") == "healthy"
except Exception as e:
logger.warning(f"Failed to get agents from router for {node_id}: {e}")
logger.warning(f"Failed to check router health for {node_id}: {e}")
# Get agents from DB for this node
try:
db_agents = await repo_city.get_agents_for_node(node_id)
db_agent_ids = {a.get("id") or a.get("slug") for a in db_agents}
except Exception as e:
logger.warning(f"Failed to get DB agents for {node_id}: {e}")
db_agents = []
db_agent_ids = set()
# Build combined list
# Build agents list - if router is healthy, agents are "active", otherwise "stale"
result_agents = []
router_agent_ids = set()
for ra in router_agents:
agent_id = ra.get("id") or ra.get("name") or ra.get("slug")
for db_agent in db_agents:
agent_id = db_agent.get("id") or db_agent.get("slug")
if not agent_id:
continue
router_agent_ids.add(agent_id)
# Check if in DB
has_db_record = agent_id in db_agent_ids
status = "active" if has_db_record else "phantom"
# Determine status based on router health and agent status
agent_status = db_agent.get("status", "offline")
if router_healthy and agent_status in ("online", "active"):
status = "active"
elif router_healthy:
status = "stale" # Router up but agent offline
else:
status = "stale" # Router down
result_agents.append({
"id": agent_id,
"name": ra.get("name"),
"kind": ra.get("kind"),
"runtime": ra.get("runtime") or f"{node_id}-router",
"name": db_agent.get("display_name") or db_agent.get("name"),
"kind": db_agent.get("kind"),
"runtime": f"{node_id}-router" if router_healthy else None,
"node_id": node_id,
"last_seen_at": ra.get("last_seen_at"),
"last_seen_at": db_agent.get("last_seen_at"),
"status": status,
"has_db_record": has_db_record
"has_db_record": True
})
# Add stale agents (in DB but not in router)
for db_agent in db_agents:
agent_id = db_agent.get("id") or db_agent.get("slug")
if agent_id and agent_id not in router_agent_ids:
result_agents.append({
"id": agent_id,
"name": db_agent.get("display_name") or db_agent.get("name"),
"kind": db_agent.get("kind"),
"runtime": None,
"node_id": node_id,
"last_seen_at": None,
"status": "stale",
"has_db_record": True
})
# Count by status
active = sum(1 for a in result_agents if a["status"] == "active")
phantom = sum(1 for a in result_agents if a["status"] == "phantom")