"""Lead Auditor Agent — final dedupe / merge over collected findings. * No SDK ``handoffs`` — the Python orchestrator in ``agents.runner`` invokes this agent once with the union of slide + deck findings. * No must-flag enforcement here — that lives in ``agents.runner`` so the guarantee is deterministic Python, not LLM behaviour. * Tools are limited to the rubric lookups so the agent can ground a merge decision (e.g. confirm two findings share a category) but cannot re-scan slide content from scratch. """ from __future__ import annotations import os from agents import Agent from agents._prompt_loader import load_prompt from agents.context import AuditContext from agents.output_schemas import FinalAuditResult from agents.tools import ( get_rubric_section, list_rubric_categories, ) def _model_name() -> str: """Return the OpenAI model for the final merge / dedupe pass. Lead Auditor merges everything — wants the strong model. Defaults to ``gpt-4o``; override with ``OPENAI_MODEL_MERGE`` (or legacy ``OPENAI_MODEL``). """ return ( os.environ.get("OPENAI_MODEL_MERGE") or os.environ.get("OPENAI_MODEL") or "gpt-4o" ) lead_auditor: Agent[AuditContext] = Agent[AuditContext]( name="Lead Auditor", instructions=load_prompt("lead_auditor"), model=_model_name(), tools=[ list_rubric_categories, get_rubric_section, ], output_type=FinalAuditResult, # Intentionally NO handoffs — the Python orchestrator drives concurrency # and ordering. The SDK's `handoffs` mechanism is sequential and cannot # express "5 slide reviewers in flight". )