CoolFace
Apppublic

khushiks21/fraud-investigation-env

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

Fraud Investigation RL Environment

An OpenEnv-compatible reinforcement learning environment where LLM agents learn to detect financial fraud across three progressively harder tasks.


Motivation

Financial fraud costs banks billions annually. This environment simulates real investigator workflows: gather evidence, form hypotheses, make decisions. Unlike toy environments, every case mirrors real-world fraud patterns used by fraud ops teams.


Tasks

TaskDifficultyDescription
task_easyEasyCredit card fraud — geo-impossible transactions, velocity fraud, legitimate travelers
task_mediumMediumAccount takeover — device hijack, credential stuffing, SIM swap
task_hardHardNetwork fraud — money mule rings, bust-out fraud, legitimate businesses

Episode Design (2-step)

  1. 1.Step 1 — Investigate Agent sees account profile + transactions only. Calls investigate to reveal login events, account changes, and system signals.
  1. 1.Step 2 — Decide Agent sees full data and submits final fraud decision.

Action Space

json
{
  "action_type": "investigate | submit_decision",
  "is_fraud": true,
  "fraud_type": "card_fraud | account_takeover | money_mule | bust_out | legitimate",
  "confidence": 0.91,
  "evidence": ["geo_impossible", "card_not_present"],
  "attack_vector": "geo_impossible",
  "action": "block_card | freeze_account | allow | file_SAR | hold_for_review | escalate",
  "flagged_accounts": ["ACC-1001"],
  "hub_account": null,
  "regulatory_action": "SAR | law_enforcement | none",
  "reasoning": "Transaction from Lagos 224 mins after Mumbai swipe — physically impossible."
}

Observation Space

json
{
  "case_id": "CC-001",
  "task": "task_easy",
  "step": 1,
  "account": { "account_id": "...", "name": "...", ... },
  "transactions": [...],
  "login_events": [...],
  "account_events": [...],
  "linked_accounts": [...],
  "additional_signals": { "distance_km": 8200, ... },
  "reward": 0.01,
  "done": false,
  "feedback": "..."
}

Reward Design

SignalWeightNotes
Fraud/legitimate correct+0.30Core decision
Fraud type correct+0.15cardfraud vs accounttakeover etc
Evidence signals matched+0.25Fuzzy match, partial credit
Correct action taken+0.20block_card / freeze / allow
Confidence calibrated+0.10Penalizes overconfident wrong answers
False positive-0.10Flagging legitimate as fraud

Baseline Scores

TaskAvg Reward
task_easy~0.78
task_medium~0.73
task_hard~0.71

Quick Start

1. Clone and set up

bash
git clone https://github.com/khushiks2021/RL-env
cd RL-env
cp .env.example .env
# Edit .env and add your GROQ_API_KEY

2. Start the environment server

bash
docker build -t fraud-env .
docker run -p 8000:8000 fraud-env

Or with docker-compose:

bash
docker-compose up -d

3. Run inference

bash
pip install -r requirements.txt
python inference.py

Environment Variables

VariableRequiredDescription
HF_TOKENYes (or GROQ)HuggingFace API token
GROQAPIKEYYes (or HF)Groq API key (free tier works)
APIBASEURLNoLLM endpoint (default: Groq)
MODEL_NAMENoModel name (default: llama-3.1-8b-instant)
ENV_URLNoEnvironment server URL (default: http://localhost:8000)
EPISODESPERTASKNoEpisodes per task (default: 2)

API Endpoints

MethodPathDescription
GET/healthHealth check
POST/resetStart new episode
POST/stepSubmit action
GET/stateCurrent episode state
GET/tasksList all tasks
POST/closeEnd episode