FDE in Action — AP Invoice Automation
A teaching-grade accounts-payable agent that pays clean invoices touchlessly, routes every exception to a human, and makes each judgment (deterministic / LLM / human) visible on screen.
Problem
AP teams touch nearly every invoice by hand — reading the PDF, matching it to a PO and goods receipt, checking the math, and deciding whether to pay. The boring 40–50% is pure cost; the dangerous minority (duplicates, bank-detail changes, blocked vendors) is where real money leaks.
Constraint
The system has to be exact and auditable where money is decided, yet still handle genuinely fuzzy work (messy document layouts, near-duplicate re-sends). Getting an LLM to add up numbers or compare thresholds is slower, dearer, and occasionally wrong at the one thing you most need to be right.
Architecture decision
The cheapest reliable option wins — deterministic Python owns the three-way match, tolerances, tax math, thresholds and exact-duplicate detection; the LLM is scoped to extraction, classification, fuzzy near-duplicate, GL suggestion and human-facing briefs, behind a cheap→strong model router. No agent framework, no vector DB (keyed SQL against a mock ERP), no fine-tuning. Every high-stakes action is human-in-the-loop; every decision is on an audit trail; every non-deterministic step is covered by an eval (recall = 1.0, zero false-negatives).
Notes
Two teaching layers on one screen. The FDE engagement loop — Frame → Audit → Judgment → Evals → Build → Deploy — each stage producing a first-class doc a non-engineer VP can read. And the three pillars of agent engineering — Harness (procedural + semantic memory, a tool catalog), Loop (verified-done, human-in-the-loop gates, a budget ceiling, stagnation guards, and policy-in-code that makes a hard-risk invoice physically unpayable), and LLM Ops (trace, evals, an LLM judge, and a lesson written back to memory).
The outer loop closes it: process a wave, project a governed policy change with the same deterministic engine (so the projection matches the next wave exactly), and promote it through a human gate — automation rises from ~43% to ~49% with zero hard-risk false-auto-pays.
The method behind this build is written up as a playbook: FDE + Loop Engineering: define the loop, not the code.
Live demo
Open demo ↗https://fde-in-action.vercel.appStill unfinished
- Serverless state is per-instance — queue approvals, promoted policy versions and accumulated waves reset on cold starts (the Docker single-container path keeps one durable SQLite file).
- Runs in offline-mock mode on the hosted demo; with a live API key, single-invoice replay and the resolution agent work, but "process whole stream" / a full wave can exceed the serverless function timeout.
- Offline extraction is a regex parser tuned to the synthetic layouts (100% by construction) — it proves the plumbing, not OCR robustness on real documents.