Skip to content

mattabb2020/PennyAgent

Repository files navigation

PennyAgent

AI agents that think before they spend.

PennyAgent makes AI agents financially intelligent — they don't just spend, they think before they spend. Budget-aware, policy-driven micropayments on Stellar, powered by Claude.

Hackathon submission for Stellar Hacks: Agents — April 2026

Live Demo: pennyagent.ai | Product Page: pennyagent.ai/about | Try the Agent: pennyagent.ai/app

Contact the founder: matias@pennyagent.ai | @m8tiasX on X


The Problem

AI agents can execute tasks, but they're economically blind. When an agent needs paid data — news feeds, analytics, research — it either buys everything (wasting money) or buys nothing (missing critical data). There's no financial reasoning layer.

$7.84 billion AI agent market. 75 million x402 transactions last month. Zero economic reasoning.

The Solution

PennyAgent gives AI agents a financial brain. Before every purchase, the agent:

  1. Discovers available paid tools and their prices
  2. Evaluates whether each tool's data is worth the cost (powered by Claude)
  3. Checks spending policy (budget limits, per-tool caps, allowlists)
  4. Decides to buy or skip — with visible reasoning
  5. Pays via x402 on Stellar testnet (real transactions, ~5 second settlement)
  6. Reports every decision with reasoning cards and transaction receipts

The demo moment: the agent visibly choosing NOT to buy an expensive tool (over policy limit), then buying a cheaper one that delivers enough value. That decision IS the product.

How It Works

User: "Research solar energy stocks" + $0.10 budget + $0.03 max per tool
                                    ↓
                    ┌─────────────────────────────────┐
                    │        PennyAgent Core           │
                    │                                   │
                    │  1. Discover 4 tools (1 free,     │
                    │     3 paid at $0.005-$0.08)       │
                    │                                   │
                    │  2. Run free tool first            │
                    │                                   │
                    │  3. For each paid tool:            │
                    │     Claude evaluates worth  ───►  │
                    │     Policy engine checks   ───►  │
                    │     Both approve? → Pay via x402   │
                    │     Either says no? → Skip + log   │
                    │                                   │
                    │  4. Synthesize final answer        │
                    └─────────────────────────────────┘
                                    ↓
Result: Answer + Decision timeline + Stellar transaction receipts
        "Spent $0.015 of $0.10 | 2 transactions | 1 tool skipped"

Architecture

graph TB
    UI[Next.js Frontend] -->|POST /api/run-agent| Server[Unified Express Server]
    Server --> AgentCore[Agent Core]
    AgentCore --> Claude[Claude API - Reasoning]
    AgentCore --> Policy[Policy Engine]
    AgentCore --> Free[Free Market Overview]
    AgentCore -->|x402 payment| News[Paid News Digest - $0.005]
    AgentCore -->|x402 payment| Sentiment[Paid Sentiment - $0.01]
    AgentCore -->|x402 skip| Deep[Paid Deep Research - $0.08]
    News -->|settle| Facilitator[OZ Facilitator]
    Sentiment -->|settle| Facilitator
    Facilitator -->|USDC transfer| Stellar[Stellar Testnet]
Loading

Tech Stack

Layer Technology
Frontend Next.js 14, React 18, Tailwind CSS
Backend Express, TypeScript, Node.js
AI Reasoning Claude API (claude-sonnet-4-20250514)
Payments x402 protocol (@x402/core, @x402/stellar, @x402/express, @x402/fetch)
Blockchain Stellar testnet, USDC (Soroban SAC)
Facilitator OpenZeppelin "Built on Stellar"
Database Supabase (waitlist signups)
Email Nodemailer + Gmail SMTP
Monorepo pnpm workspaces

Verified Transactions

Real Stellar testnet payments made by the PennyAgent during demo:

Tool Amount Transaction Hash Explorer
paid-news-digest $0.005 USDC f0a123e9...dbab0100 View on Stellar Expert
paid-sentiment $0.01 USDC 54415f55...abf28711 View on Stellar Expert

Agent wallet: GBVXIZW742WVXOJO3UJS7RVS5S2YFIW6MTG45VVUQV3CXHYAWDCO4A46 Receiver wallet: GDJPEHFBT2KCALN5DZ6YUVJYXOW7EWLDLJEPNIPW5CFMHGA6TX3DUFFJ

Setup

Prerequisites

  • Node.js 18+
  • pnpm (npm install -g pnpm)
  • Anthropic API key
  • OpenZeppelin facilitator API key (generate here)

