Open source  /  Implementation guide

Open-source implementation · Agentic commerce

Build an agentic commerce harness on open source

What this is. A build-it-yourself path to the same outcome, made from open-source parts you host. It does not publish 5 Kings’ internal method, client data, or any third party’s confidential information — and it says plainly where the open-source path is weaker than a specialist service.

In one paragraph

A commerce harness is the machinery between a conversation and an order: catalogue lookup, price and stock, cart, payment, fulfilment, and a record of every step. Building it open source means every one of those hops is a service you can inspect and replace. It also means you own the failure modes.

What you end up with

  • A catalogue and availability API the agent calls, with a stable schema and caching
  • A cart and checkout path that is idempotent from the first request
  • Payment authorisation and capture as explicit, auditable steps
  • A per-conversation audit trail: what was quoted, what was ordered, what was charged

The reference stack

Every project below is open source and self-hostable. Licences are the ones the project publishes today; check them against your own distribution model before you ship, because a licence can change and an AGPL project has obligations a MIT project does not.

LayerOpen-source projectLicenceWhat it does for you
Storefront / APIWooCommerce REST or MedusaGPL-2.0 / MITCatalogue, stock, cart and order objects with an HTTP API you can call from an agent.
Commerce logicYour own service (FastAPI / Express)MITQuotes, availability rules, bundle pricing, tax and shipping decisions — the parts that are specific to your business.
PaymentsStripe API (or an open PSP)API termsPaymentIntents with idempotency keys; the only part of the chain that is unavoidably a vendor.
Queue + workersNATS or Celery + RedisApache-2.0 / BSD-3Order provisioning, emails and webhooks off the request path, with retries.
SearchMeilisearch or OpenSearchMIT / Apache-2.0Fast product search and facet counts for the agent's queries, without a paid search service.
OrchestrationLangGraph (see the harness guide)MITNamed states for a conversation: discover, configure, quote, confirm, pay, fulfil.
AuditPostgreSQL append-only tables + Langfuse tracesPostgreSQL / MITEvery state change with its inputs; the answer to 'why was this order priced like that'.

Build it

1. Separate the price decision from the price display

The agent asks your service ‘what is this, for this configuration, delivered to this address, at this quantity’. That service owns the rules. If price logic lives in a prompt or in the model, it will be wrong in a way nobody can reproduce.

2. Make the catalogue answer cacheable

Availability is read constantly and changes slowly. Cache it with a short TTL and an explicit invalidation on order. An agent that hammers your catalogue per token will cost more than the sale.

GET /api/quote?sku=ABC&qty=2&zip=76541
-> { "sku":"ABC", "unit": 2499, "qty": 2, "subtotal": 4998,
     "tax": 412, "shipping": 0, "total": 5410,
     "currency": "USD", "expires_at": "..." }

3. Quote with an expiry

A quote is a promise with a lifetime. Return expires_at and reject an order that uses an expired quote, rather than silently re-pricing. This one field prevents the most common agentic-commerce dispute.

4. Make the cart transition idempotent

Cart, order and payment each take an idempotency key derived from the conversation and the step. A retried request returns the same object. An agent that retries on timeout must never create a second order.

5. Authorise and capture separately

Authorise at confirmation, capture at fulfilment. It gives you a window to cancel a bad order and it matches how card networks expect commerce to work. Log both with the provider’s id.

6. Provision asynchronously, then report

Fulfilment, email and ERP sync run on the queue with retries. The order endpoint returns accepted, not done. The agent polls the task or receives a callback, and the customer gets a truthful status rather than a spinner.

7. Reconcile daily

Orders in your database vs orders at the PSP vs fulfilled shipments. Three-way reconciliation, one query, every day. Any mismatch is a bug with a customer on the other end of it.

Acceptance checks

If you cannot verify a claim, it is not a finding. These are the checks that close the work; each one can be run by somebody who did not build it.

Acceptance checkHow to verify it
Price is computed server-side for 100% of ordersAssert no order row carries a client-supplied total; the recomputed total must match.
Expired quotes are rejectedPost an order with an expired quote and expect 409, not a silent re-price.
Retries do not duplicate ordersSend the same idempotency key twice; exactly one order and one authorisation.
Authorisation and capture are separately recordedBoth provider ids present on the order; timestamps ordered.
Three-way reconciliation is zero or explainedDaily job comparing internal, PSP and fulfilment counts.
Every order is traceable to a conversation and a traceOrder row carries conversation_id and trace_id.

Effort and cost

Estimate
Skill neededAdvanced: commerce data models, payments, queues, and an agent framework
Build time2 weeks for a working harness against a real catalogue; 2 days for the quote + idempotency layer alone
Running costInfrastructure plus PSP fees; model cost is small relative to payment fees
What you must hostOne 8 GB host for API + search + queue + Postgres, plus your existing storefront.

What open source does not give you

The honest half of the comparison. Each of these is a reason somebody buys the service instead of building it, and pretending otherwise would make the rest of this page worthless.

  • The PSP is the one genuinely closed part. You can self-host the logic, not the acquiring; card network rules apply regardless of how open your stack is.
  • Tax and duty calculation for multi-jurisdiction commerce is a data problem before it is a software problem. Open tax tables exist but are hard to keep current; most teams end up buying the data.
  • Agent autonomy in payment remains a liability question. A hard server-side limit and a human confirmation above it are the only defensible defaults.
  • Catalogue data quality decides the outcome. An agent given contradictory product data will produce confidently wrong quotes.
  • Fraud screening is a model problem with an adversarial counterparty. Self-hosting a good one is a serious project, not a config flag.

Scope only, stated so you can compare it with the build above.

  • The quote and pricing rules modelled on your actual catalogue, discounts and shipping logic
  • The idempotency and reconciliation layer built and tested against your PSP
  • The autonomy limits agreed with finance, enforced in code and verified in staging

Sources and further reading

What this page does not include. This guide documents an open-source implementation of the same outcome. It deliberately leaves out 5 Kings’ internal playbooks, client data, vendor terms and unpublished method: we publish what any competent team can reproduce, and we do not publish what belongs to a client or to a contract. Where a step depends on a decision only your business can make, the guide says so instead of guessing.

Take it with you

Build an agentic commerce harness on open source

The full guide as an A4 PDF: the reference stack with licences, the build steps, the acceptance checks and the honest limits — in one file you can hand to an engineer or print for a planning session.

PDF · A4 · no email required · free to redistribute with attribution

Open-source Guides & PDFs