FinSpectra is an autonomous, task-driven Multi-Agent Anti-Money Laundering (AML) & Financial Crime Investigation Engine. Built on FastAPI, LangGraph, SQLAlchemy, Neon PostgreSQL, and Groq LLM (Llama 3.3 70B), it automates deep forensic investigations of financial crime alerts, performs multi-agent evidence gathering, calculates statistical risk scores, and generates regulatory Suspicious Activity Report (SAR) dossiers.
- β‘ Atomic Alert Lifecycle Management: Implements strict status state machine transitions (
OPEN$\rightarrow$ UNDER_INVESTIGATION$\rightarrow$ CLOSED/FAILED) synchronized across Neon PostgreSQL database tables. - π€ Task-Driven LangGraph Orchestration: Dynamically generates, routes, executes, and validates multi-agent forensic tasks based on money laundering typologies.
- π Specialized Forensic Agent Nodes:
- Evidence Retrieval Agent: Gathers context on accounts, transactions, counterparties, and device associations.
-
Behavior Analyzer Agent: Calculates statistical velocity Z-scores (
$\mu$ ,$\sigma$ ), transaction volume surges, and pass-through ratios. - Graph Analyst Agent: Computes 2-hop graph topological network metrics (beneficiary dispersion, device sharing, self-transfers).
- KYC Verifier Agent: Cross-evaluates customer risk tiers, account age, and occupation against activity.
- π― Strict Typology Classifier: Classifies patterns against an enforced, validated schema (
STRUCTURING,LAYERING,MULE_ACCOUNT,FAN_IN,FAN_OUT,UNKNOWN) with automated schema validation and offline fallback. - βοΈ Composite Risk Scoring Engine: Calculates weighted risk scores (
$0.35 \times \text{Prior} + 0.25 \times \text{Behavior} + 0.25 \times \text{Graph} + 0.15 \times \text{KYC}$ ) to make actionable decisions:ALLOW,REVIEW, orBLOCK. - π Strictly Grounded Case Assembler: Generates audit-ready SAR narrative dossiers strictly grounded in observed evidence facts without hallucinating unsupported details.
- π‘οΈ Hardened Reliability & Mock Fallback: Includes auto-retries, timeouts, configurable token limits, production mock guards, and seamless offline development mock modes.
- π Safe Showcase & Live Execution Modes: Includes a demonstration CLI (
run_investigation_demo.py) supporting 100% read-only safe mode execution and live database mutation mode.
flowchart TD
DB[(Neon PostgreSQL\nalerts Table)] -->|Claim Alert\nOPEN -> UNDER_INVESTIGATION| Repo[AlertRepository]
Repo --> State[InvestigationState Initialization]
subgraph Multi-Agent LangGraph Pipeline
State --> TaskPlanner[Task Planner Node]
TaskPlanner --> TaskRouter{Dynamic Task Router}
TaskRouter -->|FETCH_EVIDENCE| EvidenceAgent[Evidence Retrieval Agent]
TaskRouter -->|VERIFY_KYC| KYCAgent[KYC Verifier Agent]
TaskRouter -->|ANALYZE_BEHAVIOR| BehaviorAgent[Behavior Analyzer Agent]
TaskRouter -->|ANALYZE_GRAPH| GraphAgent[Graph Analyst Agent]
EvidenceAgent --> TaskRouter
KYCAgent --> TaskRouter
BehaviorAgent --> TaskRouter
GraphAgent --> TaskRouter
TaskRouter -->|Tasks Complete| PlanChecker[Plan Satisfaction Checker]
PlanChecker -->|Missing Evidence / Loop < 2| TaskPlanner
PlanChecker -->|Plan Satisfied / Max Loops| TypologyNode[Typology Classifier Node]
TypologyNode --> ScoringNode[Weighted Risk Scoring Node]
ScoringNode --> CaseAssembler[Case Assembler & SAR Dossier Generator]
end
CaseAssembler -->|Persist InvestigationCase\nstatus = CLOSED| CaseDB[(investigation_cases Table)]
CaseDB -->|Complete Alert\nalerts.status = CLOSED| Repo
Fin-Spectra/
βββ app/
β βββ agents/
β β βββ nodes/ # Specialized Forensic Agent Nodes
β β β βββ behavior_analyzer.py # Velocity Z-Scores & baseline metrics
β β β βββ case_assembler.py # Grounded SAR dossier generator
β β β βββ evidence_retrieval.py# Database context aggregator
β β β βββ graph_analyst.py # Topological network & dispersion analyzer
β β β βββ kyc_verifier.py # Customer profile & risk verifier
β β β βββ plan_checker.py # Plan satisfaction & task completeness validator
β β β βββ scoring_node.py # Composite weighted risk scoring engine
β β β βββ task_planner.py # Dynamic task list planner
β β β βββ typology_classifier.py # Enforced typology classification node
β β βββ graph.py # LangGraph StateGraph & dynamic routers
β β βββ llm_client.py # Hardened Groq client with mock fallback
β β βββ state.py # InvestigationState TypedDict definition
β βββ api/
β β βββ routes_investigations.py # REST API endpoints
β βββ models/
β β βββ schema.py # SQLAlchemy ORM models & Pydantic schemas
β βββ repositories/
β β βββ alert_repository.py # Atomic Neon DB alert claim & lifecycle methods
β βββ config.py # Pydantic environment configuration
β βββ database.py # Database connection engine & sessionmaker
β βββ main.py # FastAPI application entrypoint
βββ run_investigation_demo.py # CLI Showcase Runner (Safe Mode & Live Mode)
βββ test_alert_lifecycle.py # Alert lifecycle synchronization unit test suite
βββ test_case_assembler_grounding.py # Dossier grounding & payload pruning test suite
βββ test_llm_client_reliability.py # LLM client reliability & production guard test suite
βββ test_neon_langgraph_pipeline.py # End-to-End Neon DB to LangGraph integration test suite
βββ test_typology_classifier_validation.py # Typology schema validation test suite
βββ .env.example # Environment variables template
βββ requirements.txt # Clean, minimal direct dependencies
βββ README.md # Documentation
- Python 3.10+ (Python 3.14 fully supported)
- PostgreSQL Database (e.g. Neon PostgreSQL or local PostgreSQL)
# Clone the repository
git clone https://github.com/vulcansmith-dev/Fin-Spectra.git
cd Fin-Spectra
# Create a virtual environment
python3 -m venv .venv
# Activate the virtual environment
source .venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtCopy .env.example to .env:
cp .env.example .envConfigure your credentials in .env:
# Groq LLM API Key (https://console.groq.com/keys)
GROQ_API_KEY="gsk_your_actual_groq_key_here"
# Model Selection
GROQ_MODEL="llama-3.3-70b-versatile"
# Mock Mode (Set to true to bypass Groq API for offline testing)
MOCK_LLM_MODE="false"
# Neon PostgreSQL Connection URL
DATABASE_URL="postgresql://user:pass@ep-host.neon.tech/neondb?sslmode=require"Runs the complete multi-agent pipeline on an alert without claiming or modifying any database records:
python run_investigation_demo.pyRuns in safe mode and outputs the formatted markdown Suspicious Activity Report (SAR) narrative:
python run_investigation_demo.py --show-dossierTarget a specific alert ID for investigation:
python run_investigation_demo.py --alert-id SYN_AL001Claims an alert (OPEN UNDER_INVESTIGATION), executes the graph, persists the InvestigationCase, and marks the alert CLOSED:
python run_investigation_demo.py --liveStart the FastAPI application server:
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload- API Server:
http://localhost:8000 - Swagger Interactive Docs:
http://localhost:8000/docs - ReDoc Documentation:
http://localhost:8000/redoc
POST /api/investigations/runβ Triggers a multi-agent investigation for a Phase-1 alert payload.GET /api/investigations/casesβ Lists all persisted investigation cases.GET /api/investigations/cases/{case_id}β Retrieves state snapshot for a specific case.
Run the full suite of automated unit and integration tests using pytest:
python -m pytest- Alert & Case Lifecycle Tests:
python test_alert_lifecycle.py
- End-to-End Neon DB Pipeline Integration:
python test_neon_langgraph_pipeline.py
- Typology Classifier Schema Validation:
python test_typology_classifier_validation.py
- Case Assembler Grounding & Payload Pruning:
python test_case_assembler_grounding.py
- LLM Client Reliability & Production Guard:
python test_llm_client_reliability.py
Distributed under the MIT License.