File size: 757 Bytes
2d521fd | 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 | from fastapi import APIRouter, Request
router = APIRouter()
@router.get("/stats")
async def memory_stats(request: Request):
"""
Return current memory graph statistics using the risk engine's memory instance.
"""
risk_engine = request.app.state.risk_engine
# Check if memory exists and has the required method
if hasattr(risk_engine, 'memory') and hasattr(risk_engine.memory, 'get_graph_stats'):
stats = risk_engine.memory.get_graph_stats()
return stats
else:
# Graceful fallback (e.g., during testing or if memory not initialized)
return {
"incident_nodes": 0,
"outcome_nodes": 0,
"edges": 0,
"message": "Memory not fully initialized"
}
|