Agentx402

Multi-agent workflow using AP2 with Polygon x402 for autonomous payments.

Agentx402

Created At

ETHGlobal New Delhi

Project Description

This project combines Polygon's x402 and Google's AP2 Agentic Framework, demonstrating how multiple-agent AI workflows can seemlessly connect to on-Chain Settlement. In this project we have used a simple "hoodie purchase" scenario to illustrate how AI Agent can collaborate and then settle payments using x402. Our prototype highlights:

  • Agent orchestration via AP2 – multiple AI agents communicating in a structured workflow.
  • On-chain payments via Polygon x402 – final step of the workflow triggers real USDC settlement.
  • Extensible design – while we demo a simple two-agent setup, this architecture can be scaled to complex, multi-agent workflows (e.g. multiple wallet swaps, managing multiple liquidity portfolios etc. ).

By combining AP2 and x402, we demonstrate a path toward autonomous, AI-native commerce, where agents handle the full pipeline from decision-making to settlement on-chain.

How it's Made

This project uses Google's AP2 and Polygon's x402 for creating an autonomous workflow where AI Agents reason, plan, negotiate, and then hand off to an autonomous payment layer for final settlement.

  1. Multi-Agent Workflow (AP2 in Python) We used AP2's orchestration patterns to define a multi-agent workflow. Each agent plays a specific role:
  • Agent 1 (Recommender Agent): This Agent uses Gemini's LLM to analyze the mock product data set and then provide with the most apt product according to the user's input.
  • Agent 2 (Checkout Agent): This Agent converts Agent 1's recommendation into an order and checks if the user has any discount copouns (NFTs), and then proceeds to checkout and pass on the order,payment information to the cleint's agent. This seperation of responsibilities demonstrate how AP2 workflows allow agents to specialize and pass control between them, For example, you can imagine building a website, SAAS startup with the help of LLMs, you'd want to use Gemini for the overall structure, planning then passing over the command to Claude or Open AI's LLM for building the product.
  1. On-Chain Settlement (x402) The checkout agent passes the payment details to our JS client, which uses x402 standard to handle blockchain-native settlement.
  • Client Layer (Node.js) It Interprets the payment details and uses x402-axios withPaymentInterceptor method to automatically detect and respond to HTTP 402 Payment Required Challenge, Excutes USDC Payment on Polygon Amoy Testnet using viem wallet client for the user.
  • Merchant Layer (Node.js + Express) It uses x402-express middleware as a protection and enforces a payment requirement ( Validates the USDC txn on chain), once successful responds with "Order Placed, Transaction Successful".
  1. Why AP2 + x402 Together ? AP2 enables multi-agent reasoning and workflows while x402 enable settlement enforcement (no agent can skip payment, transaction is validated on-chain), both of these together pose a killer combo for AI-native commerce.

  2. Tech Stack

  • Python (AP2 + LLM Orchestration)
  • JavaScript (x402 Settlement - viem, x402-axios, x402-express)
  • Vite + React.js (frontend)
background image mobile

Join the mailing list

Get the latest news and updates