freshcrate
Home > AI Agents > Minimum-viable-autonomous-entity

Minimum-viable-autonomous-entity

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 itsel

Description

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.

README

🤖 MVAE Minimum Viable Autonomous Entity

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.

One-Sentence Pitch

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.


✨ What Makes This Different

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

🏗️ Architecture at a Glance

┌─────────────────────────────────────────┐
│         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             │
└───────────────────────────────────────┘

🚀 Quick Start (10 minutes)

1. Prerequisites

# Check you have Node 20+
node --version

# Have Ollama running locally
ollama serve &

# Pull the model (one-time, ~4GB)
ollama pull mistral:7b-instruct

2. Install OWS & Create Wallet

# 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 arrived

2. Configure MVAE

If you're running Bun, use bun run setup, bun run autonomy, and bun run client.
The Next.js app runs with bun 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

4. Start Everything

# 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.com

5. Watch It Work

Open 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. 🎯


🎬 The 5-Minute Demo Script

Opening (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."

Live Flow

  1. Show the wallet (point to dashboard):

    "Real USDC on Base Sepolia: $50.00"
    
  2. Show the pricing:

    "Current price: $0.03 per request
     Margin: 40% profit per sale
     Mode: normal (healthy)"
    
  3. 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."
    
  4. Watch balance drop on dashboard (should show $45, $40, $35...)

  5. Wait 30 seconds for autonomy loop to run

  6. 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."
    
  7. 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."


📊 Dashboard Guide

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

🤖 How Autonomy Works

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-time

Result: Economic behavior emerges from simple rules. 📈


💾 Database Schema

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. 🔒


🔧 API Endpoints

POST /api/summarize (x402-protected)

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"
  }
}

GET /api/stats (Public)

Dashboard data endpoint.

curl http://localhost:3000/api/stats

Response: Real-time balance, price, mode, pricing history, recent requests.


🚨 Troubleshooting

"OWS wallet not initialized"

ows wallet list  # Should show mvae-agent
ows wallet create --name mvae-agent  # If not there

"Balance shows $0"

ows fund balance --wallet mvae-agent  # Check funds
# If 0, get testnet USDC from https://faucet.circle.com/

"Cannot connect to RPC"

# 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}'

"Next.js complains about bun:sqlite"

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.

"Ollama not responding"

curl http://localhost:11434/api/tags
# If fails, ensure: ollama serve is running in Terminal 1

"Port 3000 already in use"

# Use different port
PORT=3001 npm run dev

📚 Key Concepts

Economic Autonomy

The 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.

OWS (Open Wallet Standard)

Local, encrypted key custody. Your wallet lives on your machine, not in cloud. OWS handles signing, policy enforcement, and multi-chain support.

USDC on Base Sepolia

Testnet stablecoin. Real blockchain (you can verify on Basescan), but fake money. Perfect for demos.

x402 HTTP Payment Protocol

Standard way to make HTTP endpoints chargeable. When you hit an endpoint without payment proof, you get HTTP 402 + payment request.

Ollama

Local LLM inference. Mistral 7B runs on any modern laptop. ~2.5GB memory, no internet required after model download.


🎓 What You'll Learn

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

🎯 Production Roadmap

This is a demo. To scale:

  1. Deploy server to production (Railway, Vercel, AWS)
  2. Use real USDC on mainnet (not testnet)
  3. Implement persistent OWS vault (encrypted at rest)
  4. Add monitoring and alerting on balance
  5. Implement spending policies (daily limits, etc.)
  6. Scale LLM (switch to OpenAI API or self-hosted vLLM)
  7. Add competitor agents (watch market dynamics emerge!)

📖 Documentation


🙏 Built With


📜 License

MIT


💬 Questions?

This is the minimal viable example of an economically autonomous agent. The interesting questions are:

  1. What happens when you give it $1,000?
  2. What happens when there are 10,000 of them?
  3. Can agents form markets with each other?
  4. What policies create stable ecosystems?

Start building. Let's find out. 🚀

Release History

VersionChangesUrgencyDate
0.0.0No release found — using repo HEADHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchHigh4/11/2026
main@2026-04-11Latest activity on main branchMedium4/11/2026
main@2026-04-11Latest activity on main branchMedium4/11/2026
main@2026-04-11Latest activity on main branchMedium4/11/2026

Dependencies & License Audit

Loading dependencies...

Similar Packages

serverlessclawOfficial ServerlessClaw: The authoritative autonomous AI agent swarm for AWS. Zero idle cost, self-evolving, and infinite scale. Powered by OpenClaw.main@2026-04-21
opencowOne task, one agent, delivered. The open-source platform for task-driven autonomous AI agents.OpenCow assigns an autonomous AI agent to every task — features, campaigns, reports, audits — and deliverv0.4.2
skalesYour local AI Desktop Agent for Windows, macOS & Linux. Agent Skills (SKILL.md), autonomous coding (Codework), multi-agent teams, desktop automation, 15+ AI providers, Desktop Buddy. No Docker, no terv10.0.4
Autonomous-Skill-Builder-Agent🛠️ Build personalized learning paths with the Autonomous Skill Builder Agent, leveraging AI to enhance skill mastery and adaptive learning experiences.main@2026-04-20
night-watch-cliAI agent that implements your specs, opens PRs, and reviews code overnight. Queue GitHub issues or PRDs, wake up to pull requests.master@2026-04-20