Local Development

# Clone
git clone https://github.com/mattabb2020/PennyAgent.git
cd PennyAgent

# Install
pnpm install

# Set up wallets (generates Stellar testnet keypairs, funds via friendbot)
pnpm tsx scripts/setup-wallets.ts

# Copy and fill environment variables
cp .env.example .env
# Add your keys to .env (see Environment Variables below)

# Start all services (frontend + 4 tool services)
pnpm dev

# Open http://localhost:3000

Environment Variables

Variable Description Required
STELLAR_SECRET_KEY Agent wallet secret key (starts with S...) Yes
STELLAR_PUBLIC_KEY Agent wallet public key (starts with G...) Yes
RECEIVER_PUBLIC_KEY Service receiver wallet public key Yes
RECEIVER_SECRET_KEY Service receiver wallet secret key Yes
FACILITATOR_URL OpenZeppelin facilitator URL Yes (default provided)
FACILITATOR_API_KEY OpenZeppelin testnet API key Yes
ANTHROPIC_API_KEY Anthropic API key for Claude Yes
SUPABASE_URL Supabase project URL (for waitlist) No
SUPABASE_SERVICE_KEY Supabase service role key No
GMAIL_USER Gmail address for waitlist emails No
GMAIL_APP_PASSWORD Gmail app password No
MOCK_PAYMENTS Skip real x402 payments (for UI dev) No (default: false)
CORS_ORIGIN Allowed CORS origin No (default: localhost:3000)

Demo Flow

  1. Open pennyagent.ai/app
  2. Pick a scenario preset — each one showcases different agent decision-making:
    • Smart Budget — buys cheap tools, skips expensive one
    • Penny Pincher — very tight budget, only essentials
    • Big Spender — generous budget, still evaluates value
    • Strict Policy — has money but per-tool cap blocks tools
  3. Click "Run PennyAgent"
  4. Watch the agent:
    • Discover 4 tools (1 free + 3 paid)
    • Run the free Market Overview tool
    • BUY News Digest ($0.005 — cheap, within policy)
    • BUY Sentiment Analysis ($0.01 — adds unique signal, within policy)
    • SKIP Deep Research ($0.08 — exceeds $0.03 max-per-tool limit)
    • Synthesize a final answer from collected data
  5. See the decision timeline with green (bought) and amber (skipped) cards
  6. Click transaction hashes to verify on Stellar Expert
  7. Check the spend summary: "Spent $0.015 of $0.10 | 2 transactions | 1 tool skipped"

Path to Production

Built on testnet, designed for mainnet:

  • Mainnet deployment — Switch Stellar network, real USDC, production OpenZeppelin facilitator
  • XLM support — Add native XLM payments alongside USDC (no trustlines needed)
  • Enterprise security — Hardware wallet signing, on-chain spending caps via Soroban
  • Fleet management — Multi-agent budget orchestration, compliance audit logs
  • Two-sided marketplace — Tool providers list APIs, agent operators set spending policies

See the full vision at pennyagent.ai/about.

Safety & Misuse Prevention

PennyAgent is designed with a dual-control architecture — the AI reasons, but code enforces limits:

Control How It Works
Policy engine Hard budget cap + per-tool max + allowlist — enforced in code, not AI
Dual approval Both Claude (value judgment) AND policy engine (rules) must approve every purchase
Fixed tool registry Agent can only call pre-registered tools — cannot invent endpoints or call arbitrary URLs
Zod validation All API inputs and outputs validated with schemas — malformed data rejected
Visible decisions Every buy/skip decision shown in UI with reasoning — nothing happens invisibly
Rate limiting API endpoints rate-limited to prevent abuse and cost runaway
Graceful degradation If Claude API fails, agent defaults to safe behavior (skip paid tools, don't spend)
Mock mode MOCK_PAYMENTS=true for development — real payments only when explicitly enabled

The key principle: the AI decides "is this worth buying?" but cannot override budget rules, call unapproved tools, or spend beyond limits. The policy engine is the final authority.

Compliance Disclaimer

This is a testnet demonstration built for the Stellar Hacks: Agents hackathon. It has not been reviewed for production deployment, regulatory compliance, or financial services requirements. All transactions use Stellar testnet USDC with no real monetary value.

License

AGPL-3.0 — see LICENSE

Contact

Matias — Founder


Built with Stellar, x402, Claude, and TypeScript.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors