CoolFace
Apppublic

ps2181/invoice-processing-pipeline

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

<div align="center">

<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=6,11,20&height=200&section=header&text=Invoice%20Processing%20Pipeline&fontSize=40&fontColor=fff&animation=twinkling&fontAlignY=35&desc=Self-Improving%20Multi-Agent%20Fraud%20Detection%20%7C%20OpenEnv%20%2B%20GRPO%20%2B%20Qwen2.5&descAlignY=55&descSize=16" width="100%"/>

<p> <a href="https://ps2181-invoice-processing-pipeline.hf.space/web"> <img src="https://img.shields.io/badge/๐Ÿš€%20Live%20Demo-HuggingFace%20Spaces-FF9D00?style=for-the-badge&logo=huggingface&logoColor=white" /> </a> <a href="https://colab.research.google.com/drive/1C13giNt-NmbzKNFJr5L1fms3L8LfmB"> <img src="https://img.shields.io/badge/Training%20Colab-Open%20Notebook-F9AB00?style=for-the-badge&logo=googlecolab&logoColor=white" /> </a> <a href="https://ps2181-invoice-processing-pipeline.hf.space/docs"> <img src="https://img.shields.io/badge/API%20Docs-FastAPI-009688?style=for-the-badge&logo=fastapi&logoColor=white" /> </a> </p>

<p> <img src="https://img.shields.io/badge/Framework-OpenEnv-1A356E?style=for-the-badge" /> <img src="https://img.shields.io/badge/Model-Qwen2.5--1.5B%20+%20LoRA%20r%3D16-8B1A4E?style=for-the-badge" /> <img src="https://img.shields.io/badge/Training-GRPO%20+%20Unsloth-00A67E?style=for-the-badge" /> <img src="https://img.shields.io/badge/Agents-5%20Adversarial-E44D26?style=for-the-badge" /> </p>

<p> <img src="https://img.shields.io/badge/Tasks-10%20Progressive-6C3483?style=for-the-badge" /> <img src="https://img.shields.io/badge/Deployment-Docker%20%7C%20HF%20Spaces-0D1117?style=for-the-badge&logo=docker" /> <img src="https://img.shields.io/badge/Theme-%234%20Self--Improvement-FF6B35?style=for-the-badge" /> <img src="https://img.shields.io/badge/Hackathon-Meta%20PyTorch%202026-185FA5?style=for-the-badge" /> </p>

<br/>

Meta PyTorch OpenEnv Hackathon โ€” Grand Finale ยท April 25โ€“26, 2026 Team: Pritam Satpathy & Gnana Nawin T ยท VIT, Vellore

<br/>

<a href="https://git.io/typing-svg"> <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&weight=600&size=22&pause=1000&color=007A87&center=true&vCenter=true&width=750&lines=5-Agent+Adversarial+Fraud+Detection+System;Self-Improving+via+Cross-Episode+Regulator;GRPO-Trained+LoRA+Agents+on+Live+Environment;Invoice+%E2%86%92+Extract+%E2%86%92+Audit+%E2%86%92+Approve+%E2%86%92+Improve" alt="Typing SVG" /> </a>

</div>


๐Ÿ”ฅ The Core Idea

A system that continuously generates harder challenges targeting its own weakest points.

Most fraud detection pipelines are static. Ours gets harder for itself over time: the Regulator finds where the Auditor keeps failing, the Generator exploits those exact blind spots in the next episode, the Auditor's new mistakes update the Regulator โ€” and the loop closes without any human intervention.

Primary theme: #4 Self-Improvement ยท Secondary: #1 Multi-Agent Interactions

<div align="center"> <img width="1710" height="326" alt="5-agent self-improvement loop" src="https://github.com/user-attachments/assets/319654c3-aa24-47e8-9716-734d4e902168" /> </div>


๐Ÿค– 5-Agent Architecture

๐ŸŽฏ Regulator โ”€โ”€bias weightsโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โšก Generator
     โ–ฒ                                                                โ”‚
     โ”‚                                                      raw invoice text
     โ”‚ missed fraud types                                             โ–ผ
     โ”‚                                                         ๐Ÿ” Extractor
     โ”‚                                                                โ”‚
     โ”‚                                                     structured data
     โ”‚                                                                โ–ผ
     โ””โ”€โ”€โ”€โ”€ episode outcome โ”€โ”€โ”€โ”€ โœ… Approver โ—„โ”€audit resultsโ”€โ”€โ”€ ๐Ÿ•ต๏ธ Auditor

