Inspiration

Every hackathon project I've seen treats AI as a tool for humans — an agent that shops for you, or an agent that pays a bill for you. But AI is increasingly doing work for other AI systems: one agent generates code, another generates images, another verifies output. In that world, there is no receipt layer. The worker agent has no safe way to bill the buyer agent, and the buyer has no trustworthy way to confirm what was delivered or what was paid.

I wanted to build that missing layer — but responsibly. The real problem isn't "let AI move money." It's how do you let AI assist financial workflows without letting it authorize them? That question became the core of AgentLedger: a multi-agent invoice verification and payment safety system.

What it does

AgentLedger runs two specialized AI-assisted components:

Agent A (Work Evaluation): Examines the original work requirements and the delivered work, and produces a recommendation — ACCEPT, REJECT, or REQUEST_REVISION — along with quantity and quality assessment.

Agent B (Invoice Processing): Extracts structured invoice information (buyer, description, amount, currency) from unstructured input, creates a PayPal Sandbox draft invoice, and prepares it for sending.

Between them sits independent Python safety validation. AI output is treated as a suggestion, never as an authorization. Critical financial actions require explicit human authorization, and every invoice and payment is independently verified before the order state advances.

The system demonstrates a full controlled flow: work evaluation → invoice extraction → validated draft invoice creation → reconciliation on uncertain responses → explicit buyer authorization → invoice sending → independent delivery verification → independent payment verification → persistent JSON order registry with protected state transitions.

How we built it

The project is a Python application with a clear separation between AI-assisted intelligence and deterministic safety logic.

The AI layer: Groq API handles invoice information extraction and delivered-work evaluation. Each agent has a focused responsibility rather than open-ended autonomy.

The safety layer: Independent Python functions validate buyer identity, description, amount, and currency before any invoice is created. AI output cannot bypass these checks.

The PayPal layer: Uses the PayPal Sandbox REST API (https://api-m.sandbox.paypal.com) to create draft invoices, with stable request IDs to prevent duplicate invoices on retry. When PayPal returns an uncertain response, the system reconciles rather than blindly retrying.

The authorization layer: Sending an invoice requires explicit buyer authorization. Opening a checkout does not mean payment succeeded.

The verification layer: Invoice SENT status is independently verified, and payment success is confirmed through independent PayPal verification — checking invoice ID, buyer, seller, amount, currency, and successful transaction IDs before an order can transition from SENT to PAID.

The persistence layer: A JSON order registry tracks orders with protected state transitions. Ordinary registry updates cannot mark an order PAID; only independent payment verification can.

The guiding principle throughout:

AI assists    →    Python validates    →    Human authorizes AI assists→Python validates→Human authorizes AI-generated decisions never directly authorize a financial operation.

Challenges we ran into

Balancing AI assistance against financial safety. The tempting design is to let the LLM "decide" and act. I deliberately inverted that: the LLM only recommends, and deterministic Python enforces the rules. This made the system less "autonomous" but far safer and easier to defend.

Handling uncertain PayPal responses. If an invoice creation call times out, you don't know whether an invoice was created. Retrying blindly risks duplicates. I solved this with stable request IDs plus a reconciliation step that checks for an existing invoice before any retry.

Preventing duplicate operations. Every financial action needs an idempotency strategy. Stable request IDs and registry-based state checks prevent double invoices and double processing.

Keeping order state honest. It would be easy for a normal registry update to flip an order to PAID. I restricted that transition so only independent payment verification can authorize SENT → PAID. Work acceptance, checkout opening, and sending an invoice are all distinct from payment success.

Testing financial logic. I built unit and integration tests to prove the safety properties hold — ultimately 172 total tests and 17 main integration tests passing, with no compilation errors and a clean application startup.

Accomplishments that we're proud of

We're proud that AgentLedger is not a thin wrapper around a payment API — it is a safety-first financial workflow where AI assists, Python validates, and humans authorize.

  1. A real safety boundary between AI and money. The core design principle is that AI output can never independently authorize a financial operation. Groq handles extraction and evaluation; independent Python validation enforces the rules; explicit buyer authorization gates invoice sending and checkout. This separation is baked into the architecture, not bolted on.

  2. Handling the hard financial edge cases. Most student payment projects assume the happy path. AgentLedger explicitly handles the failure modes: Stable request IDs prevent duplicate invoices on retry. Reconciliation resolves uncertain PayPal responses instead of blindly retrying. Independent invoice SENT verification confirms delivery rather than trusting that a call "succeeded." Independent payment verification (invoice ID, buyer, seller, amount, currency, successful transaction IDs) is the only path that can move an order to PAID.

  3. A protected order state machine. The persistent JSON order registry enforces strict transitions. Ordinary updates cannot mark an order PAID — only independent payment verification can authorize SENT → PAID. Work acceptance, checkout opening, and invoice sending are all treated as distinct events from payment success.

  4. Duplicate-operation prevention by design. Idempotency and registry-based state checks prevent double invoices and double processing — a property that matters far more in financial systems than any feature.

  5. Verified testing discipline. 172 total tests passing. 17 main integration tests passing. No compilation errors, successful application startup, and all 9 menu options verified. A clean, public GitHub repository (39 files) with .env, orders.json, and venv/ correctly excluded.

  6. Honest, controlled autonomy. We deliberately chose controlled autonomy over unrestricted autonomy. The flashy version of this idea is "two agents pay each other with zero humans." We built the version where AI assists, Python validates, and humans authorize — because that's the version that is testable, explainable, and safe. We're proud we didn't trade safety for a demo.

  7. A defensible architecture. Two specialized agents with clear, non-overlapping responsibilities, a deterministic safety layer, PayPal Sandbox integration, and a persistent registry — a clean system we can explain and defend end-to-end during evaluation.

What we learned

Agentic commerce is not "give an LLM a credit card." It needs a receipt layer, idempotency, reconciliation, and independent verification. Those are the real engineering problems.

Separating AI from authorization is a design discipline, not a feature. It shaped every module boundary in the project.

Uncertainty is the hard part. Network timeouts and ambiguous API responses are where financial systems break — so reconciliation and stable request IDs matter more than the happy path.

Honest scoping is a strength. The flashy version of this idea is "two agents pay each other with zero humans." I chose a safer, verifiable, controlled-autonomy design instead — and that's the version I can explain, test, and defend.

What's next for AgentLedger

Explicit negotiation protocol: structured REJECT with reasons and partial/revised invoice handling as a formal workflow.

Better requirements handling: generating a requirements.txt and a reproducible setup path.

Webhook-based payment confirmation: reacting to PayPal events rather than polling.

Multi-agent orchestration: an orchestrator that splits a task across several worker agents, with the same safety guarantees applied per invoice.

Expanded verification: richer reconciliation and audit logging for every state transition.

The long-term goal is the same as the original inspiration — a receipt layer for the agent economy — but built on a foundation where AI assists, Python validates, and humans authorize.

Built With

  • agents
  • automation
  • database
  • financial
  • fintech
  • git
  • github
  • groq
  • invoice
  • multi-agent
  • payment
  • rest
  • safety
  • sandbox
  • unit
  • unittest
  • vs
Share this project:

Updates

Submission history