Inspiration

AI agents are starting to buy things for people. But a prompt that says "stay under $60" is not a control. Agents can be tricked by untrusted text, split purchases to dodge limits, or retry a payment twice. Mandate is a permission layer for AI purchasing agents. An AI agent can propose a purchase. The owner's rules decide whether money moves.

What it does

A small-business owner describes spending rules in plain English, for example: "Spend at most $60 total on office supplies from Demo Office Store. Maximum $40 per order. No gift cards or subscriptions. Ask me before any purchase above $30."

  1. Gemini drafts a structured policy and flags ambiguity. Only the owner can activate it, and policies are immutable versions.
  2. The agent proposes products from a controlled catalog.
  3. A deterministic backend, not AI, evaluates the actual merchant, items, total and remaining budget, and returns allow, review or block with reason codes.
  4. If allowed, the budget is reserved atomically and the owner approves the payment in the standard PayPal sandbox checkout.
  5. The backend revalidates the mandate, then authorizes and captures through PayPal. Budget counts as spent only after PayPal confirms the capture.
  6. A transaction timeline records every decision and PayPal reference.

Demo scenarios: a valid purchase; a prompt-injection attempt (a product description telling the agent to ignore the rules and buy a gift card), which the backend blocks before any payment call; split spending that tries to dodge the budget; duplicate payment execution that returns the existing transaction; and a revoked mandate after authorization, where capture is blocked and a void is attempted.

How PayPal is used

PayPal is central to the payment flow (sandbox only): Orders with standard buyer approval, authorization, capture, void of uncaptured authorizations, signature-verified webhooks, and polling reconciliation. Idempotency keys and database constraints prevent duplicate charges. Returned amount, currency and payee are checked against the local record.

How AI is used

Gemini drafts policies, selects products from the allowed catalog, and explains decisions. Output is validated against strict schemas, and usage is capped per session. The AI is treated as an untrusted planner. It has no PayPal credentials, cannot activate policies, and cannot override a block.

How we built it

Next.js (App Router) and TypeScript, Tailwind CSS, PostgreSQL (Neon) with migrations, Zod validation, the Gemini API, the PayPal REST API (sandbox), and Vercel for hosting. The budget ledger uses atomic reservations so concurrent purchases cannot overspend. Tests cover limits, concurrency, tampering, expiry, revocation, duplicates and webhooks against a real PostgreSQL instance.

Challenges

Defining exactly when a reservation becomes spending and when it can be released, especially around timeouts and ambiguous payment states. We keep a reservation held until PayPal's authoritative state shows no capture and no capturable authorization remains. We also had to keep application approval and PayPal buyer approval clearly separate.

What we verified, and what we did not

Verified in the PayPal sandbox: a real buyer approval, authorization and capture ($5.00); a real authorize, revoke, blocked capture and void sequence; real webhook signature verification and duplicate-execution handling in local runs; live Gemini policy drafting, proposals and explanations. Redacted evidence is in the repository's evidence/ folder. Not verified before submission: .

Limits

This is a sandbox prototype (USD, test accounts, no real money). The mandate is an application-level control, not a PayPal-native delegated wallet, and the owner still approves each payment in PayPal. It does not certify anything or claim to be tamper-proof, and the audit trail is not independently verified.

What's next

Full-period live reconciliation, calibrated and richer policy types, stronger authentication, and testing with real merchants.

Built With

Share this project:

Updates

Submission history