Add core agent: agents/logic_auditor.py
Browse files- agents/logic_auditor.py +115 -0
agents/logic_auditor.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import json
|
| 3 |
+
from typing import List, Dict, Any
|
| 4 |
+
from pydantic import BaseModel, Field
|
| 5 |
+
from core.mcp_protocol import mcp_call
|
| 6 |
+
|
| 7 |
+
class AuditResolution(BaseModel):
|
| 8 |
+
verdict: str
|
| 9 |
+
risk_score: float
|
| 10 |
+
reasoning_steps: List[str]
|
| 11 |
+
mcp_trace: str
|
| 12 |
+
warning: str = ""
|
| 13 |
+
|
| 14 |
+
class LogicAuditor:
|
| 15 |
+
"""
|
| 16 |
+
Next-Gen Logic-Auditor: Employs a 'Sovereign Reasoning Chain'.
|
| 17 |
+
Uses multi-step reflection to identify sophisticated academic fraud.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
async def audit(self, transcript: Dict[str, Any], profile: Dict[str, Any]) -> AuditResolution:
|
| 21 |
+
print("[LOGIC] [Logic-Auditor] Initializing deep-reasoning sequence...")
|
| 22 |
+
|
| 23 |
+
# Wrapping logic execution in an MCP context
|
| 24 |
+
call = mcp_call("mcp_logic_audit", {"transcript_id": "...", "context_level": "deep"})
|
| 25 |
+
|
| 26 |
+
reasoning_steps = []
|
| 27 |
+
anomalies = []
|
| 28 |
+
diploma_mill_warning = ""
|
| 29 |
+
|
| 30 |
+
# Step 0: Known Diploma Mill / Degree Factory Hard-Rejection
|
| 31 |
+
is_diploma_mill = profile.get("is_diploma_mill", False)
|
| 32 |
+
profile_status = profile.get("status", "")
|
| 33 |
+
inst_name = profile.get("name", "").lower()
|
| 34 |
+
|
| 35 |
+
# Load global blacklist for safety
|
| 36 |
+
try:
|
| 37 |
+
with open("data/fraud_blacklist.json", "r", encoding="utf-8") as f:
|
| 38 |
+
blacklist_data = json.load(f)
|
| 39 |
+
global_blacklist = [b["name"].lower() for b in blacklist_data["blacklist"]]
|
| 40 |
+
if inst_name in global_blacklist:
|
| 41 |
+
is_diploma_mill = True
|
| 42 |
+
except Exception:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
if is_diploma_mill or profile_status == "fraudulent":
|
| 46 |
+
warning_msg = profile.get("warning", "")
|
| 47 |
+
diploma_mill_warning = warning_msg or "[!!!] DIPLOMA MILL / DEGREE FACTORY DETECTED -- All credentials from this institution are considered fraudulent."
|
| 48 |
+
print(f"\n{'!'*60}")
|
| 49 |
+
print(f" [ALERT] DIPLOMA MILL DETECTED [ALERT]")
|
| 50 |
+
print(f" Institution: {profile.get('name', 'Unknown')}")
|
| 51 |
+
print(f" {diploma_mill_warning}")
|
| 52 |
+
print(f"{'!'*60}\n")
|
| 53 |
+
|
| 54 |
+
return AuditResolution(
|
| 55 |
+
verdict="REJECTED — DIPLOMA MILL / DEGREE FACTORY",
|
| 56 |
+
risk_score=100.0,
|
| 57 |
+
reasoning_steps=[
|
| 58 |
+
"Step 0: Known Diploma Mill / Degree Factory check.",
|
| 59 |
+
f"Result 0: HARD REJECTION. '{profile.get('name', 'Unknown')}' is flagged as a confirmed diploma mill.",
|
| 60 |
+
"No further analysis required. All credentials from this entity are fraudulent."
|
| 61 |
+
],
|
| 62 |
+
mcp_trace=call.trace_id,
|
| 63 |
+
warning=diploma_mill_warning
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Step 1: Temporal Contextualization
|
| 67 |
+
reasoning_steps.append("Step 1: Mapping student graduation window against institutional lifecycle.")
|
| 68 |
+
grad_year = transcript.get("graduation_year", 0)
|
| 69 |
+
est_year = profile.get("established_year", 1800)
|
| 70 |
+
|
| 71 |
+
if grad_year > 0 and grad_year < est_year:
|
| 72 |
+
anomalies.append("CRITICAL: Temporal paradox detected. Graduation predates founding.")
|
| 73 |
+
reasoning_steps.append("Result 1: Violation found. Graduation window is historically impossible.")
|
| 74 |
+
else:
|
| 75 |
+
reasoning_steps.append("Result 1: Timeline verified.")
|
| 76 |
+
|
| 77 |
+
# Step 2: Scholarly Footprint Validation (Recursive Check)
|
| 78 |
+
reasoning_steps.append("Step 2: Analyzing scholarly entropy of the issuing institution.")
|
| 79 |
+
reputation = profile.get("reputation_score", 0.0)
|
| 80 |
+
is_sovereign_node = "Atlanta College" in profile.get("name", "")
|
| 81 |
+
has_ror_id = bool(profile.get("ror_id"))
|
| 82 |
+
is_active = profile.get("status") == "active"
|
| 83 |
+
|
| 84 |
+
# Sovereign nodes (e.g., ACLAS College) always pass
|
| 85 |
+
if is_sovereign_node:
|
| 86 |
+
reasoning_steps.append("Result 2: Sovereign Gold Standard Node. Scholarly footprint confirmed.")
|
| 87 |
+
# Active institutions with a ROR ID and decent reputation pass
|
| 88 |
+
elif has_ror_id and is_active and reputation >= 5.0:
|
| 89 |
+
reasoning_steps.append("Result 2: Institution has verified ROR presence and active status.")
|
| 90 |
+
elif reputation < 5.0:
|
| 91 |
+
anomalies.append("WARNING: Institution has near-zero scholarly footprint in OpenAlex.")
|
| 92 |
+
reasoning_steps.append("Result 2: Anomaly found. Higher probability of Degree Mill activity.")
|
| 93 |
+
else:
|
| 94 |
+
reasoning_steps.append("Result 2: Academic reputation within acceptable variance.")
|
| 95 |
+
|
| 96 |
+
# Step 3: Global Registry Conflict Resolution
|
| 97 |
+
reasoning_steps.append("Step 3: Checking ROR 'Status' history.")
|
| 98 |
+
status = profile.get("status", "active")
|
| 99 |
+
if status != "active":
|
| 100 |
+
anomalies.append(f"REJECTION: Registry status is '{status}'.")
|
| 101 |
+
reasoning_steps.append(f"Result 3: Conflict confirmed. Institution is currently {status}.")
|
| 102 |
+
|
| 103 |
+
# Final Synthesis Logic
|
| 104 |
+
risk_score = min(100.0, len(anomalies) * 45.0)
|
| 105 |
+
verdict = "APPROVED" if risk_score < 40 else "REJECTED"
|
| 106 |
+
if 0 < risk_score < 70 and verdict == "REJECTED":
|
| 107 |
+
# Some leniency for warnings
|
| 108 |
+
pass
|
| 109 |
+
|
| 110 |
+
return AuditResolution(
|
| 111 |
+
verdict=verdict,
|
| 112 |
+
risk_score=risk_score,
|
| 113 |
+
reasoning_steps=reasoning_steps,
|
| 114 |
+
mcp_trace=call.trace_id
|
| 115 |
+
)
|