Inspiration
Small business owners like the bakeries, salons and cafes I had in mind lose hours each week comparing suppliers, haggling over prices and chasing invoices. Handing that work to an AI agent is tempting, but an agent with access to a payment account is also a serious risk: it can be tricked, overspend, or pay the wrong party. I wanted to build the trust layer first. The question became: how do you let an AI spend money safely?
What it does
Autopilot CFO is an AI purchasing agent that restocks supplies and pays vendors through PayPal, inside spending rules the owner writes in plain English.
- Rules in plain English. The owner types "Keep flour, butter and sheet pans stocked, max $400/week, auto-approve under $100." An AI turns that into structured limits, and the owner reviews and edits them before anything becomes active.
- Market check with Channel3. The agent looks up what other merchants charge through Channel3's product search, so it can judge whether a price is fair.
- Negotiation. A buyer agent negotiates with a vendor that has a hidden floor price and bulk discounts. A $120 order was negotiated down to about $97.
- Policy gate. Before any money moves, 15 deterministic checks run in code: budget, per-purchase cap, allowed vendor, the right payee, currency, hidden fees, order splitting, replay, and more. The model cannot override them.
- PayPal payment. Orders under the auto-approve limit are paid automatically through the PayPal Payouts API. Larger orders wait for the owner to approve or reject.
- Live status and an AG Grid audit ledger. PayPal webhooks, plus a background status check, update each payment in real time. The AG Grid ledger records every offer, its reasoning, every policy check and the payment status.
The demo includes a malicious vendor that tries a prompt injection and tampered invoices (a different payee, a higher price after agreement, hidden fees, a currency swap). The injection is ignored, and every tampered invoice is blocked before PayPal is called.
How we built it
- Architecture. A TypeScript monorepo: a policy-engine package (
packages/guardrail), an Express API and agents (apps/server), and a React and Vite UI with AG Grid (apps/web), deployed on Render. - Policy engine first. I built the guardrails before the agents, so the model had to work within limits that were already tested. The engine is pure, fails closed on malformed input, and uses integer cents throughout.
- Groq for the AI. Groq's model parses the owner's rules into JSON, and it powers the buyer agent. The agent acts only through tool calls (
make_offer,accept_offer,walk_away,quote_total,market_prices). Any malformed or off-limit output ends the negotiation with no deal. The price limit is also enforced in code, which clamps the offer even when the model is fully fooled. - PayPal. Payouts create, status and cancel, with payout ids derived from each deal, so a retry can never pay twice. Webhooks are verified with PayPal's signature API. The code refuses to run outside the sandbox.
- Channel3 and AG Grid. Channel3 supplies retail prices, and the agent receives only numbers, never product text, so web content cannot inject instructions. AG Grid powers the three linked tables in the ledger: negotiations, the audit trail and the policy checks.
- Testing. 354 automated tests cover the policy checks, the attack scenarios, the webhook handling and the UI. I also ran the real PayPal sandbox and the live model, not just mocks.
- Hosting. One Render service serves both the API and the built UI. Public-demo mode gives each visitor their own isolated state, sets purchase limits, and disables the developer-only payment endpoint.
Challenges we ran into
- The model didn't follow my instructions. The first buyer opened too close to its limit and then walked away with a deal still available. I fixed this with prompt changes, and later with rules in code, so the outcome no longer depends on the model's wording.
- Matching PayPal's sandbox. The sandbox didn't match the docs in several places. A business account in the wrong country couldn't send payouts. A payout could only be cancelled once its whole batch was processed, even when the item was already unclaimed. A cancel sometimes returned an internal error. Each time, my simulated PayPal had missed the rule, so I updated the simulation and the code to match what the sandbox actually did.
- A batch "success" is not a delivered payment. Early on, a batch success event marked an unclaimed payout as delivered. Only item-level events now decide what happened to the money, and a test covers exactly that case.
- Rate limits. Groq's free tier and Channel3's search results both forced changes: automatic retries that wait as long as the provider asks, and a relevance filter because a flour search returned bread makers.
- Shared state. The first version kept one budget for everyone. A public demo needed per-visitor sessions, so webhooks and the background check had to find the right visitor's payment.
- Honest limits. PayPal cannot reverse a delivered payout through its API, so "refund" records a request to the vendor and says so in the UI, rather than pretending to refund.
Accomplishments that we're proud of
- A safety property that holds under attack. In the malicious-vendor scene, the agent paid normal prices to the real vendor, and every tampered invoice was stopped before PayPal was called. The attack tests and the demo both check this.
- The model can't spend beyond the rules. Even when the model is fooled into accepting any price, the code clamps the offer to the owner's limit.
- The real PayPal sandbox confirms the flow. An unclaimed payout was cancelled and PayPal returned the money. The live webhook path was tested with signed events.
- 354 automated tests across the policy engine, the server and the UI, and a fresh-clone check before every submission.
What we learned
- Put the trust layer in code and test it against attacks. Prompts are guidance; they are not a security boundary.
- Verify against the real system. The simulated PayPal only became useful once it matched what the sandbox really did, so tests should be checked against live behaviour, not just written from the docs.
- Design for the case where money is in flight. Webhooks can be late or out of order, and a batch can succeed while an item is still unclaimed. Statuses must be derived from the right event, and the budget must be freed only when money really comes back.
- Be honest in the product. It's better to say "refund requested" than to fake a reversal that PayPal cannot perform.
What's next for Autopilot CFO
- Real vendors. Connect to actual supplier catalogues and invoices instead of a simulated vendor.
- Persistent storage. Replace the in-memory state with a database, so ledgers survive restarts.
- Owner notifications. Send approval requests to the owner's phone, and let them approve from there.
- Broader rules. Recurring restock schedules, budgets per category, and multi-vendor comparison.
- The guardrail engine as a library. The policy engine could be published as a standalone open-source package for any PayPal-using agent.
Built With
- aggrid
- channel3
- express.js
- groq
- markdown
- node.js
- paypal
- react
- render
- typescript
- vite
- vitest
- zod