"""Whether the OpenAI tool-calling inspector is active (for dev / health visibility).""" from __future__ import annotations from typing import Any from app.config import settings def is_openai_inspector_live() -> bool: """True when section generation may use ``run_inspector_tool_loop`` (tool-calling). Matches the gate in :class:`app.agentic.agents.HeadAgent` — non-empty API key and ``inspector_tool_agent`` enabled. """ key = (settings.openai_api_key or "").strip() return bool(key) and bool(settings.inspector_tool_agent) def inspector_public_status() -> dict[str, Any]: """Safe JSON for ``/health`` and logs: no secrets, only booleans and paths.""" key_ok = bool((settings.openai_api_key or "").strip()) flag = bool(settings.inspector_tool_agent) live = key_ok and flag if not key_ok: reason = "OPENAI_API_KEY is unset or empty — per-section agent uses the legacy fixed pipeline." elif not flag: reason = "INSPECTOR_TOOL_AGENT=false — tool-calling loop disabled; legacy pipeline runs." else: reason = "OpenAI tool-calling inspector is active for agentic report generation." return { "effective_mode": "openai_tool_agent" if live else "legacy_pipeline", "openai_api_key_configured": key_ok, "inspector_tool_agent": flag, "inspector_max_tool_rounds": int(settings.inspector_max_tool_rounds), "tool_agent_endpoints": [ "POST /reports/{report_id}/agentic/generate", ], "other_generate_path": ( "POST /reports/{report_id}/generate uses the inspector HeadAgent when " "AGENTIC_INSPECTOR_WHEN_NOTES_ONLY=true or NOTES_ONLY_GENERATION=false; " "otherwise the standard fixed RAG pipeline (notes-only default)." ), "summary": reason, }