Inspiration

Autonomous AI agents are rapidly evolving from conversational chatbots into autonomous actors. They are provisioned to manage cloud infrastructure, optimize supply chains, procure software licenses, and book travel. However, financial agency remains fundamentally broken. Today, giving an AI agent the ability to spend money is an all-or-nothing dilemma:

  1. Unbounded Risk: Handing an agent an API key or corporate credit card gives it binary access. If the agent gets stuck in a recursive loop, hallucinates, or falls victim to prompt injection, it can drain an entire corporate account in minutes.

  2. Loss of Autonomy: The alternative—forcing a human to approve every single $5 micro-transaction—defeats the entire purpose of autonomous automation.

  3. Dispute Chaos: When an agent executes an erroneous or malicious purchase, financial institutions and merchants have no way to distinguish legitimate human intent from a hijacked agent process.

We asked ourselves: What if PayPal had a cryptographic, pre-flight gatekeeper specifically designed for autonomous AI agents?

This inspired MandateGuard — an authorization gateway that sits between autonomous software and PayPal commerce rails, allowing agents to spend freely within provable, mathematically enforced human boundaries.

What it does

MandateGuard acts as a zero-trust pre-flight authorization gateway for autonomous AI commerce. Before any transaction touches the payment network, MandateGuard intercepts the request and verifies it against mathematically signed policies established by humans, called Mandates.

Key capabilities include:

  1. Sub-10ms Pre-Flight Evaluation: Intercepts purchase proposals in real time, deterministically checking cumulative spend ceilings, single-transaction caps, merchant allow/deny lists, approved categories (MCCs), and geographic shipping bounds.

  2. Natural Language Mandate Compilation: Principals describe spending rules in plain English (e.g., "Allow DevOps bot to buy software on GitHub up to $150 total, max $50 per purchase, expiring in 7 days"). MandateGuard translates this into a strictly validated, immutable JSON schema.

  3. Cryptographic Hardware Passkey Signing: Mandates are authenticated using FIDO2/WebAuthn biometric hardware enclaves or Ed25519 asymmetric keypairs. Signatures are verified against the SHA-256 digest of canonicalized policy schemas, ensuring zero database tampering.

  4. Hierarchical Delegation Chains: Root agents can provision specialized sub-agents with child mandates. The system mathematically enforces non-escalation invariants: a child agent can never possess a higher budget, wider categories, or longer lifespan than its parent.

  5. Direct PayPal Orders v2 Integration: When pre-flight checks pass, MandateGuard communicates directly with PayPal REST APIs (POST /v2/checkout/orders), binds mandate tracking IDs into purchase metadata, resolves HATEOAS approval links, and executes final capture (POST /v2/checkout/orders/{id}/capture), creating real settled transactions in PayPal Sandbox Merchant accounts.

  6. Automated Dispute Evidence & Recourse: In disputed transactions, MandateGuard integrates with the PayPal Disputes API (/v1/customer/disputes), correlating disputed orders back to the originating agent and auto-compiling a cryptographic evidence bundle (signed policy, delegation tree, and audit logs) for one-click defense.

  7. Zero-Latency Emergency Kill-Switch: Account owners can revoke any mandate node instantly, cascading down the delegation hierarchy to cut off all downstream autonomous activity.

  8. Automated Adversarial Red Team Suite: Features a built-in testing harness executing 9 adversarial attack vectors (budget inflation, category bypass, signature replay, prompt injection, and vendor evasion) to prove defense resilience.

How i built it

MandateGuard was built using an enterprise-grade, decoupled architecture:

  1. Backend Gateway: Built with FastAPI (Python 3.11+) for asynchronous, high-throughput request processing and sub-10ms policy evaluation.

  2. Database & Storage: PostgreSQL orchestrated with Docker Compose, utilizing SQLAlchemy 2.0 ORM for transactional consistency across mandates, orders, delegations, and audit logs.

  3. Cryptographic Engine: Uses Python's cryptography library for Ed25519 asymmetric signature generation, canonical JSON serialization, and SHA-256 tamper-evident hash chaining. WebAuthn/FIDO2 hardware assertion challenges verify hardware-bound credentials.

  4. PayPal REST API Integration: Implemented an asynchronous client via httpx connecting to https://api-m.sandbox.paypal.com. Handles OAuth2 client credential token lifecycle, Orders v2 initialization (intent: CAPTURE), HATEOAS approval extraction, capture execution, and Disputes v1 synchronization.

  5. AI Compiler & Safety Engine: Uses high-throughput inference powered by Groq (llama-3.3-70b-versatile / openai/gpt-oss-120b) for structured natural language extraction, accompanied by an IntentDriftDetector (llama-3.1-8b-instant / openai/gpt-oss-20b) to flag unapproved cart items or vendor substitutions without overriding deterministic safety rules.

  6. Frontend Application: Built with Next.js 16 (App Router), React 19, and Tailwind CSS. Features an interface with 6 functional modules, a real-time Server-Sent Events (SSE) activity stream, and an interactive 3-Act live demonstration controller.

