AgentPay — Autonomous Agent Budgeting & PayPal Settlement

  1. Inspiration: The Missing Financial Primitive for AI Agents

In 2026, AI agents don't just generate text or answer support queries; they execute multi-step business workflows. They spin up GPU clusters on cloud providers, purchase specialized market datasets, query paid search APIs, and procure digital services on the fly.

Yet, as builders give agents greater autonomy, a glaring bottleneck emerges: payment execution.

Today, developers face an uncomfortable binary:

  1. Handing over raw corporate credit cards or unrestricted API tokens: An autonomous loop error or prompt injection could wipe out thousands of dollars in minutes.
  2. Requiring human approval for every micro-transaction: Forcing human sign-off on a $\$0.50$ web-scraping query or $\$2.00$ serverless scale-up completely destroys agent autonomy.

We were inspired to build AgentPay as the missing financial layer: a programmable corporate card and policy engine that gives agents safe, capped micro-spending power settled in real time via PayPal, while automatically routing anomalies and high-stake payments to human supervisors.


  1. What We Built: The Architecture of a Financial Firewall

AgentPay functions as an intelligent proxy between autonomous agents and the financial web:

  • Agent Identity & Key Provisioning: Each agent (e.g., DevOps Auto-Scaler, Market Research Copilot) receives a scoped authorization token linked to a cryptographic ledger.
  • Serverless Policy Engine: Sits before every payment call to verify spending constraints in real time.
  • PayPal Sandbox Settlement: Approved spends execute programmatic Orders and Captures via PayPal's REST APIs.
  • Human-in-the-Loop Cockpit: A real-time dashboard featuring live balance dials, budget consumption bars, and an instant approval/decline queue for flagged transactions.
  • Comprehensive Audit Trail: Every transaction records the agent ID, vendor, justification prompt, amount, policy verdict, and PayPal transaction reference.

  1. The Math Behind the Policy Engine

To prevent runaway agent spend while allowing elastic bursts for mission-critical tasks, we modeled our budget and policy firewall mathematically.

A. Rolling Time-Window Budget Constraint An agent $A_i$ requesting amount $x$ at timestamp $t$ must satisfy the rolling 24-hour spending cap $B_{\text{daily}}$:

$$\sum_{j \in T_{24}(t)} \text{amount}j + x \le B{\text{daily}}(A_i)$$

where $T_{24}(t) = { j \mid t - 86400 \le t_j \le t \land \text{status}_j = \text{COMPLETED} }$.

B. Tiered Decision Matrix For any transaction request $(x, V)$ with amount $x$ and vendor $V$:

$$\text{Verdict}(x, V) = \begin{cases} \text{DECLINED} & \text{if } V \notin \text{Whitelist}(A_i) \lor x > \text{MaxTx}(A_i) \ \text{AUTO\PAY} & \text{if } x \le \theta{\text{auto}}(A_i) \land \text{VendorAutoPay}(V) = \text{true} \ \text{PENDING\APPROVAL} & \text{if } \theta{\text{auto}}(A_i) < x \le \text{MaxTx}(A_i) \lor \text{VendorAutoPay}(V) = \text{false} \end{cases}$$

Here, $\theta_{\text{auto}}$ is the automated approval threshold, and $\text{MaxTx}$ is the hard ceiling for an individual transaction.


  1. How We Built It

We designed AgentPay to be cloud-native, secure, and responsive:

[ AI Agent Workflow ]
         │ (HTTP REST / API Key)
         ▼
[ Supabase Edge Function: evaluate-and-pay ]
    ├── Validate Auth & API Keys
    ├── Evaluate Policies against Postgres DB (RLS)
    └── Decision Router:
         ├── If Within Limits ──► [ Edge Function: paypal-service ] ──► [ PayPal Sandbox API ]
         └── If Over Threshold ──► Insert into [ approvals_queue ]
                                            │
                                            ▼ (Supabase Realtime)
                              [ React + Tailwind Cockpit UI ]
                              [ (Human Approves / Rejects)   ]
  • Frontend: React 18, Vite, TypeScript, and Tailwind CSS. Built with responsive metric cards, interactive task simulators, vendor management tables, and a real-time settlement audit stream.
  • Backend & Database: Supabase (PostgreSQL) with Row Level Security (RLS) policies isolating agents, vendor rules, transaction logs, and approval queues by workspace owner.
  • Serverless Edge Functions (Deno):
    • paypal-service: Secure OAuth token generation (/v1/oauth2/token) using server-side Sandbox Client ID and Secrets, plus order creation and capture endpoints (/v2/checkout/orders).
    • evaluate-and-pay: Central policy gatekeeper checking budget thresholds, vendor permissions, and transaction histories before invoking payment execution.

  1. Challenges We Faced

  2. Server-Side Secret Hygiene vs. Client Convenience: Early on, keeping frontend simplicity without exposing sensitive PayPal Client Secrets or Supabase Service-Role tokens was critical. We enforced a strict boundary: the frontend client only communicates via authenticated Supabase calls or agent endpoints, while PayPal credentials live exclusively in encrypted backend secrets.

  3. State Concurrency & Rolling Budgets: Simulating multiple agents requesting compute simultaneously introduced potential race conditions. We structured atomic updates and rolling ledger aggregations in SQL to avoid double-spend exploits.

  4. Bridging PayPal Sandbox with Serverless Architectures: Integrating PayPal's OAuth lifecycle inside stateless Edge Functions required robust token caching and error-handling routines for edge cases like expired tokens, rate limits, and network timeouts.


  1. What We Learned
  • Financial Safety is as Important as Model Alignment: As agent reasoning improves, economic guardrails become the decisive factor in whether companies permit agents to touch production tools.
  • Micro-approvals Keep Trust Intact: Providing users with granular controls (vendor toggles, monthly caps, manual overrides) makes developers confident enough to leave agents running overnight.
  • Fintech Needs Realtime Ergonomics: Using Supabase Realtime subscriptions alongside PayPal webhooks demonstrated how fluid financial operations can feel when transactions stream instantly into a single cockpit view.

  1. What's Next for AgentPay
  • PayPal Payouts & Multi-Currency Support: Expanding from order capture to peer-to-peer agent bounties and multi-currency international vendor settlements.
  • LLM Reasoning Audits: Recording embedding vectors of agent justification prompts to detect prompt injection attempts and anomalous spending patterns before requests hit the policy engine.
  • SDK for Popular Agent Frameworks: Publishing zero-config plugins for LangChain, CrewAI, and AutoGen so developers can equip any agent with an AgentPay corporate card in two lines of code.

Built With

  • ai-agents
  • api-security
  • autonomous-agents
  • deno
  • edge-functions
  • fintech
  • full-stack
  • langchain
  • llm
  • lucide-icons
  • microservices
  • node.js
  • oauth-2.0
  • paypal-sandbox-api
  • postgresql
  • react
  • realtime
  • rest-api
  • row-level-security
  • supabase
  • tailwind-css
  • typescript
  • vite
  • webhooks
Share this project:

Updates

Submission history