GargiG15/Accounts_Payable_AI_Auditor_
AP Workflow OpenEnv ๐งพ
  
Overview
AP Workflow OpenEnv simulates the Accounts Payable (AP) invoice processing workflow โ a critical real-world finance task performed by every company on earth. AP clerks handle incoming invoices by:
- Validating invoice data against Purchase Orders (POs)
- Detecting fraudulent or duplicate invoices
- Routing high-value invoices for manager approval
- Posting approved invoices to the General Ledger (GL)
Humans spend 20โ40 hours/week on AP tasks. AI agents that can automate this accurately save enterprises millions annually. This environment enables RL researchers and agent developers to train and evaluate agents on this domain.
Why This Environment?
- Real-world utility: AP processing is a billion-dollar automation target. No existing OpenEnv covers financial document workflows.
- Multi-step reasoning: Requires reading structured data, cross-referencing POs, detecting anomalies, and making routing decisions.
- Fraud detection: Agents must identify signals like amount spikes, fake vendor names, and round-number patterns.
- Partial rewards: Dense reward shaping guides agents step-by-step rather than sparse end-of-episode signals.
Action Space
Actions are structured JSON with the following tools:
Example Action
{
"tool_call": "validate_data",
"parameters": {
"invoice_id": "INV-A1B2C3D4",
"amount": 1250.00,
"vendor_id": "V002"
},
"reasoning": "Checking if invoice amount matches PO approved amount within 5% tolerance"
}Observation Space
Each observation contains:
Invoice Object
{
"invoice_id": "INV-A1B2C3D4",
"vendor_name": "TechParts Ltd.",
"vendor_id": "V002",
"amount": 1250.00,
"date": "2025-01-15",
"due_date": "2025-02-14",
"po_number": "PO-XYZ123",
"line_items": [...],
"status": "pending",
"is_duplicate": false,
"is_fraudulent": false
}Tasks
Easy: Single Invoice Validation
- Max Steps: 20
- Description: Validate one basic invoice against a Purchase Order. Check amount, date, vendor, and post to the correct GL account.
- Grader:
1.0= Correctly validated + posted to correct GL0.7= Posted but wrong GL code0.5= Validated but not posted0.0= Valid invoice rejected- Expected baseline (GPT-4o): ~0.92
Medium: Fraud & Duplicate Detection
- Max Steps: 35
- Description: Process 3 invoices: 1 valid, 1 fraudulent, 1 duplicate. Correctly classify each.
- Grader:
(TP_fraud + TP_dup + TP_valid_posted) / total + 0.2 ร prevented_loss_ratio- False positives penalized at -0.1 each
- Expected baseline (GPT-4o): ~0.67
Hard: Full AP Cycle with Approvals
- Max Steps: 50
- Description: Process 5 invoices over a simulated 3-day cycle. Includes 1 high-value invoice requiring approval routing, 1 fraudulent, 1 duplicate. Must post all valid invoices to correct GL accounts.
- Grader:
0.4 ร validation_accuracy + 0.3 ร approval_routing_correct + 0.3 ร ledger_accuracy- Episode ends when all invoices processed or max steps reached
- Expected baseline (GPT-4o): ~0.41
Reward Function
Rewards are shaped to provide dense feedback throughout the episode:
Project Structure
ap-openenv/
โโโ openenv.yaml # OpenEnv metadata and task list
โโโ models.py # Pydantic: Observation, Action, Reward, StepResult
โโโ env.py # APWorkflowEnv: step() / reset() / state()
โโโ grader.py # Task-specific graders (0.0โ1.0)
โโโ data_generator.py # Invoice/PO generation with fraud injection
โโโ server.py # FastAPI OpenEnv endpoints
โโโ inference.py # Baseline inference script (OpenAI client)
โโโ Dockerfile # Container definition
โโโ requirements.txt # Python dependencies
โโโ README.md # This fileSetup & Usage
Local Development
# Install dependencies
pip install -r requirements.txt
# Start the server
python server.py
# โ Server running at http://localhost:8000
# In another terminal, run baseline
export OPENAI_API_KEY=sk-your-key
python inference.pyDocker
# Build
docker build -t ap-env .
# Run
docker run -p 8000:8000 ap-env
# Run baseline against dockerized env
export OPENAI_API_KEY=sk-your-key
export AP_ENV_URL=http://localhost:8000
python inference.pyHugging Face Spaces
Deploy directly to HF Spaces โ the server runs FastAPI on port 7860 (set PORT=7860).
API Reference
POST /reset
{"task_id": "single_invoice_validation", "seed": 42}POST /step
{
"tool_call": "validate_data",
"parameters": {"invoice_id": "INV-...", "amount": 1000.0},
"reasoning": "Checking fields"
}GET /state
Returns full internal state for debugging.
POST /grade
{"task_id": "single_invoice_validation"}Returns {"score": 0.92, "breakdown": {...}, "passed": true, "feedback": "..."}
Baseline Scores
Reproduce with:
export OPENAI_API_KEY=your-key
export MODEL_NAME=gpt-4o-mini
python inference.pyEnvironment Variables
License
MIT License โ see LICENSE.
