| """Anomaly Detection Agent - Identifies unusual behaviors.""" |
|
|
| from typing import Dict, List, Any |
|
|
|
|
| class AnomalyDetectionAgent: |
| """Detects anomalies in claim data.""" |
| |
| def __init__(self): |
| self.name = "AnomalyDetectionAgent" |
| self.version = "1.0" |
| self.anomaly_threshold = 0.6 |
| |
| def process(self, claim_data: Dict[str, Any], historical_data: Dict[str, Any]) -> Dict[str, Any]: |
| """Detect anomalies in claim.""" |
| anomalies = [] |
| anomaly_score = 0.0 |
| |
| |
| claim_amount = claim_data.get("claim_amount", 0) |
| if claim_amount > 10000: |
| anomalies.append("unusually_high_amount") |
| anomaly_score += 0.4 |
| |
| |
| if historical_data.get("fraud_flag", False): |
| anomalies.append("previous_fraud_history") |
| anomaly_score += 0.5 |
| |
| |
| anomaly_score = min(anomaly_score, 1.0) |
| |
| return { |
| "anomalies_detected": anomalies, |
| "anomaly_score": anomaly_score, |
| "is_anomalous": anomaly_score >= self.anomaly_threshold, |
| "confidence": 0.82 |
| } |
| |
| def get_trace(self) -> Dict[str, Any]: |
| return { |
| "agent": self.name, |
| "version": self.version, |
| "timestamp": "2024-12-31T01:00:00Z", |
| "status": "completed" |
| } |
|
|