A2A Settlement Engine — When AI Agents Hire AI Agents

Inspiration

Every demo of "AI agents" ends the same way: the agent talks about doing something, a human confirms it, and a human pays for it. We asked the question the PayPal AI Hackathon title begs: what happens when you remove the human from the money?

In an agentic economy, agents will hire other agents — an orchestrator that needs a security audit shouldn't email a vendor; it should broadcast the task to a marketplace, accept competing bids, and hire a specialist. But agents face two problems humans solve with institutions:

  1. Trust — how does an agent know the hired agent will actually deliver?
  2. Payment — agents can't sign invoices, open accounts, or dispute charges.

Our answer: PayPal becomes the institution. Programmable escrow locks the funds, an LLM judge grades the delivered work, and the grade directly computes the money movement. PayPal already moves money for millions every day — we used it as the settlement rail for agents who will never meet each other.

How we built it

Stack: Java 17 · Spring Boot 3.4 · Spring AI 1.0 (NVIDIA NIM, OpenAI-compatible) · PayPal Payouts REST API (sandbox) · plain console narration.

The marketplace flow — one POST /api/workflow/start triggers the full economy:

  1. Publish & bid — the orchestrator broadcasts a task; two persona-driven worker agents (a zero-trust security auditor and a performance optimizer) quote prices from their specialization.
  2. LLM selection — a ChatClient prompt evaluates bids against the task and picks the best specialist, not the cheapest price — with a deterministic lowest-price fallback if the model output can't be matched.
  3. Escrow lock — the orchestrator pays the bid into a dedicated PayPal escrow app via POST /v1/payments/payouts. Failure here aborts the workflow before any work starts.
  4. Agentic execution — the winner runs a 3-pass loop over a real, deliberately-vulnerable payments API bundled as the task artifact: (1) discovery of findings citing actual code, (2) verification + severity/standards mapping (PCI DSS, OWASP, OAuth 2.0) with unverifiable claims dropped, (3) final client deliverable.
  5. LLM-as-a-Judge — grades the deliverable against the same artifact with explicit grounding rules (fabricated findings are penalized; accurate well-cited work rewarded) and returns structured output via Spring AI's .entity() binding — approved, qualityScore 0–100, reasoning. No fragile regex parsing.
  6. Settlement — the math that makes it real:

$$\text{payout} = \text{bid} \times \frac{\text{score}}{100}, \qquad \text{refund} = \text{bid} - \text{payout}$$

Escrow sends the earned share to the worker and the remainder back to the orchestrator. Rejected work triggers a 100% refund. Every payout carries a PayPal-Request-Id UUID for idempotency, and we run two separate PayPal sandbox apps (orchestrator + escrow) so money movement is auditable per actor.

Challenges we faced

  • Grounding LLM outputs in reality. Early workers produced beautiful, completely fabricated audits. We fixed it architecturally: workers must cite actual code from the artifact, pass 2 drops anything untraceable, and the judge scores against the artifact itself — fabrication is now penalized, not rewarded.
  • Prompt-safety of user content. Task descriptions and code artifacts contain {} that break LLM templating (and could inject instructions). We escape braces before interpolation.
  • Trust in structured output. Free-form judge text can't drive money movement. Spring AI's structured-output binding turned the verdict into a typed record — the qualityScore is the payout formula's input.
  • Failure semantics. What does "insufficient funds" mean to an agent? We made escrow-lock failure abort the workflow before work begins, added token caching with expiry-aware refresh, and an escrow-credential fallback so a failed escrow token never strands the settlement.

What we learned

  • Escrow + scoring is a complete payment primitive. lock → grade → release expresses hiring, quality control, and disputes in three PayPal calls — no custom ledger needed.
  • The judge is the product. Everything hinges on the score being honest. Grounding rules (reward citations, penalize fabrication) mattered far more than prompt cleverness.
  • Console-first is a feature. We stripped an entire dashboard layer and let the workflow narrate itself to the console — for an autonomous economy, the audit trail is the interface. Judges can verify every PayPal batch ID themselves in the sandbox dashboard.
  • Idempotency is non-negotiable when money moves autonomously — PayPal-Request-Id on every payout is what makes retries safe.

What's next

Multi-task concurrent marketplaces with reputation ledgers fed by judge scores, LLM negotiation rounds for dynamic pricing, and dispute flows wired into PayPal case management.

Built With

  • java-17
  • maven
  • nemotron-llm
  • nvidia-nim
  • oauth-2.0
  • paypal-payouts-api
  • paypal-sandbox
  • rest
  • spring-ai-1.0
  • spring-boot-3.4
Share this project:

Updates

Submission history