"""Reviewer Agent — bilingual quality check with strongest reasoning model.""" from __future__ import annotations import json from typing import Any from .base import BaseAgent from app.config import settings class ReviewerAgent(BaseAgent): name = "reviewer" description = "双语报告质量审查 — 使用最强推理模型" system_prompt = """\ You are a senior consulting partner reviewing a report before client delivery. The report has both Chinese and English versions (or will be translated). Review dimensions: 1. **Accuracy** — Are data points, percentages, and claims supported by the research? Cross-check global claims against English research, Chinese claims against Chinese research. 2. **Logical consistency** — Does the narrative flow? Are there contradictions between chapters? 3. **Depth of analysis** — Is it consultancy-grade or just surface-level? Would a C-suite exec find it valuable? 4. **Bilingual quality** — If translated version exists, check for translation artifacts, mistranslated terminology, or cultural mismatches. 5. **Data gaps honesty** — Are uncertainties acknowledged or are claims fabricated? 6. **Completeness** — Are any critical aspects of the requirement left unaddressed? Scoring guide: - 90+: Publication-ready - 80-89: Minor issues, can pass with notes - 70-79: Needs revision (verdict: revise) - <70: Significant problems (verdict: reject) Output (JSON): { "overall_score": 85, "verdict": "pass|revise|reject", "issues": [ { "severity": "high|medium|low", "chapter": "affected chapter", "dimension": "accuracy|consistency|depth|bilingual|gaps|completeness", "description": "issue description", "suggestion": "specific fix suggestion" } ], "strengths": ["what the report does well"], "summary": "Overall assessment (2-3 sentences)" }""" def __init__(self): super().__init__(model=settings.model_for_domain("reasoning")) async def run(self, context: dict[str, Any]) -> dict[str, Any]: draft = context["draft"] draft_translated = context.get("draft_translated", {}) research = context["research"] sections = [ "## Research Plan (what was asked)", json.dumps(research, ensure_ascii=False, indent=2), "", "## Primary Draft", json.dumps(draft, ensure_ascii=False, indent=2), ] if draft_translated: sections.extend([ "", "## Translated Version", json.dumps(draft_translated, ensure_ascii=False, indent=2), ]) prompt = "\n".join(sections) + "\n\nReview the report. Output JSON." result = await self.call_llm_json(prompt, max_tokens=4096) return {"review": result}