Inspiration

Small exporters lose orders in the gap between "a buyer is interested" and "the buyer has paid". Enquiries arrive incomplete, buyers push for discounts, and a quote sent in a hurry can give away the margin. An AI agent could run that conversation, but no seller will hand pricing to a model that might agree to anything. I wanted to show an agent that can negotiate freely and still cannot break the seller's rules or move money on its own.

What it does

TradeThread is an AI deal desk for exporters. It takes one export deal from enquiry to paid invoice:

  1. Buyer enquiry. A buyer arrives: either the buyer's own AI purchasing agent with a budget, quantity and deadline, or a person typing in a chat.
  2. AI negotiation. The seller's AI sales agent asks for missing details, tests counter-offers and makes formal offers.
  3. Price protection. Every offer passes through a pricing engine. A price below the seller's floor or past the discount cap is blocked, and each blocked price is shown in the conversation and on a price rail.
  4. Seller approval. The seller sees the total, discount and margin and approves or rejects. The AI agents cannot approve a deal.
  5. PayPal invoice. Only after approval can the AI agent send a PayPal invoice, and it cannot set or change the amount.
  6. Verified payment. The buyer pays the advance, the balance invoice is issued automatically, and the deal is marked paid only when PayPal itself reports each invoice as paid.

How we built it

  • PayPal Invoicing API v2 (Sandbox) to create, send, read and cancel invoices. The advance and the balance are two linked invoices; the second is issued when the first is paid.
  • PayPal webhooks. The app registers its own webhook for INVOICING.INVOICE.PAID and verifies each event's signature with PayPal. A webhook only prompts the app to fetch the invoice's real status, and a background check every 15 seconds covers late webhooks.
  • Google Gemini with function calling for both agents. The seller agent can check terms, propose an offer and, after approval, send the invoice. The buyer agent can accept an offer or walk away.
  • Deterministic guardrails in TypeScript, with money in integer cents: the pricing rules, the buyer's budget check and the approval gate.
  • Stack: React, TypeScript and Vite for the interface; Fastify on Node.js for the API; PostgreSQL for storage; hosted on Render with a Neon database.
  • 28 automated tests cover the pricing boundaries and the guardrails.

Challenges we ran into

  • PayPal rejects partial payments on a single invoice for Indian merchant accounts, so the advance and balance became two linked invoices.
  • A Sandbox buyer in India cannot pay an Indian Sandbox merchant, so the demo buyer is a United States account.
  • A language model will happily offer a price it should not. The fix was to stop trusting it: the model proposes, and code decides whether the proposal is allowed.
  • Payment state had to stay correct when webhooks are late, duplicated or forged, so PayPal's API is always the source of truth.

Accomplishments that we're proud of

  • A full deal runs live end to end: two AI agents negotiate, the seller approves, the agent sends the invoice, and a signed Sandbox webhook confirms the payment.
  • A forged webhook is rejected, and a duplicate webhook cannot issue a second invoice. Both are covered by tests.
  • The AI cannot quote below the minimum price, cannot approve its own offer and cannot choose an invoice amount. All three are covered by tests.

What we learned

Useful agents in commerce need a clear split: the model handles language and strategy, code handles rules and arithmetic, a person makes the commitment, and the payment provider is the only authority on whether money moved.

What's next for TradeThread

  • More than one product line per offer.
  • Seller accounts, so each exporter sets their own catalogue and rules.
  • Shipping documents and currency conversion attached to the same deal.

Tools and disclosures

  • The code was written with Claude Code (Anthropic's AI coding assistant) under my direction and review.
  • Google Gemini powers the two negotiating agents at runtime.
  • All companies, people and products in the demo are fictional. All payments are PayPal Sandbox payments; no real money moves.

Built With

Share this project:

Updates

Submission history