File size: 1,459 Bytes
7f10b99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""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
        
        # Check claim amount vs historical average
        claim_amount = claim_data.get("claim_amount", 0)
        if claim_amount > 10000:
            anomalies.append("unusually_high_amount")
            anomaly_score += 0.4
        
        # Check fraud flag
        if historical_data.get("fraud_flag", False):
            anomalies.append("previous_fraud_history")
            anomaly_score += 0.5
        
        # Normalize score
        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"
        }