← portfolio.os/ projects / onyx

project / onyx

Onyx

shipped
Full StackAI/ML

Overview

A solo build for Agentic Commerce Pioneers Edition II, Track 1 (Agentic Checkout). Onyx is an ordering agent for the suppliers a small business already buys from. A manager describes a restock in plain language with a budget. Onyx prices it against each supplier's real store, assembles the cheapest basket that covers the request and fits the budget, and places one order per supplier after a single approval. No supplier has to integrate.

Problem

A cafe orders the same things every week from several small suppliers. Each supplier has its own website, login, checkout and delivery charge. Comparing delivered cost across three carts by hand is tedious enough that nobody does it, so the business overpays. Most of these suppliers are small Shopify stores that will never build an API or an agent integration. Onyx is designed to work with them as they are.

What I built

  • Supplier onboarding from a URL. Onyx calls Agnic POST /explore, which drives the store's live checkout read-only and stops before payment. Onyx then stores the merchant id, rail, currency and discovered catalogue. Explore runs asynchronously for about two minutes, so Onyx tracks it with its own state machine.
  • Natural-language requests. An LLM parses the request into strict JSON, and Zod validates it before it becomes a Request row. The LLM provider is swappable.
  • Per-supplier live quotes. Onyx calls POST /shopify/quote with max_total_minor and max_shipping_minor caps on every call.
  • Delivered-cost basket assembly. An exact-cover search finds the cheapest non-overlapping set of supplier carts that covers every requested item within one budget, with a greedy fallback.
  • Approval and dispatch. Each supplier cart gets an immutable approval row with the exact items, destination and caps. Onyx then dispatches through POST /dispatch and polls GET /orders/{id} until the order reaches a terminal state and returns evidence.

Architecture

Next.js App Router frontend and API routes, Prisma on Neon Postgres, deployed on Vercel. The flow runs through five pages: /suppliers, /request, /price, /approve and /dispatch. Long operations never hold a request open. Explore and dispatch both persist state first and let the browser poll a short-lived route. If a serverless function dies mid-flight, the in-flight order is not lost.

Spending authority comes from a passkey-signed CAD mandate with per-purchase and daily limits, against a vaulted card that Onyx never sees. A purchase has to pass three separate checks before the card is touched: the API token's limits, the signed mandate, and the per-order caps recorded at approval.

architecture diagram
Architecture diagram of Onyx, generated by GitDiagram

generated by gitdiagram · click to explore interactively ↗ · full size

Decisions

  • Assign items by delivered cost, not unit price. Each supplier ships separately, so a cheaper item can still lose once its own shipping is added.
  • Treat quotes with checkout-time tax as ceilings. Onyx labels them as ceilings and never compares them directly with a settled total.
  • Safety rules live in code, not just error handling:
    • Nothing is dispatched without an approval, and the approved payload is sent verbatim.
    • A conditional approved → dispatching update claims each order atomically, so it can't be charged twice.
    • The order id is saved before anything else. A timeout counts as an uncertain purchase and is polled, never retried blindly.
    • retryable: null halts everything and flags the order for a human.
  • Refusals are expected outcomes. A cap breach, an undeliverable destination or an unmatched item shows up as a labelled skip, not an error. Each supplier's order is independent, so one failure doesn't affect the others.

Results

Onyx attempted to onboard six real Canadian suppliers with no integration on their side. Five onboarded: Pilot Coffee Roasters, Bulkmart, Kim Eco-Pak, A1 Cash & Carry and Eight Ounce Coffee, all on Shopify. The sixth, Swish, was refused because its catalogue sits behind a trade account. In that case the engine stopped instead of guessing its way into a checkout it couldn't complete.

Onboarding, search, live quotes with real shipping, cap enforcement, the signed mandate and the full dispatch path all ran for real. Only settlement was simulated: purchases went through a sandbox store with a test card. One dispatch came back with retryable: null, and Onyx stopped as designed instead of retrying or refunding.

What I learned

  • In agentic checkout, the hard part is what happens when a purchase might or might not have gone through. Persisting state before acting, and refusing to blind-retry, matter more than the happy path.
  • A failure that stops cleanly is a stronger demo than one that's hidden. The retryable: null dispatch and the Swish refusal both showed the safety rules working on real stores.
  • Money-moving agents need layered limits. Token limits, a signed mandate and per-order caps each catch different mistakes, so no single bug or bad parse can overspend.
  • Optimize for what the customer actually pays. Comparing delivered cost instead of unit price can change which supplier wins an item, because separate shipping per supplier can wipe out a cheaper sticker price.
  • Serverless platforms punish long-held requests. Persisting state first and letting the browser poll short-lived routes made two-minute explores and slow dispatches survive function timeouts.