Inspiration Agentic commerce promises autonomous buying and selling, but it lacks deterministic guardrails. Individuals fear runaway spending or subscription traps, while merchants fear ruinous discounts and post-purchase disputes. We wanted to build a secure, trustless system where AI negotiates on behalf of humans, but a deterministic engine ensures no one ever gets a bad deal, and all transactions are settled securely.

What it does Orderly-AI implements a two-sided policy-bounded agent architecture on the PayPal Sandbox:

Autonomous Negotiation: A Buyer Agent and Seller Agent formulate offers and counter-offers using structured JSON schemas via Google Gemini 3.5.

Deterministic Guardrails: A pure TypeScript policy engine validates every proposal in code before it reaches the opposing agent or PayPal. It enforces hard price ceilings, merchant floor prices, bundle discount rules, and blocks unauthorized claims.

Human-in-the-Loop Settlement: When agents agree, the final purchase requires explicit human approval via native PayPal JavaScript SDK Buttons. It creates and captures the payment using PayPal Orders v2.

AI Dispute Mediation: If an issue arises post-purchase (e.g., damaged transit), an impartial Mediator Agent reads the negotiation transcript, purchase data, and merchant policies to recommend a resolution (full refund, partial refund, or contest), citing specific clauses. The merchant executes the real refund via PayPal Payments v2.

Tamper-Evident Auditability: Every turn, policy verification, and webhook is logged in an append-only, SHA-256 hash-chained ledger displayed in an interactive AG Grid Community dashboard.

How we built it Framework: Built a high-performance reactive marketplace using Next.js 14 (App Router), TypeScript, and TailwindCSS.

Payments & E-commerce: Integrated PayPal Orders v2 (Capture intent), Payments v2 (Refunds), Webhooks v1, and the official @paypal/agent-toolkit/ai-sdk.

AI & Logic: Utilized Google Gemini 3.5 Flash for structured outputs enforced by runtime Zod validation. We built a Pure TypeScript Policy Engine to intercept and validate every LLM output.

Dashboard & Security: Implemented AG Grid Community v32 for a high-performance audit ledger, backed by SHA-256 hash chaining for tamper-evidence.

Challenges we ran into LLM Hallucinations & Schema Adherence: AI models can sometimes suggest prices outside the bounds of human policies or return malformed JSON. We solved this by forcing application/json responses with strict Zod parsing, and implementing a deterministic fallback generator that takes over if the model fails its policy constraints twice.

Webhook Security: Handling asynchronous payment captures securely required strict adherence to PayPal's documentation. We implemented mandatory 5-header transmission validation, cryptographic signature verification via PayPal's official endpoints, and a bounded LRU deduplicator to prevent double-processing.

Accomplishments that we're proud of Successfully combining generative intelligence (Gemini) with mathematical safety guarantees (our Policy Engine) so the AI literally cannot violate user-defined financial constraints.

Executing a seamless end-to-end sandbox flow: from AI negotiation, to human authorization via native PayPal buttons, to final capture and automated AI dispute resolution.

Our comprehensive test suite covering pure policy logic, cryptographic hash chains, API routing, and webhook security.

What we learned Building autonomous commerce tools requires a shift from "prompt engineering" to "policy engineering." Generative AI is fantastic for strategy and communication, but classical determinism (hard-coded rules and SDKs) is absolutely mandatory when dealing with financial transactions and user trust.

What's next for Orderly-AI We plan to expand Orderly-AI into WhatsApp Business & Conversational Social Commerce, allowing buyers to negotiate directly in chat while the policy engine ensures discounts stay legal and generates an approved PayPal payment link on the spot. We also see massive potential in B2B wholesale procurement and enterprise e-commerce platforms to slash chargeback overhead using our AI Mediator Agent.

Built With

Share this project:

Updates

Submission history