<div align="center">

AgentRoleReward Signal
๐ŸŽฏ RegulatorCross-episode oversight: detects Auditor blind spots, reweights GeneratorPrecision 0.35 + Recall 0.35 + No over-flagging 0.15 + Early warning 0.15
โšก GeneratorAdversary: creates invoices biased toward blind spots+0.85 evades both ยท +0.60 evades Auditor ยท +0.10 caught
๐Ÿ” ExtractorParser: text โ†’ structured JSON with 4 independent signalsFormat 0.10 ยท Field accuracy 0.40 ยท Math 0.25 ยท Completeness 0.25
๐Ÿ•ต๏ธ AuditorDetector: fraud classification with confidence scores+0.99 correct type ยท +0.90 clean cleared ยท +0.01 miss or FP
โœ… ApproverGatekeeper: final approve / escalate / rejectโ‰ฅ0.80 โ†’ reject ยท 0.50โ€“0.80 โ†’ escalate ยท <0.50 โ†’ approve

</div>


โšก Three Novel Features

<table> <tr> <td width="33%" align="center">

๐Ÿ”ฎ Predictive Regulator

Computes trend slopes over 5-episode windows.<br/>Warns of emerging blind spots before detection rates cross the critical threshold โ€” proactive oversight, not reactive retraining.

+0.15 early-warning bonus

</td> <td width="33%" align="center">

๐Ÿงฌ Compound Fraud

Invoices carry two fraud signals simultaneously (e.g. phantom vendor + price gouging).<br/>Partial credit +0.65 for catching one; full reward +0.99 for both.

Prevents single-signal heuristics.

</td> <td width="33%" align="center">

๐Ÿ“Š Confidence Calibration

Tracks (confidence, correct?) pairs per fraud type.<br/>Detects overconfident misses โ€” the Auditor saying "90% sure, approved" on fraud โ€” the most dangerous real-world failure mode.

</td> </tr> </table>


๐ŸŽฏ 10 Tasks โ€” Progressive Curriculum

<div align="center">

#TaskWhat the Agent FacesDifficulty
1easySingle clean invoice โ€” extract 5 fields๐ŸŸข Easy
2mediumBatch with date chaos, vendor typos, currency noise๐ŸŸก Medium
3hardExtraction + PO reconciliation โ€” flag overcharges, missing items๐ŸŸ  Hard
4expertFull fraud audit across all four fraud types๐Ÿ”ด Expert
5adversarialOCR corruption, SUBTOTAL traps, fake TAX/FX noise lines๐Ÿ”ด Expert
6negotiateAsk clarifying questions first (bonus for โ‰ค2), then extract๐ŸŸก Medium
7supply_chainDetect quantity shortfalls, price spikes, phantom deliveries๐Ÿ”ด Expert
8long_horizon20-step 4-phase investigation: extract โ†’ reconcile โ†’ audit โ†’ risk forecast๐Ÿ”ด Expert
9personalizedAdapts to your weak fields โ€” next invoice always targets your worst category๐Ÿ”„ Adaptive
10curriculumAuto-progresses easyโ†’mediumโ†’hardโ†’expert based on score (โ‰ฅ0.80 to advance)๐Ÿ”„ Auto

</div>

Dynamic difficulty also adjusts within each task via a rolling 10-episode score window: score above 0.85 โ†’ heavier OCR, more discrepancies, deeper traps. Drop below 0.60 โ†’ it eases off.


๐Ÿ“ˆ Training Results โ€” GRPO on Live Environment

All 3 agents trained with TRL GRPOTrainer + Unsloth using the deployed HF Space as the live reward verifier โ€” /grader endpoint is the reward function during training.

Before vs After Training

<div align="center">

AgentUntrained (random)Qwen 72B baselineAfter GRPOImprovement
๐Ÿ” Extractor0.100.670.914+714% vs random
๐Ÿ•ต๏ธ Auditor0.01โ€”0.52 live rewardDead โ†’ active signal
โšก Generatorโ€”โ€”0.22 plausibilityFormat & realism learned

</div>

