Fraud Detection Workflow

In this assignment, you'll create a multi-agent fraud detection system using CrewAI. The system will analyze transactions, detect anomalies, and escalate suspicious cases to specialized agents when necessary.

Input

Transaction Data

Analyze

Detect Anomalies

Escalate

If Anomalies > N

Report

Final Analysis

How It Works

The fraud detection system uses multiple specialized agents working together under the supervision of an Agent Manager. Each agent has a specific role in analyzing transactions and detecting potential fraud.

Agent Components

Transaction Analyzer Agent

Analyzes incoming transactions and identifies potential anomalies based on predefined rules and patterns.

Fraud Specialist Agent

Handles escalated cases with high anomaly scores, performing in-depth analysis and verification.

Report Generator Agent

Compiles the final report summarizing all analyzed transactions and their outcomes.

Required Inputs

  • Transaction data (amount, location, time, etc.)
  • Anomaly threshold (N)

🔥 Bonus Feature: Parallel Processing with Asynchronous Crews

(Click to expand) â–¼

If you've completed Assignment 4 (AI-Powered Onboarding System), you can enhance this fraud detection system by implementing parallel processing using asynchronous crews. This allows for faster processing of transactions by running multiple analysis tasks simultaneously.

Pro tip: Split your transaction list into batches and let multiple agents work their magic in parallel. Just make sure to handle those async results properly!

Useful Resources

Code Examples

Transaction Data (use this as input data)

transaction_list = [
    # Normal Transactions
    "TXN1 | Withdrawal | $500 | ATM | New York | 2024-07-01 14:23 | Card Ending: 1234",
    "TXN2 | Online Purchase | $200 | Electronics Store | San Francisco | 2024-07-02 09:45 | IP: 192.168.0.1",
    "TXN3 | Transfer | $1,000 | Bank Account | Zurich | 2024-07-02 17:10 | Beneficiary: John Doe",
    "TXN4 | POS Purchase | $50 | Grocery Store | Berlin | 2024-07-03 12:30 | Card Ending: 5678",
    "TXN5 | Withdrawal | $400 | ATM | Dubai | 2024-07-04 08:15 | Card Ending: 1234",
    "TXN6 | Online Purchase | $150 | Retail Store | Paris | 2024-07-04 20:50 | IP: 10.0.0.2",
    "TXN7 | Transfer | $2,000 | Bank Account | London | 2024-07-05 11:30 | Beneficiary: Jane Smith",
    "TXN8 | POS Purchase | $30 | Coffee Shop | New York | 2024-07-05 15:00 | Card Ending: 5678",
    "TXN9 | Withdrawal | $200 | ATM | San Francisco | 2024-07-06 10:00 | Card Ending: 1234",
    "TXN10 | Online Purchase | $300 | Bookstore | Berlin | 2024-07-06 13:45 | IP: 10.0.0.5",

    # Anomalies
    "TXN11 | Withdrawal | $9,999 | ATM | Las Vegas | 2024-07-07 03:15 | Card Ending: 9999",  # High Amount, Odd Time
    "TXN12 | Transfer | $50,000 | Offshore Account | Cayman Islands | 2024-07-07 05:00 | Beneficiary: Unknown",  # Offshore Account
    "TXN13 | Online Purchase | $5,500 | Luxury Retailer | Unknown Location | 2024-07-07 23:59 | IP: 255.255.255.0",  # Suspicious IP and Location
    "TXN14 | Withdrawal | $7,000 | ATM | Dubai | 2024-07-08 02:30 | Card Ending: 0000",  # Odd Time, High Amount
    "TXN15 | POS Purchase | $1 | Jewelry Store | New York | 2024-07-08 14:00 | Card Ending: 5678",  # Unusually Low Amount
    "TXN16 | Online Purchase | $10,000 | Electronics | Hong Kong | 2024-07-08 22:45 | IP: 192.0.2.1",  # Large Online Purchase
    "TXN17 | Transfer | $25,000 | Bank Account | Zurich | 2024-07-09 16:10 | Beneficiary: Suspicious Entity",  # High Value Transfer
    "TXN18 | Withdrawal | $6,000 | ATM | Remote Location | 2024-07-09 04:45 | Card Ending: 8888",  # Remote Location, Odd Time
    "TXN19 | POS Purchase | $9,000 | Luxury Boutique | Paris | 2024-07-09 19:30 | Card Ending: 1234",  # Unusually High POS Purchase
    "TXN20 | Online Purchase | $8,200 | Unknown Store | Unknown | 2024-07-09 21:15 | IP: 0.0.0.0"  # Untraceable IP, Unknown Store
]

Conditional Task

# Condition to check if issues exceed a threshold
def is_escalation_needed(output: TaskOutput) -> bool:
    return len(output.pydantic.issues) > 5

class CodeReviewTaskOutput(BaseModel):
    issues: List[str]

def create_code_review_tasks(code_files: List[str]):
    task1 = Task(
        description=f"Review the following code files for issues: {code_files}",
        agent=code_reviewer,
        expected_output=f"List of code issues found in each file.",
        output_pydantic=CodeReviewTaskOutput,
    )
    return [task1]

# Define conditional task
conditional_task = ConditionalTask(
    description="Escalate code review if more than 5 issues are detected.",
    agent=senior_developer,
    condition=is_escalation_needed,
    expected_output="Senior review with recommendations for critical issues.",
)