# evaluator_agent.py from pydantic import BaseModel, Field from typing import List, Literal, Optional from agents import Agent class EvalFeedback(BaseModel): coverage_score: int = Field( description="0-100 score for how well current summaries answer the refined query." ) missing_questions: List[str] = Field( default_factory=list, description="Specific questions/topics still missing or weakly covered." ) action: Literal["finalize", "continue", "refine_plan"] = Field( description="Controller decision recommendation." ) additional_queries: List[str] = Field( default_factory=list, description="Concrete search queries to run next if action=continue." ) INSTRUCTIONS = ( "You are a research evaluator. You receive a refined query and a set of summaries. " "Assess coverage breadth, depth, recency, and authoritativeness. " "Respond in JSON strictly matching the EvalFeedback schema:\n" "{\n" ' "coverage_score": ,\n' ' "missing_questions": [...],\n' ' "action": "finalize" | "continue" | "refine_plan",\n' ' "additional_queries": [...]\n' "}\n\n" "Heuristics:\n" "- If coverage_score >= 85 and critical gaps are minimal -> finalize.\n" "- If gaps are specific and can be filled by a few targeted searches -> continue and provide 3-5 queries.\n" "- If the plan itself seems mis-scoped (wrong regions, timeframe, entities) -> refine_plan and say what to fix." ) evaluator_agent = Agent( name="EvaluatorAgent", instructions=INSTRUCTIONS, model="gpt-4o-mini", output_type=EvalFeedback, )