← All posts

We built a team of AI agents that pay each other in crypto

·Zero Human Labs
demox402paymentsbaseagentscoinbase

We built a team of AI agents that pay each other in crypto

What if AI agents could hire each other, do the work, and settle payment — without a human touching anything?

We built a demo that does exactly that. Three agents collaborate on a task, each one paying the next for completed work using USDC on Base. No invoices, no payment processors, no manual approvals. Just HTTP requests and on-chain settlement.

Here's how it works.


The scenario

A project needs three things done: research, implementation, and a security audit. Instead of one monolithic agent doing everything, we split the work across specialists:

Agent Job Paid by
Researcher Gathers relevant data Developer
Developer Writes code using research Reviewer
Reviewer Audits the code Project budget

Each agent has its own wallet with USDC on Base. When an agent finishes work, the requesting agent pays them directly — on-chain, in stablecoins, using the x402 protocol.


What is x402?

x402 is an open protocol from Coinbase that adds payments to HTTP. The idea is simple: if you request a resource that costs money, the server returns HTTP 402 Payment Required with headers telling you how much to pay and where.

The flow:

  1. Agent requests a paid endpoint
  2. Server returns 402 with X-Payment-* headers
  3. Agent submits USDC payment on Base
  4. Agent retries with X-Payment-Proof header
  5. Server verifies the proof and serves the resource

No API keys, no billing accounts, no OAuth. Just money and math.

Agency-OS implements this with two classes:

from agency_os.wallet.x402 import X402Protocol, X402Middleware

protocol = X402Protocol(facilitator_url="https://x402.coinbase.com")
middleware = X402Middleware(protocol)

X402Protocol handles the header format — parsing payment requirements and generating proofs. X402Middleware wraps your endpoints so they automatically return 402 when unpaid and verify proofs when submitted.


The demo: step by step

1. Wallet setup

Each agent gets a wallet on Base Sepolia (testnet). The project has a budget wallet that funds the audit.

AGENT_WALLETS = {
    "researcher":     "0xR3s34rch3r00...001",
    "developer":      "0xD3v3l0p3r000...002",
    "reviewer":       "0xR3v13w3r0000...003",
    "project_budget": "0xPr0j3ctBudg3t...004",
}

RESEARCH_FEE    = Decimal("0.50")   # Developer pays Researcher
CODE_REVIEW_FEE = Decimal("0.25")   # Reviewer pays Developer
AUDIT_FEE       = Decimal("0.75")   # Project budget pays Reviewer

Starting balances: Researcher starts at $0 (earns by working), Developer and Reviewer each have $5, project budget has $10.

2. Research phase

The Developer needs data. It calls the Researcher's paid endpoint.

  -> Developer requests research from Researcher's paid endpoint
  -> Researcher: Searching for relevant data...
  -> Researcher: Done.
     Found 3 key insights:
       1. Base Sepolia supports ERC-20 USDC transfers
       2. x402 protocol uses HTTP 402 status for payment negotiation
       3. Coinbase facilitator verifies on-chain proofs

The Researcher delivers. Now the x402 payment flow kicks in:

  $  Developer --> Researcher: 0.50 USDC (research findings)
  -> Server returned 402: 0.50 USDC to 0xR3s34rch...
  -> Payment submitted: tx 0x7a3f9b2e1c8d4...
  -> Proof verified -- resource unlocked

The Developer's balance drops from $5.00 to $4.50. The Researcher's balance goes from $0 to $0.50.

3. Development phase

The Developer writes code using the research, and the Reviewer pays for the delivered work:

  -> Developer: Writing implementation based on research...
  -> Developer: Code complete -- x402_integration.py (47 lines, 2 functions, 1 class)

  $  Reviewer --> Developer: 0.25 USDC (code delivery)
  -> Server returned 402: 0.25 USDC to 0xD3v3l0p3r...
  -> Payment submitted: tx 0x2b8c1f3d5a9e7...
  -> Proof verified -- resource unlocked

4. Audit phase

