AFTERPACT — Making AI-Powered Commerce Accountable

Inspiration

AI agents are rapidly becoming capable of searching for products, comparing offers, and completing purchases on behalf of people. But there is a critical gap in this evolution: what happens after the payment?

Imagine asking an AI agent to order a specific product for you. It finds an offer, checks out, and confirms the purchase. Then the wrong item arrives, the delivery is incomplete, the price changes, or the merchant fails to deliver.

Who is responsible? What exactly did the agent promise? Can the buyer prove what was agreed? And can the problem be resolved without navigating a long, frustrating support process?

Most agentic-commerce demonstrations focus on making the purchase. We wanted to tackle the much harder question: making the outcome trustworthy.

That idea became AFTERPACT: the assurance layer for agentic commerce.

Our guiding principle is simple:

AI can make the purchase. It should never have unlimited authority over the promise, the money, or the recovery.

What we built

AFTERPACT transforms an AI-driven purchase into a verifiable, policy-controlled lifecycle.

Instead of treating checkout as the end of a transaction, AFTERPACT follows the purchase from the initial request through delivery and, when necessary, recovery.

The lifecycle has nine stages:

  1. Intent: The buyer describes what they want in natural language. AI interprets the request into structured, validated purchase criteria.
  2. Discovery: The system identifies and ranks suitable offers, with live Channel3 discovery when configured.
  3. PurchasePromise: The selected offer becomes a versioned, hash-chained commitment containing the merchant, items, total, and delivery expectations.
  4. Approval: The buyer explicitly approves the exact promise version and hash. Material changes invalidate the previous approval.
  5. Payment: PayPal Orders v2 handles the payment lifecycle, including captures and refunds. The integration uses idempotency and webhook verification.
  6. Monitoring: Delivery and purchase outcomes are compared against the original promise.
  7. Incident detection: A mismatch, missing item, incorrect amount, or delivery problem can trigger an incident.
  8. Resolution: AI analyzes the available evidence and proposes a recovery action. Deterministic policy checks constrain the proposal; it cannot execute itself.
  9. Verified recovery: The operator makes the decision, the refund is validated against the captured amount, and the provider response is verified before the case is closed.

Every important transition is recorded in the Flight Recorder, an append-only, hash-chained audit trail that makes the transaction inspectable and replayable.

The result is not simply an AI shopping assistant. It is an accountability system for commerce performed by AI agents.

How we built it

We designed AFTERPACT around a separation of responsibilities:

  • AI interprets and recommends.
  • Deterministic code validates and enforces policy.
  • The buyer approves material commitments.
  • The payment provider executes financial operations.
  • The Flight Recorder preserves evidence.

This distinction is fundamental. An AI model can misunderstand an instruction, encounter malicious content, or produce an incorrect recommendation. It should therefore never be the final authority on whether money can move or whether a refund is permitted.

The core architecture

We built the application with TypeScript, Node.js, and a modular architecture separating the domain, policy engine, payments, AI, API, and web interface.

The main components include:

PurchasePromise and lifecycle engine

Each purchase is represented by a versioned commitment. Its integrity is protected through hashing and a linked history. Approvals are tied to a specific version, preventing an agent from silently changing the merchant, price, or other material terms after approval.

Deterministic policy engine

Before sensitive actions are allowed, the policy engine evaluates them and returns an explicit decision: Cleared, Hold, or Refused, with structured reason codes.

This also provides protection against prompt-injection attempts and unauthorized changes to purchase details.

PayPal integration

PayPal is central to the payment architecture, not an ornamental checkout button. We integrated Orders v2, captures, refunds, OAuth token caching, request idempotency, webhook verification, deduplication, and a payment kill switch.

The implementation defaults to sandbox operation. Live payment mode requires explicit configuration and an additional safety flag.

Vultr AI inference

Vultr Inference powers AI-assisted intent extraction, incident analysis, recovery proposals, and the Studio agent when credentials are configured.

AI output is validated before it enters the application. When inference is unavailable, clearly labeled deterministic or heuristic fallbacks preserve the functionality without pretending that an AI model was used.

Flight Recorder and recovery timeline

The Flight Recorder provides a verifiable history of the transaction. The recovery timeline helps operators understand what happened, when it happened, and what actions remain possible.

Sponsor technologies

