Inspiration

Every accounts-payable team re-runs the same judgment on every invoice: does it match the PO, was it delivered, is the vendor trusted, have we paid this before, is that price change justified? It's repetitive, high-stakes, and error-prone — duplicate and fraudulent payments cost businesses billions. I didn't want another invoice-OCR bot. I wanted an AI that does the investigation and decides whether it's even allowed to act on its own.

What it does

APEX is an autonomous accounts-payable agent — an "AI finance employee." An invoice arrives and APEX:

  1. Extracts it with Qwen-VL (image → structured JSON).
  2. Investigates it with a Qwen3 reason→act→observe loop that calls real tools — purchase order, vendor, goods-receipt, and duplicate-scan lookups.
  3. Builds an evidence tree (PO-match %, delivery, vendor trust, duplicates, price deltas).
  4. Runs a policy engine that answers the real question: "Am I allowed to approve this?" — not "am I confident?"
  5. Auto-approves within policy, or escalates to a human with the full evidence attached.
  6. Writes every step to a cryptographically signed, hash-chained audit trail that detects tampering.

The differentiator is governance, not OCR. The agent's job isn't to be confident — it's to be permitted.

How I built it

  • Backend: FastAPI + SQLite; a custom Qwen3 tool-calling loop that is safe-by-default (any tool error escalates to a human).
  • Models via Qwen Cloud / DashScope (OpenAI-compatible endpoint): Qwen-VL for document understanding, Qwen3 for planning, policy reasoning, and the decision rationale.
  • Audit chain: ed25519 signatures over a SHA-256 hash chain (hash = SHA256(prev_hash + canonical_payload)); a verify endpoint re-walks the chain and flags any altered receipt.
  • Frontend: React + Vite — a live "Agent Console" that streams each tool call, plus Evidence and Audit screens.
  • Deploy: a single multi-stage Docker container (API + SPA on one port) on Alibaba Cloud ECS.
  • 33 backend tests; all four demo scenarios verified end-to-end against live Qwen models.

Challenges I ran into

  • Coherent demo data. Duplicate-detection didn't fire at first because the "resend" reused the same invoice ID and the scan excluded it as itself. Fixed by giving the duplicate a distinct ID with the same vendor+amount — exactly what a real duplicate payment looks like.
  • Same-origin frontend. The SPA defaulted its API base to localhost, so the deployed UI tried to call the viewer's own machine. Switched to same-origin relative calls so one container just works.
  • Registry friction. Function Compute requires an ACR image and free Personal-Edition ACR wasn't available on my account, so I deployed on ECS building straight from the public repo — simpler and fully reproducible.

What I learned

Framing an agent around authority ("what am I allowed to do") instead of confidence makes it genuinely enterprise-credible and easy to explain. Qwen-VL + Qwen3 compose cleanly through the OpenAI-compatible DashScope API.

What's next

Real ERP/email connectors, policies learned from human overrides, and external timestamp-anchoring of the audit chain for regulator-grade provenance.

Built With

Share this project:

Updates