Inspiration

AI agents have started to shop for people. They read blogs, forum answers and video reviews, then they buy. Nobody clicks an affiliate link, so the writer whose knowledge made the sale earns nothing. Affiliate programs pay for clicks. Agent-side commissions pay the agent, which makes it biased. Pay-per-crawl pays for reading, even when the reading changed nothing.

We asked a simple question: if a review changed what an AI agent bought, can we prove it, and pay the writer?

What it does

Sway is the attribution and payout layer for agentic commerce.

  1. A neutral AI agent decides. Google Gemini reads human-written sources (a travel blog, a forum answer, a video transcript, a spec table) and picks a product. It earns nothing for its choice.
  2. Screening comes first. A source that tries to give orders to AI agents is blocked. A source that copies another writer is caught with 5-word shingles. Both earn $0, and the reason is shown.
  3. You can see the influence. Click Remove & re-run on one review and the agent decides again without it. In our live run, the agent picks the Halvo Q7. Without Priya's long-haul review, it picks the Brisane ANC2. Her review swayed the sale.
  4. The shopper pays with PayPal. Checkout uses the PayPal JS SDK and Orders API. The server sets the price, and a signed PayPal webhook confirms the capture.
  5. Exact Shapley attribution. After capture, Sway replays the decision over every combination of sources and computes each source's Shapley value. In the run in our video: Priya φ = 0.50 → $7.07, Maya $2.53, Tomás $1.25. Dev argued for the other headphones (φ < 0), so he earns $0.
  6. Money vests only if the sale sticks. PayPal refund and dispute webhooks decide. A refund forfeits the commission, a dispute freezes it, and a refund after payout becomes a clawback netted against the next payout.
  7. PayPal Payouts pays the creator. In our recorded run, PayPal sandbox batch 7CDCNDTKBRPQQ paid Priya her $7.07.

Any AI agent can shop through Sway. Sway is an MCP server. An agent such as Claude, ChatGPT or Cursor gets a neutral pick, the human sources behind it, counterfactuals, and a PayPal checkout link for the person. The agent never touches the money.

PayPal integration

  • Orders v2 + JS SDK buttons: checkout of the agent's pick, price taken from our database, idempotent with PayPal-Request-Id.
  • Webhooks with signature verification: capture, refund, reversal, dispute and payout events, verified against the raw body, de-duplicated, and processed by the same handlers as API responses.
  • Refunds: full and partial, cent-exact forfeits and clawbacks.
  • Payouts: creator payouts by email, with an outbox, status polling, reversals and cancellation of unclaimed items.
  • Every money movement goes into a double-entry, SHA-256 hash-chained, append-only ledger. The trial balance is zero by construction, and every order satisfies creator pool + Sway fee + returned to merchant = commission.

How we built it

  • Go engine, one static binary with the Next.js UI embedded: attribution engine, ledger, PayPal client, Postgres job queue, MCP server.
  • AI: Google Gemini through its OpenAI-compatible API, behind one provider interface (Claude and any OpenAI-compatible model also plug in). JSON-schema structured outputs, one fixed prompt for every counterfactual run, a content-addressed run cache, singleflight de-duplication, request pacing with 429 backoff, and a deterministic fallback that keeps every purchase moving.
  • Math: v(S) is the probability the agent picks the purchased product when it sees only coalition S (softmax over its scores). We compute exact Shapley values over all 2ⁿ coalitions for the top sources, with sampling variance carried into every φ, and a Monte Carlo mode for large source sets. The Shapley efficiency gap on every order is about 1e-16.
  • Next.js + AG Grid for the Shopper, Creator and Merchant views. Render hosts the web service (Blueprint in the repo), and Neon serverless Postgres holds the data.

Challenges we ran into

  • Making counterfactuals fair. An LLM re-run is noisy. We made prompts byte-identical for identical coalitions, cached every run, averaged samples, and set a noise floor so only real influence is paid.
  • Money under concurrency. Our stress test found a real race: a payout could spend money that a dispute had just frozen. We fixed it with one lock order across all money paths and a ledger guard that refuses any balance below zero.
  • Cross-border sandbox payments. Our first sandbox merchant could not receive USD. We moved checkout to a US sandbox merchant and kept the full live flow.

Accomplishments that we're proud of

  • Exact Shapley attribution over real LLM re-runs, end to end with real PayPal rails, live on the web.
  • A load test of 2,000 purchases from 128 concurrent shoppers: zero errors, every order balanced to the cent. Thirty rounds of random refunds, disputes, payouts and webhook replays keep every invariant.
  • 15 browser end-to-end tests, including an accessibility audit, run on every change.

What we learned

Influence is measurable. When the agent's prompt is fixed and its runs are cached, a counterfactual is cheap and repeatable, and Shapley values give a fair answer that a creator can check. We also learned that payments for agents need the same discipline as payments for people: idempotency, signed webhooks and a ledger that never lies.

What's next for Sway

  • PayPal partner onboarding for real merchants, and Log in with PayPal for creators.
  • An SDK so any agent can report its decisions and sources to Sway.
  • A distilled scoring model to cut attribution cost per order.

Try it

Built With

Share this project:

Updates

Submission history