Setup: Qwen2.5-1.5B-Instruct ยท 4-bit QLoRA r=16 ยท Unsloth + TRL ยท Google Colab A100

Extractor Reward Curve

Extractor Training X-axis: training step (1โ€“20) ยท Y-axis: reward (0โ€“1). Left: total GRPO reward across 4 independent signals (format 0.10 + field accuracy 0.40 + math 0.25 + completeness 0.25). Right: live `/grader` score peaking at 0.914 โ€” above Qwen 72B baseline (0.67) and untrained 1.5B (0.46).

Left: Total GRPO reward across 4 signals (format + field + math + completeness) over 20 training steps. Right: Live environment grader score peaking at 0.914 โ€” above Qwen 72B baseline (0.67) and untrained 1.5B baseline (0.46).

Auditor Reward Curve (Run 2 โ€” Bug Fixed)

Auditor Training Run 2 X-axis: training step (1โ€“30) ยท Y-axis: reward (0โ€“1). Total reward (blue) and live env reward (orange) with ยฑ1 std band. Best total: 0.719 at step 10. Live env reward climbed from 0.01 (dead signal, Run 1) to 0.52 after fixing the TRL episode_id list indexing bug.

Total reward (blue) and live env reward (orange) over 30 steps with ยฑ1 std band. Best total reward: 0.719. Live env reward rose from 0.01 (dead signal in Run 1) to 0.52 after fixing the episode_id list bug.

Generator Reward Curve

Generator Training X-axis: training step (1โ€“30) ยท Y-axis: reward (0โ€“1). Live evasion reward (red) flat near 0 โ€” Auditor+Approver caught all fraud attempts. Fraud plausibility reward (orange dashed) stable at ~0.20 โ€” Generator learned realistic invoice structure even without successful evasion.

Live evasion reward (red) flat near 0 โ€” Auditor+Approver caught all fraud attempts. Fraud plausibility reward (orange dashed) learned and stable at ~0.20, showing the Generator learned to produce realistic-looking invoices even without successful evasion.

๐Ÿ” Reward Hacking Caught at Step 10

At step 10 the model achieved math_consistency = 0.97 and completeness = 1.0 while field_accuracy = 0.00 โ€” it had learned to output arithmetically-consistent JSON with entirely hallucinated values:

Step 10 โ€” Reward Hacking Detected:
  format:            0.10  โœ…
  math_consistency:  0.97  โœ… โ† model gaming this signal
  completeness:      1.00  โœ… โ† model gaming this signal
  field_accuracy:    0.00  โŒ โ† hallucinating all values

  Action: adjusted training emphasis on field_accuracy weight
  Result: field_accuracy climbed to 0.30+ by step 30

Without 4 independent signals, a single aggregated reward would have called this success. Independent signals are diagnostics, not just incentives.

Auditor Training โ€” Run 2 (exact data)

<div align="center">

StepTotal RewardLive Env RewardยฑStd
50.48280.2828ยฑ0.194
100.71880.5188ยฑ0.239
150.45380.2538ยฑ0.123
200.57330.3733ยฑ0.212
250.53250.3325ยฑ0.232
300.60380.4038ยฑ0.147

Run 1 (dead signal): live env reward flat at 0.010 โ€” TRL passes episode_id as a list; old code sent the whole list instead of indexing per completion

</div>


๐ŸŽ Reward Architecture

๐Ÿ” Extractor โ€” 4 Independent Signals

python
reward_format(extracted)             # 0.10 โ€” all 5 required JSON keys present?
reward_field_accuracy(extracted, gt) # 0.40 โ€” vendor / date / currency / total match?
reward_math_consistency(extracted)   # 0.25 โ€” qty ร— unit_price = amount per line?
reward_completeness(extracted, gt)   # 0.25 โ€” all expected line items captured?

# All clamped to (0.01, 0.99) โ€” no log(0), no gradient collapse at boundaries

๐Ÿ•ต๏ธ Auditor

<div align="center">

OutcomeRewardWhy
Correct fraud type detected0.99Rewards precise classification, not just binary flagging
Clean invoice correctly approved0.90Keeps false-positive rate honest
Compound fraud โ€” one of two types caught0.65Partial credit prevents cliff on hard cases
Fraud flagged but wrong type0.50Penalises sloppiness; rewards catching something
Miss or false positive0.01Near-zero punishes both failure modes symmetrically