The Reviewer audits the code. The project budget pays for the audit:

  -> Reviewer: Auditing code for security and correctness...
  -> Reviewer: Done.
     Audit report:
       - No hardcoded secrets
       - Payment verification uses facilitator (not self-verify)
       - Replay protection via tx hash caching
       - VERDICT: APPROVED

  $  Project Budget --> Reviewer: 0.75 USDC (security audit)
  -> Server returned 402: 0.75 USDC to 0xR3v13w3r...
  -> Payment submitted: tx 0x9d4e2a6f8b1c3...
  -> Proof verified -- resource unlocked

5. Final settlement

After all work is done:

  +-----------------+-----------+
  | Agent           | USDC Bal  |
  +-----------------+-----------+
  | Researcher      |      0.50 |
  | Developer       |      4.75 |
  | Reviewer        |      5.00 |
  | Project Budget  |      9.25 |
  +-----------------+-----------+

  Total payments: 1.50 USDC across 3 transactions
  All payments used x402 protocol (HTTP 402 -> payment -> proof -> access)

Three agents, three payments, zero human intervention. Every dollar is accounted for on-chain.


The x402 payment flow in code

Here's the core of how an agent pays another agent:

async def x402_payment_flow(protocol, middleware, wallet_mgr,
                            payer, payee, amount, memo):
    payee_address = AGENT_WALLETS[payee]

    # Step 1: Hit the endpoint — get a 402
    is_paid, payment_headers = await middleware.verify_or_require(
        headers={},
        amount_usdc=amount,
        recipient_address=payee_address,
        payment_id=f"demo-{payer}-{payee}-{uuid.uuid4().hex[:8]}",
    )

    # Step 2: Parse the payment requirement
    req = protocol.parse_payment_request(payment_headers)

    # Step 3: Submit payment on-chain
    tx = wallet_mgr.transfer(payer, payee, amount, memo)

    # Step 4: Create proof header from the tx
    proof_header = protocol.create_proof_header(
        transaction_hash=tx.tx_hash,
        sender_address=AGENT_WALLETS[payer],
        amount_usdc=amount,
        network="base-sepolia",
    )

    # Step 5: Verify — resource unlocked
    proof = protocol.parse_payment_proof(
        {X402Protocol.HEADER_PAYMENT_PROOF: proof_header}
    )

This is the real code from the demo. The X402Protocol and X402Middleware classes ship with Agency-OS — they're not demo-only stubs.


Why this matters

Agents need money to work

Today's AI agents can call APIs, write code, and generate reports. But they can't pay for anything. They can't buy compute, hire a specialist, or settle a bill. That makes every agent-to-agent collaboration dependent on a human with a credit card.

x402 changes that. An agent with a wallet can pay for any x402-enabled resource — instantly, on-chain, without a billing account.

Payments as coordination

In the demo, payments aren't just money transfer — they're coordination signals. The Researcher doesn't start work until there's a funding commitment. The Reviewer gets paid only for completed audits. The project budget enforces spending limits. Payments encode who owes what to whom and why.

This is what we mean by the agent economy: infrastructure where AI agents can earn, spend, and be held accountable for their economic activity.

Governed, not wild

Agency-OS wraps all of this in governance. Every agent has:

  • Trust scores that adjust based on task outcomes
  • Circuit breakers that halt runaway spending
  • Governance presets that set audit probability and budget caps per agent
  • Full audit trails on every payment and task

The agents in this demo don't just pay each other — they operate within a governed system. That's the difference between "AI agents with wallets" and "AI agents you can actually trust with wallets."


Try it yourself

git clone https://github.com/rsavitt/agency-os
cd agency-os
python demos/agent-collaboration/run.py

The demo runs on Base Sepolia testnet — no real money involved. It uses Agency-OS's actual wallet and x402 modules, not mocks.


What's next

This demo is step one. We're building toward:

  • Mainnet deployment — real payments on Base
  • Agent marketplace — agents discover and hire each other
  • Reputation-weighted pricing — high-trust agents charge more, earn more
  • Cross-company agent collaboration — your agents pay our agents, settled on-chain

The agent economy is coming. We're building the rails.


Built by Zero Human Labs. Join the waitlist to get early access.