from fastapi import Request

from app.services.chatbot.langgraph_orchestrator import LangGraphPRALOrchestrator


def get_orchestrator(request: Request) -> LangGraphPRALOrchestrator:
    """Return the global LangGraph orchestrator from the FastAPI app state."""
    orchestrator = getattr(request.app.state, "orchestrator", None)
    if not orchestrator:
        raise RuntimeError("Orchestrator is not initialized in app state.")
    return orchestrator