We integrated AG Grid for data-heavy interfaces and the AG Grid Agent Studio framework for the agent workspace. Channel3 provides a live product-discovery path when configured. We deliberately distinguish integrated technologies from documented upgrade paths rather than claiming integrations that are not present.

Challenges we faced

1. Giving AI useful autonomy without giving it control over money

The hardest architectural challenge was deciding where AI should stop and deterministic enforcement should begin.

We wanted AI to handle ambiguous language, understand incidents, and suggest intelligent recovery actions. But allowing a model to independently authorize payments or refunds would create unacceptable risks.

We solved this by placing deterministic policy gates between AI recommendations and sensitive operations. AI proposes; the system validates; an authorized human decides where required.

2. Preserving the integrity of a purchase over time

A purchase is not a static object. Offers can change, merchants can modify terms, and delivery outcomes can differ from expectations.

We needed a way to prove exactly what the buyer approved. The versioned, hash-chained PurchasePromise and approval binding ensure that material changes cannot silently inherit an earlier authorization.

3. Making payment operations reliable

Financial operations introduce difficult edge cases: duplicated requests, timeouts, webhook retries, partial refunds, and inconsistent provider responses.

We implemented idempotency, webhook verification and deduplication, explicit error mapping, capture-bound refund validation, and a kill switch. We also maintained a deterministic mock transport for reproducible demonstrations and tests, with clear labels distinguishing simulated operations from real PayPal Sandbox responses.

4. Making the demonstration honest and reproducible

A system that appears to work only when every API key is configured is difficult to evaluate.

We therefore built a deterministic flagship demonstration that can run without external credentials. Live integrations unlock when configured, and the interface identifies whether information comes from a real provider, a simulation, or a deterministic fallback.

This was important to us: a judge should be able to understand exactly what happened rather than having to trust a screenshot or an impressive-looking AI response.

What we learned

Building AFTERPACT reinforced several important lessons:

  • Autonomy and accountability are different problems. Making an agent capable of taking action does not make that action safe or trustworthy.
  • AI should not be the security boundary. Critical financial decisions need deterministic validation, explicit authorization, and enforceable constraints.
  • Evidence is a product feature. A verifiable history is valuable not only for debugging but also for buyers, merchants, operators, and dispute resolution.
  • Failure handling deserves first-class design. Timeouts, duplicated requests, incomplete deliveries, and failed refunds are not unusual exceptions in real systems. They are part of the product.
  • Honest fallbacks matter. A clearly identified simulation is more useful than a fake live integration, especially when evaluating a financial application.

We also learned how much complexity exists beyond checkout. A trustworthy agentic-commerce system must connect identity, intent, authorization, payment execution, fulfillment evidence, incident handling, and recovery into one coherent lifecycle.

Results and validation

We built a nine-act flagship demonstration that takes a purchase through intent, discovery, approval, payment, incident detection, AI-assisted resolution, verified recovery, audit replay, and Studio regeneration.

The repository includes:

  • 319 passing tests, with 33 credential-dependent tests visibly skipped in the keyless test run.
  • A 30-scenario live AI evaluation reporting 30/30 successful cases and 1.000 citation precision.
  • A Postman collection with 38 requests and a verified Newman run of 37/37 requests and 18/18 assertions.
  • A reproducible demonstration, integration documentation, and release evidence.
  • A verified PayPal Sandbox flow covering an order, capture, and successful partial refund, with a valid Flight Recorder trail.

These results validate important parts of the implementation, while the project still has limitations. The fallback catalog and logistics events are simulated, live product discovery requires Channel3 credentials, and persistence currently uses JSON snapshots rather than a production database. We have not yet conducted third-party usability testing.

What's next

AFTERPACT is a foundation for a future in which people delegate more purchasing decisions to AI agents without surrendering control over their money or their rights as buyers.

Our next priorities are stronger real-world fulfillment integrations, durable production-grade persistence, broader merchant support, and usability testing with buyers and operators.

We believe the future of agentic commerce should not be measured only by how quickly an AI can complete a purchase.

It should also be measured by whether that purchase was authorized, whether the promise was respected, and whether the system can prove that the problem was resolved when something goes wrong.

AFTERPACT makes the promise matter — even after the payment.

Built With

Share this project:

Updates

Submission history