Inspiration
Autonomous AI agents move quickly until they run into real-world ambiguity—conflicting hardware datasheets, breaking production edge cases, security sign-offs, or undocumented protocol behaviors. When an agent hits low confidence, it either hallucinates an answer or stalls a workflow completely.
Meanwhile, existing freelance platforms weren't built for software agents: they require human-to-human back-and-forth, allow anyone to click self-declared profile tags without proof, and return unverified free-form text that an AI pipeline cannot safely trust.
We built TrustToPay to give autonomous AI systems a deterministic, trustworthy bridge to skill-tested human expertise—backing every task with PayPal escrow before work starts, mandatory L1–L3 skill certification, fail-closed multi-layer verification, and an HMAC-SHA256 signed handback.
What it does
TrustToPay orchestrates a complete 6-stage escalation and verification protocol between AI requesters (via Web UI, REST API, or MCP) and human specialists:
- Task Framing & Clarity Analysis: Requesters (or autonomous agents) submit a task across Programming, Crypto & blockchain, Conceptual, or Hardware compatibility. TrustToPay computes a rule-based clarity confidence score \(C\) and escalates whenever \(C < 0.75\) (below the 75% threshold), surfacing missing context, open questions, conflicting attachments, suggested budget, and required skills before dispatch.
- Upfront Escrow via PayPal Checkout: Before any specialist can view or claim a task in the marketplace, escrow funds ($5.00–$100.00 USD) are captured upfront via PayPal Orders v2 with webhook integrity checks (
/api/webhooks/paypal). - Mandatory L1–L3 Skill Verification: "No passed test, no tasks." Specialists cannot claim jobs by selecting unverified profile tags. Across 115 skills in 12 categories, each skill remains locked until the specialist passes sequential assessments (Foundation L1 \(\to\) Practitioner L2 \(\to\) Advanced L3) with live camera and screen proctoring checks.
- Semantic Hybrid Matching & Dispatch: Funded tasks are matched against verified specialists using Jina AI (
jina-embeddings-v3, 1024-dimensional vectors) and Elasticsearch hybrid retrieval (trusttopay-specialists-v1), then scored deterministically across verified skill level, historical acceptance rate, and turnaround speed before dispatching top-5 invitations:
$$ S = 0.50 S_{\mathrm{skill}} + 0.30 S_{\mathrm{verify}} + 0.20 S_{\mathrm{speed}} $$
- Dual-Layer Automated Verification Gate: Submitted work is verified by:
- Deterministic Evidence & Citation Rules: Explicit 80+ char conclusion without hedging, concrete technical specifics, independent public
https://reference URLs, and a verbatim"quoted excerpt"(15+ chars). - Static Security Scanner & Fail-Closed Gemini Gate: Scans for exposed secrets (
sk-...,AKIA..., private keys), destructive shell commands, and prompt injection—backed by Google Gemini (CODE_REVIEW_FAIL_CLOSED=true) and an isolated acceptance check runner.
- Deterministic Evidence & Citation Rules: Explicit 80+ char conclusion without hedging, concrete technical specifics, independent public
- Signed Cryptographic Handback (
HMAC-SHA256): Once verified (PASSED), TrustToPay hashes the canonical artifact (SHA-256) and issues signed headers (X-TrustToPay-Signature,X-TrustToPay-Artifact-Sha256) so the requesting agent can cryptographically verify integrity before resuming execution.
How we built it
- Frontend (
frontend/): React 18, TypeScript, Vite 6, Tailwind CSS, Radix UI primitives, TanStack Query, and Recharts—powering the Requester Workspace, Specialist Marketplace, L1–L3 Assessment Flow, Safety & Quality Reports, and Escrow Ledger. - Backend API (
backend/): Node.js (>=20), Express 4, Prisma 6 ORM, Zod schema validation, Helmet, and Express Rate Limit—running on Render with managed PostgreSQL in production and SQLite (schema.sqlite.prisma) for offline local simulation (DEMO_MODE=true). - Authentication & Identity: Supabase Auth with PKCE, JWT validation,
HttpOnlysession cookies, and scopedAgentApiKeytokens (ttp_test_...) for headless autonomous callers. - Payments & Notifications: PayPal Orders v2 JS SDK + server-side order capture, webhook verification, transaction reconciliation, CSV audit export, and Resend idempotent email delivery for priority specialist offers.
- Hybrid Search & AI Safety: Jina AI semantic embeddings synced to Elasticsearch (
trusttopay-specialists-v1, with PostgreSQL fallback) and Google Gemini (gemini-3.8-flash) layered behind deterministic scanners. - Agent-Native Tooling:
- MCP Server (
@trusttopay/mcp-server): Supports bothSTDIOandStreamable HTTP, exposing strictly 4 scoped tools (trusttopay_create_task,trusttopay_get_task_status,trusttopay_get_verified_result,trusttopay_cancel_task). - Reusable Agent Skill (
skills/trusttopay/SKILL.md): Installable vianpx skills add https://github.com/HarmanPahalajani/TrustToPay --skill trusttopaywith documented escalation thresholds. Also Used AG Grid For Dashboards and analytics. ---
- MCP Server (
Challenges we ran into
- Fail-Closed Safety vs. External AI Rate Limits: Relying blindly on an LLM reviewer breaks trust if upstream APIs throttle (
429) or time out. Designing the pipeline withCODE_REVIEW_FAIL_CLOSED=trueensured external failures drop safely intoNEEDS_HUMAN_REVIEWrather than auto-passing uninspected code, while deterministic citation and secret scanners catch structural violations immediately. - PayPal Sandbox Cross-Region & Payout Constraints: Integrating real PayPal Orders v2 surfaced two strict Sandbox rules: USD checkout requires a US Personal Sandbox Buyer account, and India-registered merchant accounts restrict outbound PayPal Payouts (
PAYPAL_PAYOUTS_ENABLED=false). We surfacedPAYOUT_UNAVAILABLEtransparently in the live ledger—while keeping Sandbox escrow capture, automated verification, and HMAC handback fully live—and enabledDEMO_MODE=truefor full local payout simulation. - Cookie Isolation During Multi-Role Evaluation: Testing both Requester and Reviewer roles from the same browser origin causes
HttpOnlysession cookies to overwrite each other, so we documented strict window isolation, built scoped API keys, and pre-seeded 8 full-lifecycle evaluation scenarios (A–J). - Dual-Database Parity: Keeping Render's PostgreSQL schema aligned with zero-setup local SQLite development required strict schema parity validation (
npm run db:validate) across migrations and seed scripts.
Accomplishments that we're proud of
- End-to-End Agent Loop Without Compromising Safety: An AI agent detects a blocker via the TrustToPay Skill, opens an idempotent escrow task over MCP or REST, waits for a skill-tested human to respond, inspects a dual-layer verification report (12/12 checks passed on completed scenarios), and validates the
HMAC-SHA256payload before consuming it. - Zero-Fluff Skill Gatekeeping: Implemented sequential
L1–L3assessments across 115 skills in 12 domains backed by PostgreSQL persistence and real-time Elasticsearch + Jina vector re-indexing upon passing. - Production Transparency & Verifiable State: Deployed live on trusttopay-frontend.onrender.com with Swagger/OpenAPI docs (
/api-docs), real PayPal Sandbox checkout, deterministic rejection auditing (Scenario C), and realistic edge-case scenarios (Scenario F and Scenario G).
What we learned
- Determinism Must Anchor Probabilistic AI: LLMs excel at semantic nuance, but deterministic structural gates (regex secret scanning, public
https://URL checks, non-hedging conclusion length, and verbatim evidence quotes) make verification faster, cheaper, and resistant to prompt injection. - Least-Privilege Agent Surfaces Matter: Scoping
@trusttopay/mcp-serverto strictly 4 requester-only tools prevents compromised agent prompts from invoking specialist-only endpoints, bypassing safety gates, or altering escrow payouts. - Honest Financial State Machines Beat Fake "Success" UI: Explicitly modeling
AWAITING_FUNDING,FUNDED,VERIFICATION_REJECTED,NEEDS_HUMAN_REVIEW, andPAYOUT_UNAVAILABLEstates makes debugging and third-party auditing transparent.
What's next for TrustToPay
- Automated Multi-Currency Payouts: Enable automated PayPal Payouts / Hyperwallet disbursement for supported merchant regions so verified specialists settle instantaneously upon passing checks.
- Sandboxed Execution Enclaves: Upgrade the isolated acceptance runner into ephemeral containerized sandboxes so submitted code patches compile and run untrusted test suites safely before
PASSEDtransitions. - Multi-Reviewer Quorum for High-Stakes Tasks: Extend single-reviewer completion on tasks \(\ge\) $50.00 USD or
Highpriority into cryptographic \(N\)-of-\(M\) consensus reviews for security and smart-contract audits. - Native Framework Plugins: Publish turnkey integrations beyond MCP for LangGraph, CrewAI, and OpenAI Agents SDK so developers can add verified human escalation in a few lines of code.
Built With
- css
- elasticsearch
- express.js
- gemini
- jinaai
- node.js
- paypal
- paypalsdk
- postgresql
- prisma
- react
- render
- supabase
- typescript
- vite