</div>

โšก Generator (Adversarial Self-Play)

OutcomeReward
Fraud evades both Auditor and Approver0.85
Auditor misses, Approver catches0.60
Auditor catches it0.10

๐ŸŽฏ Regulator โ€” Cross-Episode

Total = Precision(0.35) + Recall(0.35) + No-over-flagging(0.15) + Early-warning-bonus(0.15)

The early-warning bonus rewards predictions of emerging blind spots โ€” before detection rates cross the critical threshold.


๐Ÿง  Trained LoRA Agents

<div align="center">

AgentBase ModelLoRA ConfigHuggingFace Hub
๐Ÿ” ExtractorQwen2.5-1.5B-Instructr=16, ฮฑ=16, 4-bit QLoRAps2181/extractor-lora-qwen2.5-1.5b
๐Ÿ•ต๏ธ AuditorQwen2.5-1.5B-Instructr=16, ฮฑ=16, 4-bit QLoRAps2181/auditor-lora-qwen2.5-1.5b
โšก GeneratorQwen2.5-1.5B-Instructr=16, ฮฑ=16, 4-bit QLoRAps2181/generator-lora-qwen2.5-1.5b

</div>

LoRA target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj


๐ŸŒ The Regulator in Action

After each episode, the Regulator publishes a report the Generator uses to bias its next batch:

GET /regulator/report

{
  "total_audits_recorded": 20,
  "detection_rates": {
    "phantom_vendor":        "31%  โš  BLIND SPOT (-0.08โ†“)",
    "price_gouging":         "74%  โœ“ OK (+0.03โ†‘)",
    "math_fraud":            "81%  โœ“ OK (+0.01โ†‘)",
    "duplicate_submission":  "62%  โšก EMERGING (-0.02โ†“)"
  },
  "blind_spots": ["phantom_vendor"],
  "emerging_blind_spots": ["duplicate_submission"],
  "generator_weights": {
    "phantom_vendor":       0.30,    โ† 3ร— upweighted (blind spot)
    "duplicate_submission": 0.20,    โ† 2ร— upweighted (emerging)
    "price_gouging":        0.125,
    "math_fraud":           0.125,
    "compound_fraud":       0.10
  },
  "verdict": "Recommend retraining on: phantom_vendor"
}

๐ŸŽญ Sample Multi-Agent Episode

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  MULTI-AGENT PIPELINE  ยท  LIVE EPISODE
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

  ๐ŸŽฏ  REGULATOR  (30-episode rolling window)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  phantom_vendor     31%  โš  BLIND SPOT  โ† prioritised 60%
  price_gouging      74%  โœ“ OK
  math_fraud         81%  โœ“ OK
  duplicate          62%  โœ“ OK

  โšก  GENERATOR  (Qwen2.5 LoRA)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Fraud focus : phantom_vendor (60% Regulator weight)
  Vendor      : ShadowByte Technologies  โ† not in registry

  ๐Ÿ”  EXTRACTOR  (Qwen2.5 LoRA)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Reward : 0.847  [format 0.10 ยท field 0.38 ยท math 0.25 ยท completeness 0.12]

  ๐Ÿ•ต๏ธ  AUDITOR  (Qwen2.5 LoRA)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  INV-85529  โ†’  ๐Ÿšจ FLAGGED  [PHANTOM VENDOR]  conf=0.91
  INV-85530  โ†’  โœ… APPROVED                   conf=0.88

  โœ…  APPROVER
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  INV-85529  โ†’  โŒ REJECT
  Generator reward : 0.60  (evaded Auditor on 1/3, Approver caught)

  ๐ŸŽฏ  REGULATOR UPDATE
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  phantom_vendor detection: 31% โ†’ 45%  โ†‘ improving
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿš€ Quick Start

bash
# Health check
curl https://ps2181-invoice-processing-pipeline.hf.space/health

# Environment-wide metrics
curl https://ps2181-invoice-processing-pipeline.hf.space/metrics

# Auto-progressive curriculum episode
curl -X POST https://ps2181-invoice-processing-pipeline.hf.space/reset \
  -H "Content-Type: application/json" -d '{"task_id": "curriculum"}'

