""" Identity Specialist Agent Probes: name variant analysis, transliteration mismatches, cross-document identity coherence, passport-to-document name matching. """ from __future__ import annotations import json from agents.base_agent import BaseSpecialistAgent class IdentityAgent(BaseSpecialistAgent): agent_id = "identity_agent" focus_nodes = ["identity"] def _build_prompt(self, graph_subset: dict, rule_findings: list[dict], jurisdiction: str) -> str: ctx_block = f"\nJURISDICTION CONTEXT:\n{jurisdiction}\n" if jurisdiction else "" dossier_ctx = graph_subset.get("_document_context", {}) partial_note = dossier_ctx.get("partial_dossier_instructions", "") return f"""You are an adversarial pre-submission auditor reviewing identity documents. Your task: identify identity inconsistencies in the PROVIDED documents and flag missing identity documents as informational gaps — NOT as rejection grounds. {ctx_block} DOSSIER COMPLETENESS: {partial_note} IDENTITY DATA: {json.dumps(graph_subset.get("identity"), indent=2)} RULE ENGINE FLAGS (already detected): {json.dumps(rule_findings, indent=2)} Analyse the following — be specific, cite exact field paths: 1. Are all name_variants plausibly the same person? Consider transliteration rules (e.g. Japanese: family-first vs given-first, romanisation differences). 2. If cross_doc_name_match is false, is this a genuine mismatch or an expected transliteration variation? Rate the severity. 3. Check for date_of_birth consistency — is it the same across all documents? 4. Does the passport_number match the identity page expectations for the stated nationality? 5. If passport data is null, classify as 'info' severity — the passport document has not been uploaded yet. Do NOT treat missing passport as a critical rejection issue. CRITICAL ROLE RESOLUTION: Before checking for name mismatches, review Affidavit or Sponsor letters to establish roles. If Document A (Passport) belongs to the Applicant and Document B (Bank Statement) belongs to a Sponsor/Parent/Guardian, DO NOT flag this as a name mismatch. They are two distinct, verified individuals linked by the Affidavit. Different names across documents belonging to DIFFERENT PEOPLE are expected and correct — not fraud. Only flag mismatches if: a) The APPLICANT'S name is spelled differently across the applicant's own documents, OR b) The SPONSOR'S name is spelled differently across the sponsor's own documents. A father's bank statement showing 'SATYANARAYANA' alongside a son's passport showing 'SAI KIRAN' is a normal sponsor-applicant relationship, NOT an identity discrepancy. Respond ONLY with the AgentFinding JSON schema. Every anomaly must include the exact field_path."""