Agent Allowance

Give your AI restocking agent a spending allowance it cannot break.

Inspiration

AI agents can now compare prices and pay for things. A cafe owner would happily hand off reordering milk, cups and coffee beans, but nobody wants to give an AI an open wallet. I wanted a middle ground: an allowance with rules the agent cannot break.

What it does

The owner sets a mandate: monthly budget, max per order, an "ask me above $X" line, approved suppliers, allowed categories and a maximum price rise. An AI agent watches stock, compares supplier quotes and proposes orders, funding the items that will run out soonest first.

Every proposed order goes through a plain-code policy engine, not the AI:

  • AUTO: inside every limit, so it is paid at once.
  • HOLD: over the "ask me" amount or a price spike, so it waits for the owner's approval.
  • BLOCK: unapproved supplier, wrong category, over a limit, or the kill switch is on. Nothing is paid and the reason is shown.

PayPal is the payment rail. Every AUTO or approved order is a real PayPal sandbox payout from the shop to the supplier's PayPal account. The order shows "Paying..." until PayPal confirms the payout, then "Paid", and only then does the stock arrive. The money is reserved against the budget the moment it is sent, so in-flight payments still count toward every limit. Without PayPal, nothing gets paid and nothing gets restocked.

Every step lands in an audit log with its PayPal payout reference, and one kill switch blocks all new spending.

How we built it

  • Backend: Python, FastAPI and SQLite, with a one-file JavaScript dashboard.
  • AI: Groq's openai/gpt-oss-120b with tool calling. The model has two tools: read low stock with supplier quotes, and propose orders. Its only way to spend is proposing; prices always come from the supplier catalogue, never from the model.
  • Payments: PayPal Payouts API (sandbox) with OAuth, idempotent request IDs and a background check that settles each payout as Paid or Failed.
  • Hosting: Render, deployed from a Blueprint.
  • Tests: 78 pytest tests, with PayPal and the AI mocked.

Challenges we ran into

  • Getting a PayPal developer account. Phone verification failed for days before I got sandbox access.
  • Payouts are asynchronous. PayPal accepts a payout as PENDING, so I added a "Paying..." state with budget reservation instead of pretending the money had landed.
  • Free-tier AI limits. My first agent loop used 30,000 tokens per run and took 185 seconds. A batch ordering tool cut it to about 6,000 tokens and 4 seconds.

Accomplishments that we're proud of

  • The AI genuinely adds value: when tea bags were blocked at a cheaper, unapproved supplier, it re-routed them to an approved one on its own, and the policy engine still checked that order too.
  • The agent cannot overspend, even if the model misbehaves. That is enforced in code, not by the prompt.
  • Real PayPal sandbox payouts, end to end, on a live site.

What we learned

Agentic commerce needs a trust layer more than a smarter agent. The AI is good at judgment (which supplier, how much, what to try next); plain code is better at saying no. Keeping those two jobs separate made the system both useful and safe.

What's next

Delivery lead times, monthly budget resets, per-supplier limits and authorise-then-capture for held orders.

Built With

Share this project:

Updates

Submission history