Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I Built an Autonomous AI Agent That Earns USDC While I Sleep

Description and use

Built an autonomous on‑chain AI service that accepts USDC payments via x402, processes requests with LangChain, and forwards earnings to a wallet.

Problem

Develop a self‑serving micro‑service that accepts instant USDC payments on Base, processes requests via an LLM, and forwards profits to a wallet.

Outcome

Implemented a continuous, payment‑validated AI micro‑service that earns a few USDC per call, demonstrating the integration of on‑chain payments with LLM tooling.

Workflow

  • 1. Create a FastAPI app exposing desired endpoints (e.g., /summarize).
  • 2. Wrap each endpoint with x402 middleware to validate USDC payment via X‑Payment‑Header.
  • 3. Deploy a payment watcher that scans Base for incoming USDC to the escrow address, confirms amounts, and pushes jobs to a Redis queue.
  • 4. Build an Agent Core using LangChain: define tools (e.g., URLSummarizer), initialize the agent with a model (gpt‑4o‑mini), and set up prompt handling.
  • 5. Consume jobs from the queue, run the appropriate tool via the agent, and return the result to the HTTP caller.
  • 6. Run all components in a single Docker‑Compose file for development; separate services for production.
  • 7. Monitor logs, handle retries, and forward net profit to the owner’s wallet.

Evidence

The agent runs continuously, watches for incoming payments, fulfills the request, and forwards the net profit to a wallet you control.

Source

I used the open‑source x402-py middleware (a thin wrapper around FastAPI) to verify that the caller has sent enough USDC to cover the price before the request reaches my route.

Source

  • Record date: 2026-09-14T17:45:31.766Z