# Start multi-agent episode
curl -X POST https://ps2181-invoice-processing-pipeline.hf.space/multi/reset

# Regulator blind spot report
curl https://ps2181-invoice-processing-pipeline.hf.space/regulator/report

Run Training (Google Colab)

![Open In Colab](https://colab.research.google.com/drive/1C13giNt-NmbzKNFJr5L1fms3L8LfmB)

Colab โ†’ /reset (fresh synthetic invoice from live environment)
      โ†’ model generates JSON
      โ†’ /grader scores against ground truth
      โ†’ GRPO updates weights toward higher-reward completions
      โ†’ repeat 200 steps

๐Ÿ—‚๏ธ Repository Structure

invoice-processing-pipeline/
โ”‚
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ app.py                      # FastAPI โ€” 18 endpoints
โ”‚   โ”œโ”€โ”€ environment.py              # 10 tasks ยท graders ยท dynamic difficulty
โ”‚   โ”œโ”€โ”€ multi_agent_environment.py  # 5-agent system + AuditorPerformanceTracker
โ”‚   โ”œโ”€โ”€ agents.py                   # Lazy-loading LoRA inference wrappers
โ”‚   โ””โ”€โ”€ web_ui.py                   # Gradio UI (mounted at /web)
โ”‚
โ”œโ”€โ”€ models.py                       # Pydantic: Action ยท Observation ยท State
โ”œโ”€โ”€ inference.py                    # Standalone inference helper
โ”œโ”€โ”€ client.py                       # OpenEnv-compatible Python client
โ”‚
โ”œโ”€โ”€ extractor_training_grpo.ipynb   # ๐Ÿ”ฅ Extractor GRPO training (Unsloth + TRL)
โ”œโ”€โ”€ auditor_grpo_training.ipynb     # ๐Ÿ”ฅ Auditor GRPO training
โ”œโ”€โ”€ generator_grpo_training.ipynb   # ๐Ÿ”ฅ Generator GRPO training
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ reward_curve.png            # Extractor training curve
โ”‚   โ”œโ”€โ”€ auditor_reward_curve_run2.png
โ”‚   โ””โ”€โ”€ generator_reward_curve.png
โ”‚
โ”œโ”€โ”€ openenv.yaml                    # OpenEnv manifest (all tasks declared)
โ”œโ”€โ”€ Dockerfile                      # HF Spaces Docker (port 7860, non-root UID 1000)
โ”œโ”€โ”€ pyproject.toml                  # Project metadata + dependencies
โ”œโ”€โ”€ requirements.txt                # Runtime dependencies
โ”œโ”€โ”€ validate-submission.sh          # Submission validator script
โ”œโ”€โ”€ BLOG.md                         # HuggingFace blog post
โ””โ”€โ”€ ROUND2_PROBLEM_STATEMENT.md     # Full problem statement + reward design rationale

๐Ÿ”Œ API Reference

Core OpenEnv

EndpointMethodDescription
/healthGETHealth check โ†’ {"status": "ok", "active_sessions": N}
/tasksGETAll tasks with descriptions, schemas, difficulty levels
/metricsGETPer-task episode counts, avg/best scores, Regulator state
/resetPOSTStart episode `{"task_id": "easy\medium\...\curriculum"}`
/stepPOSTSubmit extraction โ†’ reward + feedback + hint + reward_breakdown
/graderPOSTScore without consuming an attempt (training reward signal)
/stateGETEpisode metadata โ€” stepcount, done, bestreward, history
/wsWSFull episode over WebSocket (OpenEnv standard)
/webGETGradio interactive demo UI

Multi-Agent

EndpointMethodDescription
/multi/resetPOSTStart 5-agent episode โ€” Generator biased by Regulator weights
/multi/extractPOSTScore Extractor output (4 independent signals)
/multi/auditPOSTScore Auditor output, update 30-episode performance tracker
/multi/approvePOSTRun Approver, compute Generator adversarial reward
/multi/state/{id}GETFull episode state including all agent scores
/generator/scorePOSTDirect Generator scoring through Auditor+Approver pipeline

Regulator

EndpointMethodDescription
/regulator/reportGETDetection rates, blind spots, calibration, generator weights
/regulator/forecastGETTrend slopes + emerging blind spot warnings with episode countdown
/regulator/calibrationGETOverconfidence / underconfidence per fraud type
/regulator/predictPOSTScore a Regulator blind-spot prediction
/regulator/demo_seedPOSTSeed tracker with realistic demo data

๐Ÿ—๏ธ Tech Stack

<div align="center">

LayerTechnology
EnvironmentOpenEnv ยท FastAPI ยท Pydantic v2
UIGradio 4.x (mounted at /web)
DeploymentDocker ยท HuggingFace Spaces (vcpu-2 / 8 GB)
TrainingTRL GRPOTrainer ยท Unsloth
Modelunsloth/Qwen2.5-1.5B-Instruct ยท 4-bit QLoRA ยท r=16 ยท A100
RewardLive /grader endpoint on HF Space as verifier
Session MgmtThread-safe OrderedDict ยท 200-session cap ยท LRU eviction
Dynamic DifficultyPer-task rolling window (maxlen=10) โ†’ adjusts OCR intensity, batch size, discrepancy count

</div>


๐ŸŽญ Theme Alignment

<div align="center">

ThemeAlignmentEvidence
#4 Self-Improvement (primary)โœ… CoreRegulator detects blind spots โ†’ Generator biases toward them โ†’ Auditor improves โ†’ loop repeats
#1 Multi-Agent Interactionsโœ… Core5 agents with conflicting incentives โ€” Generator vs Auditor adversarial self-play
#1 Fleet AI Scalable Oversightโœ… BonusRegulator monitors Auditor cross-episode with predictive trend detection
#3.1 Professional Tasksโœ… CoreInvoice + PO + vendor registry + supply chain = real enterprise AP workflow
#2 Long-Horizon Planningโœ… Partiallong_horizon task: 20-step 4-phase investigation with multi-turn state

</div>


๐Ÿ‘ฅ Team

<div align="center">

Pritam SatpathyGnana Nawin T
๐Ÿค— ps2181๐Ÿค— gnananawin
Scaler School of TechnologyScaler School of Technology

Meta PyTorch OpenEnv Hackathon โ€” Grand Finale ยท April 25โ€“26, 2026 ยท Bangalore

</div>


๐Ÿ”— All Links

<div align="center">

ResourceLink
๐Ÿš€ Live Environmenthttps://ps2181-invoice-processing-pipeline.hf.space
๐Ÿ–ฅ๏ธ Gradio Demo UIhttps://ps2181-invoice-processing-pipeline.hf.space/web
๐Ÿ“– API Documentationhttps://ps2181-invoice-processing-pipeline.hf.space/docs
๐Ÿ“Š Metrics Dashboardhttps://ps2181-invoice-processing-pipeline.hf.space/metrics
๐Ÿ“ Blog Posthttps://github.com/ps2181/invoice-processing-pipeline/blob/main/BLOG.md
๐Ÿค— Extractor Modelhttps://huggingface.co/ps2181/extractor-lora-qwen2.5-1.5b
๐Ÿ•ต๏ธ Auditor Modelhttps://huggingface.co/ps2181/auditor-lora-qwen2.5-1.5b
โšก Generator Modelhttps://huggingface.co/ps2181/generator-lora-qwen2.5-1.5b
๐Ÿ““ Training Colab (Auditor Agent)https://colab.research.google.com/drive/1C13giNt-NmbzKNFJr5L1fms3L8LfmB
๐Ÿ““ Training Colab (Extractor Agent)https://colab.research.google.com/drive/1fxfBt13LjmT4m98pJq-b5B__1ytFeszK?usp=sharing
๐Ÿ““ Training Colab (Generator Agent)https://colab.research.google.com/drive/1O293_VBZQCthxlGpgvz5kxoty3zcsWGH?usp=sharing
๐Ÿ’ป GitHubhttps://github.com/ps2181/invoice-processing-pipeline
๐ŸŽฅ Demo Videohttps://youtu.be/QSB4UOLvaC8?si=SGnIwsfTW4JGsU3e
๐Ÿงฉ OpenEnv Frameworkhttps://github.com/meta-pytorch/OpenEnv

</div>


<div align="center">

<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=6,11,20&height=100&section=footer&animation=twinkling" width="100%"/>

Built with โค๏ธ for the Meta PyTorch OpenEnv Hackathon 2026

"The system that gets harder for itself โ€” so the agent never stops learning."

</div>