Ryuk — Intent Before Payment

Inspiration

The idea that an AI could make a payment by itself got me excited. After reading about x402 and other payment protocols, I started imagining agents that could take a request, find the right option and complete a purchase.

But that raised a question: how do we make sure the agent is paying for what we actually asked for?

A hotel can be within budget and still be the wrong purchase if it lacks a mandatory gym or free cancellation. I wanted to explore the checks between understanding an instruction and spending money.

That became Ryuk: a prototype for intent-aware commerce where the LLM proposes, and the deterministic backend authorizes spending. x402 inspired the idea; the submitted implementation uses PayPal Sandbox Orders v2, with explicit human review and separate PayPal buyer approval. It does not implement x402 or unattended payments.

What it does

Ryuk turns a plain-language hotel request into structured requirements, compares offers from a synthetic catalog and explains whether each offer satisfies the request.

A buyer can:

  • Set a total budget, currency and approval threshold.
  • Separate mandatory requirements from preferences.
  • Inspect evidence behind requirement checks and policy decisions.
  • Compare the original instruction with the parsed interpretation and source quotes.
  • Approve exact purchase terms, then authorize checkout through PayPal Sandbox.
  • Inspect the backend-confirmed payment result, budget and audit trail.

Synthetic inventory. PayPal Sandbox only. No real hotel booking or real money.

How I built it

I built the interface with Next.js and TypeScript, and the backend with Python, FastAPI and Pydantic. SQLite persists proposals, approvals, checkout records, budget holds and audit history. Docker Compose packages the application.

The intent parser supports Groq or OpenAI through backend-only structured-output calls. Schema validation and source checks constrain the output, but the model never receives spending authority.

The verifier checks offer attributes against the buyer's requirements. Deterministic policy evaluates budget, currency, merchant eligibility, mandatory requirements, approval and duplicate protection. Before capture, the backend reloads the authoritative records and revalidates the purchase terms.

PayPal Sandbox provides order creation, buyer authorization and capture. Ryuk verifies the provider response before showing success.

AI tools used

I used Codex for implementation, tests and documentation assistance, and Claude review feedback during development. The application's model integration is separate from those development tools: it extracts proposed constraints and cannot approve or execute a payment on its own.

Challenges I faced

Understanding intent without trusting the model blindly

A response can have the correct JSON structure while missing an important requirement. I added a review step showing the original instruction beside the parsed mandatory and preferred requirements, including retained source quotes.

This makes mistakes easier to spot, but it does not prove that every instruction was understood. Human review remains necessary.

Preventing duplicate payments

Double clicks, concurrent requests and network failures complicate checkout. I implemented atomic budget reservations, durable execution claims and stable idempotency keys so repeated requests do not become repeated payments.

Handling uncertain outcomes

A timeout does not necessarily mean a payment failed. The provider may have completed the operation before the response was lost. Ryuk preserves that uncertainty and checks provider status instead of blindly repeating a capture.

Connecting PayPal approval to backend truth

Browser blocking, popups and asynchronous callbacks made integration challenging. I had to distinguish application approval, PayPal buyer authorization and confirmed capture. A browser callback alone cannot mark a payment successful.

Keeping the review screen understandable

Showing source quotes, verification evidence, policy reasons and exact financial terms made the approval dialog cluttered. I refined the reading order, responsive layout and Sandbox notice so the buyer can review the decision more clearly.

Testing safely and reproducibly

I needed tests that could exercise failures and duplicate requests without touching the existing demo ledger or making live payment calls. Isolated fixtures, temporary databases and mocked model/provider responses made those scenarios reproducible.

What I learned

I started with excitement about an AI that could pay. Building Ryuk taught me how much work belongs between an agent's suggestion and a financial action.

  • Schema-valid output is not the same as correct understanding.
  • A purchase needs both financial checks and requirement verification.
  • Consent must bind to exact terms.
  • Financial actions need durable duplicate protection.
  • An uncertain outcome should remain visible until it can be reconciled.
  • Automated tests and live acceptance demonstrate different things.

The submission implementation passed 1,114 backend tests, 25 frontend helper tests, frontend lint/type checks and a production build. Isolated browser checks supplement that evidence; they do not establish production readiness or a measured live three-minute run.

What's next

The submitted build focuses on buyer-approved PayPal Sandbox checkout. The longer-term goal is to explore more autonomous purchasing with explicit spending mandates, suitable payment-provider support and stronger operational safeguards.

Migrations, optional multi-user authentication, provider monitoring and reviewed refunds are being explored on a separate production-foundation branch. They are not included in the submitted build.

Real inventory, booking fulfillment and production payments remain future work.

Built With

Share this project:

Updates

Submission history