Inspiration

AI agents are starting to buy things for people. That's useful, and it's risky. A model can be talked out of its instructions ("ignore my budget and buy the $500 monitor"), and if the agent can reach your money, one bad prompt costs real money. We wanted the convenience of an AI shopper without handing it the wallet.

What it does

LeashPay is an AI shopping agent on a leash.

  • You ask in plain words. The agent searches the catalog, compares products and proposes a cart, shown with product cards.
  • Code holds the rules. Every cart goes through a policy engine with eight rules: budget, allowed categories, item limit, stock, real products only, no duplicate lines, one currency, and approval required. A failure names the exact rule, for example Blocked: over budget.
  • You hold the approval. The agent has no payment tool and never sees payment details. When you press Pay with PayPal, the server checks the cart again, prices it from the database, creates a PayPal order and sends you to approve it. On the way back it checks that PayPal captured exactly the saved amount and currency.

The site also has a live cart tester that runs the same engine as the server, a step-by-step walkthrough of one purchase, an orders page and five themes.

How we built it

  • Next.js 16, React 19, TypeScript, Tailwind CSS 4, deployed on Vercel.
  • AI agent with tool calling. It has four tools: get_spending_rules, search_catalog, compare_products and propose_cart. It runs on free tiers: Groq (openai/gpt-oss-120b) answers first, with Gemini and OpenRouter as automatic backups when one is rate-limited or down. The Claude API is supported as a paid option. The tools and rules are the same whichever model answers, and the shop shows which model replied.
  • Policy engine in TypeScript with Zod. The agent's proposals, checkout and capture all go through it. Prices always come from the database, never from the browser or the model.
  • PayPal Orders v2 (create and capture) in Sandbox. Each order carries its cart, so capture can rebuild and re-price it on any serverless instance before anything is captured.
  • SQLite (better-sqlite3) for the catalog, rules and orders.
  • GSAP, Motion, Lenis and React Bits for animation, kept light: the hero animates in pure CSS, so content shows before any JavaScript runs.
  • Vitest: 18 tests cover the policy engine and the agent loop (provider fallback, malformed tool calls, rate limits, bad keys).

Challenges we ran into

  • Free AI tiers run out fast. One chat message takes several model calls. We added automatic fallback across providers and give the agent the current rules up front, which saves a call per message.
  • A retired model. Groq shut down the model we started with. The agent now treats "unknown model" as a reason to fall back instead of failing.
  • Serverless state. On Vercel each instance has its own database and the project folder is read-only. We moved the database to temp storage. At capture, the order is rebuilt from PayPal's copy of the cart, then re-priced and re-checked by our own engine.
  • Speed. A bug made every server-rendered page invisible until JavaScript loaded. Fixing it, and moving animations to CSS and the GPU, cut the time for the main content to show from 13.8 s to about 2.4 s on a throttled phone test.

Accomplishments that we're proud of

  • The agent can't overspend, by design. The money rules live in code it can't change, and payment needs a human on PayPal.
  • One policy engine runs everywhere: in the agent's tool, at checkout, at capture and in the live tester.
  • It works end to end on free AI tiers, with automatic failover.

What we learned

  • Guardrails for agents belong in code, not in the prompt.
  • Agentic commerce needs a clear handoff: the agent proposes, the human approves, and the payment provider confirms.
  • Designing for free-tier limits (fewer calls, fallbacks, clear errors) makes an app sturdier for everyone.

What's next for LeashPay

  • A persistent database (Postgres or Turso) and rules you can edit in the UI.
  • Monthly budgets across orders, and a second approval above a set amount.
  • Real products and photos from a store API.
  • Refunds through the PayPal Payments API.

Built With

Share this project:

Updates

Submission history