|
|
""" |
|
|
Debug routes for diagnosing issues in production. |
|
|
""" |
|
|
|
|
|
from fastapi import APIRouter |
|
|
from fastapi.responses import JSONResponse |
|
|
import sys |
|
|
import os |
|
|
import importlib |
|
|
import traceback |
|
|
from typing import Dict, Any |
|
|
|
|
|
router = APIRouter( |
|
|
prefix="/debug", |
|
|
tags=["debug"] |
|
|
) |
|
|
|
|
|
|
|
|
@router.get("/drummond-status") |
|
|
async def drummond_status() -> Dict[str, Any]: |
|
|
"""Check the status of Drummond agent and diagnose import issues.""" |
|
|
|
|
|
result = { |
|
|
"python_version": sys.version, |
|
|
"working_dir": os.getcwd(), |
|
|
"sys_path": sys.path[:5], |
|
|
"checks": {} |
|
|
} |
|
|
|
|
|
|
|
|
try: |
|
|
from src.agents.deodoro import BaseAgent |
|
|
result["checks"]["base_agent_import"] = { |
|
|
"status": "success", |
|
|
"abstract_methods": list(getattr(BaseAgent, '__abstractmethods__', [])) |
|
|
} |
|
|
except Exception as e: |
|
|
result["checks"]["base_agent_import"] = { |
|
|
"status": "failed", |
|
|
"error": str(e), |
|
|
"traceback": traceback.format_exc() |
|
|
} |
|
|
|
|
|
|
|
|
try: |
|
|
from src.agents.drummond import CommunicationAgent |
|
|
abstract_methods = getattr(CommunicationAgent, '__abstractmethods__', set()) |
|
|
result["checks"]["communication_agent_import"] = { |
|
|
"status": "success", |
|
|
"type": str(type(CommunicationAgent)), |
|
|
"base_classes": [str(base) for base in CommunicationAgent.__bases__], |
|
|
"abstract_methods": list(abstract_methods) if abstract_methods else "none", |
|
|
"has_shutdown": hasattr(CommunicationAgent, 'shutdown'), |
|
|
"has_initialize": hasattr(CommunicationAgent, 'initialize'), |
|
|
"has_process": hasattr(CommunicationAgent, 'process') |
|
|
} |
|
|
except Exception as e: |
|
|
result["checks"]["communication_agent_import"] = { |
|
|
"status": "failed", |
|
|
"error": str(e), |
|
|
"traceback": traceback.format_exc() |
|
|
} |
|
|
|
|
|
|
|
|
try: |
|
|
from src.agents.drummond import CommunicationAgent |
|
|
agent = CommunicationAgent() |
|
|
result["checks"]["instantiation"] = { |
|
|
"status": "success", |
|
|
"agent_name": agent.name |
|
|
} |
|
|
except Exception as e: |
|
|
result["checks"]["instantiation"] = { |
|
|
"status": "failed", |
|
|
"error": str(e), |
|
|
"error_type": type(e).__name__, |
|
|
"traceback": traceback.format_exc() |
|
|
} |
|
|
|
|
|
|
|
|
try: |
|
|
from src.api.routes.chat_drummond_factory import get_drummond_agent, _initialized, _import_error |
|
|
agent = await get_drummond_agent() |
|
|
result["checks"]["factory"] = { |
|
|
"status": "success" if agent else "failed", |
|
|
"initialized": _initialized, |
|
|
"import_error": _import_error, |
|
|
"agent_available": agent is not None |
|
|
} |
|
|
except Exception as e: |
|
|
result["checks"]["factory"] = { |
|
|
"status": "failed", |
|
|
"error": str(e), |
|
|
"traceback": traceback.format_exc() |
|
|
} |
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
@router.get("/module-info/{module_path}") |
|
|
async def module_info(module_path: str) -> Dict[str, Any]: |
|
|
"""Get information about a specific module.""" |
|
|
|
|
|
try: |
|
|
module = importlib.import_module(module_path) |
|
|
|
|
|
return { |
|
|
"module": module_path, |
|
|
"file": getattr(module, '__file__', 'unknown'), |
|
|
"attributes": [attr for attr in dir(module) if not attr.startswith('_')], |
|
|
"status": "loaded" |
|
|
} |
|
|
except Exception as e: |
|
|
return { |
|
|
"module": module_path, |
|
|
"status": "error", |
|
|
"error": str(e), |
|
|
"traceback": traceback.format_exc() |
|
|
} |