AI (artificial intelligence) Learning · 01 / 08

Accounts-Payable Invoicing Example

A complete, generic AI system for invoice processing: architecture decisions, pipeline DAG (Directed Acyclic Graph), AI-driven lifecycle, enterprise MCP (Model Context Protocol) gateway and RAG (Retrieval-Augmented Generation) over contracts, end to end.

The scenario

A mid-sized manufacturer (Example Manufacturing, fictional) receives several thousand supplier invoices a month by email, through a supplier portal and by SFTP (SSH File Transfer Protocol) from a few large vendors. Today, clerks key each one into the ERP (Enterprise Resource Planning), chase purchase orders and goods receipts by hand, and email approvers. Invoices wait a week, duplicates slip through, and month-end accruals are guesswork.

The goal is an accounts-payable invoicing system that reads each invoice, checks it against what was ordered and received, applies approval policy, posts it to the ERP and schedules payment — with a person deciding only what the rules cannot.

Everything here is fictional and illustrative: the company, vendors, invoices, document numbers, tolerances and targets are invented for the demo. The architecture and the tradeoffs are the point.

Architecture

Architecture of the invoicing system Invoices arrive from email, a supplier portal or SFTP. A DAG orchestrator runs deterministic steps, calls document AI for extraction, and hands exceptions to an agent. The agent uses enterprise tools through an MCP gateway and retrieves contract clauses from a RAG index. Human reviewers decide exceptions. Every step writes to the audit store. Invoice sources email · portal · SFTP DAG orchestrator deterministic steps, retries, idempotency Document AI LLM + JSON schema ERP & ledger AP, GL, payments extract post Exception agent plans, calls tools, drafts a resolution Enterprise MCP SSO · scopes · audit exceptions only tools post via gateway Knowledge (RAG) contracts · policy · pricing Human review approve · reject · query Audit & observability traces · evals · logs retrieve deterministic step LLM or gateway agent human decision
One pipeline, one agent, one gateway, one knowledge index: each part does a single job.

Each component has one job. A DAG orchestrator sequences the pipeline and owns retries. Document AI turns PDFs (Portable Document Formats) into schema-checked fields. Deterministic rules decide matching and approval. An exception agent handles only the cases the rules reject, using enterprise tools through an MCP gateway and clauses from a RAG index. Human reviewers decide what remains.

The parts, and where each is covered

DAG orchestrator

Ordered steps, retries, idempotency keys and a run history. See DAG orchestration.

Architecture decisions

Why each choice was made, what it cost, and what was rejected. See the ADR (Architecture Decision Record) log.

AI-driven lifecycle

How the system was specified, built, verified and is operated with AI in the loop. See the AI-DLC (AI-Driven Development Lifecycle) page.

Enterprise MCP gateway

The only door to ERP, vendor master, POs (Purchase Orders), receipts and approvals, with scopes and audit. See the MCP page.

RAG over contracts

Retrieves the clause that governs a disputed charge, with citations and grounding checks. See the RAG page.

End-to-end walkthrough

One invoice followed through every stage, with the data at each step.

Requirements and targets

These are the requirements the design was built against. The targets are planning figures for this demo, not measured results.

AreaRequirementIllustrative target
IntakeAccept email, portal and SFTP invoices; keep the original file100% of inbound documents recorded
AccuracyExtracted fields checked against schema and totalsZero invoices posted with failed schema checks
MatchingThree-way match to PO and goods receipt, with tolerancesClean matches need no human touch
ExceptionsExplain each exception with the governing contract clauseEvery exception carries at least one citation
ApprovalApproval bands by amount, cost centre and exception typeRouting decided by rules, never by the model
Cycle timeReceipt to ERP postingMedian under one business day for clean invoices
AuditEvery step, tool call and decision traceableComplete trace for 100% of posted invoices
SecurityNo agent holds system credentials; PII (Personally Identifiable Information) minimisedAgents reach systems only through the gateway

Suggested reading order

  1. 1 · Walkthrough

    Follow one invoice from arrival to payment to see the system working.

  2. 2 · ADRs

    Read the decisions behind the shape of the system.

  3. 3 · DAG

    See how the pipeline is sequenced and where retries and humans sit.

  4. 4 · MCP

    See how the agent and workers reach enterprise systems safely.

  5. 5 · RAG

    See how contract and policy answers are grounded and checked.

  6. 6 · AI-DLC

    See how the whole system was delivered and is run.

Build this for your business

This example uses a generic invoicing system, but the same pattern — orchestrated steps, governed tools, grounded knowledge and a documented lifecycle — fits most back-office processes. We can scope a pilot on your own documents and systems.

Book a discovery call