CoolFace
Apppublic

sagar-03/invoice-processing-agent

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

๐Ÿงพ Invoice Processing Agent โ€” OpenEnv

An OpenEnv environment where an AI agent processes invoices and decides whether to approve, reject, or flag them for human review.

Why This Problem?

Invoice processing is one of the most time-consuming tasks in any organization. Finance teams manually review hundreds of invoices weekly, checking for duplicates, anomalies, missing fields, and fraud signals. This environment simulates that workflow so AI agents can learn to automate it.


Action Space

FieldTypeValues
decisionstringapprove, reject, flag
reasonstringShort explanation (free text)

Observation Space

FieldTypeDescription
invoice_idstringUnique invoice identifier
vendorstringVendor name (may be empty)
amountfloatInvoice total
currencystringCurrency code (USD, EUR, etc.)
datestringInvoice date
line_itemslist[dict]Individual line items
flagslist[str]Detected anomalies
doneboolIs the episode over?
rewardfloatReward for the last step
messagestringHuman-readable feedback

Tasks

TaskDifficulty# InvoicesDescription
easy_triageEasy3Clear approve/reject signals
medium_triageMedium4Duplicates, over-budget, multi-vendor
hard_triageHard5Missing fields, currency mismatches, anomalies

Reward Function

OutcomeReward
Correct decision+0.99
Cautious flag (flag instead of reject/approve)+0.30
Wrong decision+0.01
Reward range: (0, 1] (Strictly between 0 and 1 as per Phase 2 requirements)

Baseline Scores

TaskScore
easy_triage1.00
medium_triage0.75
hard_triage0.60

Setup & Usage

Local

bash
pip install -r requirements.txt
python -m uvicorn server.app:app --reload --port 7860

With uv (recommended)

bash
uv sync
uv run server

Docker

bash
docker build -t invoice-env .
docker run -p 7860:7860 invoice-env

Run Inference

Linux / macOS:

bash
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct
export HF_TOKEN=hf_your_token_here
export ENV_URL=https://sagar-03-invoice-processing-agent.hf.space
python inference.py

Windows (PowerShell):

powershell
$env:API_BASE_URL="https://router.huggingface.co/v1"
$env:MODEL_NAME="meta-llama/Llama-3.1-8B-Instruct"
$env:HF_TOKEN="hf_your_token_here"
$env:ENV_URL="https://sagar-03-invoice-processing-agent.hf.space"
python inference.py

Environment Variables

VariableRequiredDefaultDescription
API_BASE_URLNohttps://router.huggingface.co/v1LLM API endpoint
MODEL_NAMENometa-llama/Llama-3.1-8B-InstructModel identifier for inference
HF_TOKENYesโ€”HuggingFace API token
ENV_URLNohttps://sagar-03-invoice-processing-agent.hf.spaceOpenEnv server URL

API Endpoints

EndpointMethodDescription
/resetPOSTStart a new episode
/stepPOSTSubmit a decision
/stateGETGet current episode state
/tasksGETList tasks + action schema
/graderPOSTGet final episode score
/baselinePOSTRun rule-based agent, returns scores for all 3 tasks
/healthGETHealth check

Example Usage

python
import requests

BASE = "http://localhost:7860"

# Start episode
obs = requests.post(f"{BASE}/reset", json={"task_name": "easy_triage"}).json()

while not obs["done"]:
    # Agent decides
    action = {"decision": "approve", "reason": "Looks valid"}
    result = requests.post(f"{BASE}/step", json=action).json()
    obs = result["observation"]
    print(obs["message"])

# Get final score
score = requests.post(f"{BASE}/grader").json()
print(f"Score: {score['score']}")