Skip to content
reaatechREAATECH

Files · Anthropic Agent Mesh for E-commerce Fraud Detection

65 (1 binary, 714.6 kB total)attempt 1

README.md·5158 B·markdown
markdown
# Anthropic Agent Mesh for E-commerce Fraud Detection
 
A mesh of specialized Anthropic-powered agents that collaborate to detect and block e-commerce fraud in real time for small businesses.
 
## Problem
 
Small e-commerce companies lose revenue to fraud but lack the data-science teams to build multi-signal detection. A single LLM call misses patterns that require analyzing orders, payments, and customer behavior together.
 
## Architecture
 
```
Incoming Order (POST /api/evaluate-order)


  ┌─────────────┐
  │  Session    │  ← @reaatech/agent-mesh-session
  │  Manager    │
  └──────┬──────┘


  ┌─────────────┐
  │ Action Mesh │  ← @reaatech/agent-mesh-router
  │ Orchestrator│
  └──┬──┬──┬────┘
     │  │  │
     ▼  ▼  ▼
  ┌──┐ ┌──┐ ┌──┐
  │TA│ │AT│ │CR│   ← Three specialist agents
  └──┘ └──┘ └──┘
     │  │  │
     ▼  ▼  ▼
  ┌─────────────┐
  │ Confidence  │  ← @reaatech/agent-mesh-confidence
  │ Gate        │
  └──────┬──────┘
         │ route / clarify / fallback

  ┌─────────────┐
  │  Supabase   │  ← Fraud log persisted
  │  Fraud Log  │
  └─────────────┘


  { verdict, steps, confidence }
```
 
## Prerequisites
 
- Node.js >= 22
- pnpm 10.x
- Supabase project
- Anthropic API key
- Langfuse account (optional, for LLM tracing)
 
## Setup
 
```bash
pnpm install
cp .env.example .env
# Fill in your API keys and endpoints
pnpm dev
```
 
## Supabase table DDL
 
```sql
CREATE TABLE fraud_evaluations (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  order_id TEXT NOT NULL,
  verdict TEXT NOT NULL,
  steps JSONB NOT NULL,
  confidence FLOAT NOT NULL,
  overall_fraud_score FLOAT NOT NULL,
  created_at TIMESTAMPTZ DEFAULT now()
);
```
 
## API Usage
 
```bash
curl -X POST http://localhost:3000/api/evaluate-order \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": "ord-001",
    "customerId": "cust-42",
    "amount": 299.99,
    "currency": "USD",
    "timestamp": "2026-05-22T12:00:00Z",
    "paymentMethod": "credit_card",
    "billingAddress": "123 Main St",
    "shippingAddress": "456 Elm St",
    "email": "buyer@example.com",
    "phone": "+1-555-0100",
    "ipAddress": "192.168.1.1",
    "items": ["SKU-001", "SKU-002"],
    "cardFingerprint": "fp_abc123",
    "shippingSameAsBilling": false
  }'
```
 
Example response:
 
```json
{
  "result": {
    "orderId": "ord-001",
    "verdict": "review",
    "steps": [
      {
        "agentId": "transaction-anomaly",
        "verdict": "Anomaly score: 0.45 — unusual shipping pattern detected",
        "durationMs": 1234,
        "confidence": 0.7
      },
      {
        "agentId": "account-takeover",
        "verdict": "Takeover score: 0.12 — no indicators found",
        "durationMs": 987,
        "confidence": 0.75
      },
      {
        "agentId": "chargeback-risk",
        "verdict": "Risk score: 0.62 — moderate chargeback risk",
        "durationMs": 1102,
        "confidence": 0.8
      }
    ],
    "confidence": 0.75,
    "overallFraudScore": 0.40
  }
}
```
 
## How the agent mesh works
 
### Specialist agents
 
1. **Transaction Anomaly** — Detects unusual transaction patterns (high velocity, mismatched BIN, currency conversion, etc.)
2. **Account Takeover** — Identifies takeover indicators (new address on existing account, unusual geolocation, credential stuffing)
3. **Chargeback Risk** — Predicts chargeback probability based on order characteristics (digital goods, first purchase, high value)
4. **Human Review** — Escalation agent for borderline cases requiring manual review
 
### Confidence routing
 
The `evaluateConfidenceGate` decision tree from `@reaatech/agent-mesh-confidence` evaluates each agent's confidence score against its configured threshold:
 
- **Confidence ≥ threshold** → route to specialist agent
- **Below threshold + clarification enabled** → generate clarification question
- **Fallback** → route to default (human-review) agent
 
## Tech stack
 
| Package | Version | Purpose |
|---------|---------|---------|
| `@reaatech/agent-mesh` | 1.0.0 | Core domain types and constants |
| `@reaatech/agent-mesh-registry` | 1.0.0 | Agent YAML configuration loader |
| `@reaatech/agent-mesh-router` | 1.0.0 | MCP agent dispatch and routing |
| `@reaatech/agent-mesh-session` | 1.0.0 | Firestore session management |
| `@reaatech/agent-mesh-confidence` | 1.0.0 | Confidence-gated routing engine |
| `@reaatech/agent-mesh-observability` | 1.0.0 | Logging, metrics, and tracing |
| `@anthropic-ai/sdk` | 0.98.0 | Claude API client |
| `@supabase/supabase-js` | 2.106.1 | Supabase database client |
| `langfuse` | 3.38.20 | LLM observability |
| `zod` | 4.4.3 | Schema validation |
 
## Running tests
 
```bash
pnpm test
```
 
## License
 
MIT — see [LICENSE](./LICENSE).