Bun is used for local scripts (
setup,autonomy,client), while the Next.js runtime uses Node-compatible database access.
An AI agent that earns money, spends it, and adjusts its own pricing to survive. No humans required.
A self-operating entity with $50+ in real USDC that sells article summaries for $0.03, pays $0.018 in Ollama compute costs, and autonomously raises its price when running low all while tracking itself in SQLite.
Most AI demos show what an agent can do. This shows what an agent needs to do to survive.
- 💰 Real Economics: Uses actual USDC on Base Sepolia testnet (not simulated)
- 🧠 Local AI: Runs Mistral 7B on Ollama (no API keys, no cloud dependencies)
- 🔐 Real Wallet: OWS-managed local key custody with policy enforcement
- 📊 Autonomous: Adjusts price every 30 seconds based on balance
- 🎯 Observable: Every decision logged to SQLite for auditing
- ⚡ Fast Demo: 5-minute walkthrough from startup to "price adjustment"
- 🧰 Runtime Split: Bun for scripts; Next.js server uses the shared Node-compatible DB layer
┌─────────────────────────────────────────┐
│ BUYER (x402 Client) │
│ Makes paid requests → sends USDC │
└────────────────┬────────────────────────┘
│ HTTP + x402 Payment
▼
┌─────────────────────────────────────────┐
│ SELLER (Next.js Server) │
│ ✅ /api/summarize → x402 protected │
│ ✅ /api/stats → dashboard data │
│ ✅ / → live dashboard │
└────────────────┬────────────────────────┘
│
┌────────────┼────────────┐
▼ ▼ ▼
┌─────────┐ ┌────────┐ ┌──────────────┐
│ Ollama │ │ SQLite │ │ OWS Wallet │
│(Summarize)│(Ledger)│ │(Real USDC) │
└─────────┘ └────────┘ └──────────────┘
▲
│ Reads balance every 30s
┌────────────┴────────────┐
│ │
┌───────────────────────────────────────┐
│ AUTONOMY LOOP (Separate Process) │
│ 1. Read REAL USDC balance from OWS │
│ 2. Calculate margin from request data │
│ 3. Apply pricing policy │
│ 4. Update price if thresholds hit │
│ 5. Log decision to SQLite │
└───────────────────────────────────────┘
# Check you have Node 20+
node --version
# Have Ollama running locally
ollama serve &
# Pull the model (one-time, ~4GB)
ollama pull mistral:7b-instruct# Global OWS installation (includes CLI + Node bindings)
npm install -g @open-wallet-standard/core
# Create your wallet (generates addresses for all chains)
ows wallet create --name mvae-agent
# Get testnet USDC (visit https://faucet.circle.com/)
# Send to your wallet address from above
ows fund balance --wallet mvae-agent # Verify funds arrivedIf you're running Bun, use
bun run setup,bun run autonomy, andbun run client.
The Next.js app runs withbun run dev, but database access inside the Next server uses the shared Node-compatible SQLite layer.
cd mvae
# Create environment file
cat > .env.local << 'EOF'
# OWS Wallet
OWS_WALLET_NAME=mvae-agent
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
USDC_CONTRACT_ADDRESS=0x036CbD53842c5426634e7929541eC2318f3dCF7e
# LLM (Ollama local)
LLM_PROVIDER=ollama
OLLAMA_MODEL=mistral:7b-instruct
OLLAMA_BASE_URL=http://localhost:11434
# Database
DATABASE_PATH=./data/mvae.db
# Autonomy
AUTONOMY_CHECK_INTERVAL_MS=30000
MIN_PRICE=0.01
MAX_PRICE=0.50
CRITICAL_BALANCE_THRESHOLD=0.50
LOW_BALANCE_THRESHOLD=1.00
EOF
npm install# Terminal 1: Ollama (keep running)
ollama serve
# Terminal 2: MVAE Server + Dashboard
npm run dev
# Terminal 3: Autonomy Loop (in new mvae/ directory)
npm run autonomy
# Terminal 4: Make test requests
npm run client https://example.comOpen dashboard: http://localhost:3000
You'll see:
- 💰 Real USDC balance updating from on-chain
- 💹 Current price ($0.03 initially)
- 📊 Mode (normal/survival/growth)
- 📈 Charts and pricing history
Make requests: Run the client 20+ times rapidly to drain balance, then watch price jump after 30 seconds. 🎯
"Most AI demos show what an agent can do. This shows what an agent needs to do to survive.
This system has $50 in real USDC on a blockchain. It sells article summaries for $0.03 each. Each summary costs it $0.018 in compute. That's a 40% margin.
But watch what happens when it runs low on money."
-
Show the wallet (point to dashboard):
"Real USDC on Base Sepolia: $50.00" -
Show the pricing:
"Current price: $0.03 per request Margin: 40% profit per sale Mode: normal (healthy)" -
Make requests:
npm run client https://example.com # x20 rapidly"Each request costs $0.018 and generates $0.03 revenue. Zero cloud infrastructure. All local." -
Watch balance drop on dashboard (should show $45, $40, $35...)
-
Wait 30 seconds for autonomy loop to run
-
Price jumps:
"Watch the price." [Wait 30s] "Price just jumped from $0.03 to $0.036. Nobody told it to do this. The agent just raised its own prices because it was running low." -
Close strong:
"This is not a chatbot. This is not an API wrapper. This is the simplest thing that qualifies as economically autonomous. An organism, not a product."
| Section | What It Shows |
|---|---|
| Balance (Top Left) | Real USDC from your OWS wallet on-chain |
| Current Price (Top Middle) | What you charge per request (set by autonomy) |
| Mode (Top Right) | normal/survival/growth based on balance |
| Margin % (Top Right) | (Revenue - Cost) / Revenue |
| Requests Chart | Number of requests over time |
| Revenue Chart | Total revenue earned |
| Price History | Every price adjustment with reason |
| Recent Requests | Last 10 requests with revenue/cost/margin |
The loop runs every 30 seconds:
// 1. Read REAL balance from OWS
const balance = await wallet.getBalance(); // $50.00 → on-chain!
// 2. Calculate margin from request history
const avgMargin = calculateMargin(requests); // 40%
// 3. Apply policy rules
if (balance < $0.50) {
price *= 1.20; // CRITICAL: raise 20%
mode = 'survival';
} else if (balance < $1.00) {
price *= 1.10; // WARNING: raise 10%
} else if (avgMargin < 10%) {
price *= 1.10; // MARGIN SQUEEZE: raise 10%
} else if (balance > $5.00) {
price *= 0.95; // GROWTH: lower 5%
}
// 4. Log decision to SQLite (audit trail)
insertPricingHistory(newPrice, reason, balance, margin);
// 5. Dashboard updates in real-timeResult: Economic behavior emerges from simple rules. 📈
SQLite (data/mvae.db) contains:
- requests Every summarize request (revenue, cost, margin)
- transactions Payment ledger (income/expense)
- pricing_history Every price adjustment with reasoning
- agent_state Current state snapshot (balance, mode, requests served)
- config Mutable settings (current price, mode)
All data is append-only for auditability. 🔒
Costs money to call. Returns article summary.
curl -X POST http://localhost:3000/api/summarize \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'Response:
{
"success": true,
"summary": "- Point 1\n- Point 2\n- Point 3",
"metrics": {
"revenue": "0.03",
"cost": "0.018",
"margin": "0.012",
"marginPct": "40.00"
}
}Dashboard data endpoint.
curl http://localhost:3000/api/statsResponse: Real-time balance, price, mode, pricing history, recent requests.
ows wallet list # Should show mvae-agent
ows wallet create --name mvae-agent # If not thereows fund balance --wallet mvae-agent # Check funds
# If 0, get testnet USDC from https://faucet.circle.com/# Test the RPC
curl https://sepolia.base.org -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'The app is configured so the Next server uses the shared database layer instead of importing Bun-only modules. If you see this error, make sure you're on the latest code and restart bun run dev.
curl http://localhost:11434/api/tags
# If fails, ensure: ollama serve is running in Terminal 1# Use different port
PORT=3001 npm run devThe agent is not following instructions it's observing its own financial state and changing behavior to maximize survival. This is the minimal definition of economic autonomy.
Local, encrypted key custody. Your wallet lives on your machine, not in cloud. OWS handles signing, policy enforcement, and multi-chain support.
Testnet stablecoin. Real blockchain (you can verify on Basescan), but fake money. Perfect for demos.
Standard way to make HTTP endpoints chargeable. When you hit an endpoint without payment proof, you get HTTP 402 + payment request.
Local LLM inference. Mistral 7B runs on any modern laptop. ~2.5GB memory, no internet required after model download.
Building this teaches:
- OWS wallet management and policy engines
- On-chain balance queries with viem
- Autonomous agent loops that observe → decide → act
- x402 payment protocol implementation
- Economic design how policy rules create behavior
- SQLite as ledger for audit trails
This is a demo. To scale:
- Deploy server to production (Railway, Vercel, AWS)
- Use real USDC on mainnet (not testnet)
- Implement persistent OWS vault (encrypted at rest)
- Add monitoring and alerting on balance
- Implement spending policies (daily limits, etc.)
- Scale LLM (switch to OpenAI API or self-hosted vLLM)
- Add competitor agents (watch market dynamics emerge!)
- Open Wallet Standard Local wallet custody
- x402 HTTP 402 micropayments
- Ollama Local LLM inference
- Viem EVM interactions
- Next.js Server + dashboard
- Better SQLite3 Fast embedded database
MIT
This is the minimal viable example of an economically autonomous agent. The interesting questions are:
- What happens when you give it $1,000?
- What happens when there are 10,000 of them?
- Can agents form markets with each other?
- What policies create stable ecosystems?
Start building. Let's find out. 🚀