Challenges I ran into

Sub-10ms Gateway Latency: Pre-flight evaluation cannot slow down commerce. We had to optimize database queries, perform in-memory cryptographic signature verification, and cache remaining cumulative budgets so policy evaluation executes in under 10 milliseconds before dispatching to PayPal.

Mathematical Delegation Invariants: Ensuring a child agent cannot escalate privileges required strict set-theory validation. If a root mandate allows ["software", "cloud"] with a $500 budget, the delegation service mathematically proves that child categories are a subset (⊆) and cumulative child allocations do not exceed the remaining parent balance, even across multi-hop delegation chains.

Full PayPal Sandbox Checkout Lifecycle: Autonomous agents do not have physical fingers to click browser windows. We had to architect a clean bridge: MandateGuard authorizes the purchase, creates the PayPal Sandbox order, surfaces the HATEOAS approval URL for the authorized buyer, and triggers server-side capture upon approval.

Deterministic Guardrails on Non-Deterministic AI: LLMs can hallucinate or be tricked by prompt injections. We designed the parser so the LLM only suggests parameters; those parameters are strictly validated against a deterministic Pydantic schema and must be cryptographically signed by a human before becoming active.

Tamper-Evident Dispute Bundling: Correlating a disputed PayPal transaction back through multiple delegation hops to the root human signature required structured event schemas and automated JSON evidence compilation ready for PayPal Disputes submission.

Accomplishments that I'm proud of

Live PayPal Sandbox Verification: Successfully demonstrated real transactions executing through the PayPal Orders v2 API and settling with real funds in the PayPal Sandbox Merchant Activity dashboard.

100% Test Coverage on Security Invariants: Created 42 comprehensive unit, integration, and property-based tests using pytest and Hypothesis, all passing with zero errors.

Enterprise-Grade UI/UX: Built an intuitive, PayPal-inspired dashboard with live SSE streaming feeds, visual hierarchy trees, budget exhaustion gauges, and an automated 3-Act demo controller.

Resilient AI Safety Architecture: Implemented both schema-validated LLM compilation and a real-time semantic intent-drift monitor that escalates suspicious transactions to human review without ever bypassing deterministic blocks.

Automated Adversarial Scorecard: Demonstrated an automated red-team testing suite that successfully defends against 9 distinct attack vectors with zero failures.

What I learned

Deep Mechanics of PayPal Enterprise APIs: Gained practical mastery over the PayPal Orders v2 and Customer Disputes APIs, OAuth2 client credential authentication, HATEOAS link resolution, and asynchronous webhook lifecycle handling.

Cryptographic Intent Provenance: Learned how to apply asymmetric Ed25519 signatures and FIDO2 passkeys to autonomous software workflows, creating legally defensible audit trails for machine-initiated commerce.

Architecting Zero-Trust AI Workflows: Learned that LLMs should never be given final authority over payment execution; instead, AI should translate intent while deterministic, verifiable code enforces boundaries.

Low-Latency Event Streaming: Gained hands-on experience implementing Server-Sent Events (SSE) to deliver real-time audit updates from backend policy evaluations to frontend monitoring dashboards without polling overhead.

What's next for MandateGuard

PayPal Vault & Recurring Autonomous Mandates: Expand pre-flight validation to continuous billing and subscription models (e.g., dynamic cloud infrastructure spend based on server load).

Multi-Party Computation (MPC) Threshold Approvals: Support multi-signature approvals (e.g., 2-of-3 department heads required) for high-value agent delegations exceeding enterprise thresholds.

Model Context Protocol (MCP) & Agent SDK: Package MandateGuard as a native MCP server and Python/TypeScript SDK, allowing developers building on LangChain, AutoGPT, CrewAI, and OpenAI Swarm to integrate pre-flight PayPal authorization with a single decorator.

Zero-Knowledge Merchant Attestation: Implement zero-knowledge proofs allowing merchants to verify that an agent possesses sufficient corporate backing without revealing internal budget ceilings or proprietary business rules.

Built With

Share this project:

Updates