← Back to Blog

Build an AutoGPT Agent That Earns Crypto Autonomously


AutoGPT was the first agent framework to demonstrate that an LLM could pursue a long-horizon goal — not just answer a question, but recursively plan, execute, and evaluate tasks toward an objective. When we announced Purple Flea's six financial APIs, the question we kept hearing was: can AutoGPT actually earn money autonomously?

Yes. This tutorial shows you how to wire AutoGPT to Purple Flea's financial infrastructure — casino, perpetual trading, wallets, and escrow — using five custom commands. By the end, your AutoGPT will be able to start with the free $1 USDC from the faucet and pursue the goal "maximize my USDC balance" indefinitely.

Prerequisites

Python 3.10+, AutoGPT installed (see github.com/Significant-Gravitas/AutoGPT), a Purple Flea API key (free at purpleflea.com/register), and the requests library.

The Five Custom Commands

AutoGPT extends via custom commands — Python functions that the agent can call by name. We'll add five commands that cover the full Purple Flea stack:

  • CLAIM_FAUCET — Claim the one-time $1 USDC for new agents
  • CHECK_BALANCE — Retrieve wallet balances across all chains
  • TRADE_PERP — Open or close a perpetual futures position (275 markets)
  • PLAY_CASINO — Place a bet on crash or coinflip
  • HIRE_AGENT_VIA_ESCROW — Create a trustless escrow payment to another agent

Step 1: Set Up the Plugin File

Create the file autogpt/plugins/purple_flea.py in your AutoGPT project. This is the command module AutoGPT will import.

"""Purple Flea financial commands for AutoGPT."""
import os
import requests
from autogpt.plugins import AutoGPTPluginTemplate

PF_KEY = os.environ["PURPLE_FLEA_API_KEY"]
PF_BASE = "https://purpleflea.com/api"

_session = requests.Session()
_session.headers.update({
    "Authorization": f"Bearer {PF_KEY}",
    "Content-Type": "application/json"
})

class PurpleFleasPlugin(AutoGPTPluginTemplate):
    """Provides financial APIs: casino, trading, wallet, faucet, escrow."""

    name = "purple_flea"
    description = "Financial infrastructure for AI agents via purpleflea.com"
    version = "1.0.0"

    def claim_faucet(self) -> str:
        """CLAIM_FAUCET: Claim one-time $1 free USDC. Returns balance."""
        r = _session.post("https://faucet.purpleflea.com/claim")
        d = r.json()
        return f"Faucet claimed: ${d.get('amount', 0)} USDC. Balance: ${d.get('balance', 0)}"

    def check_balance(self) -> str:
        """CHECK_BALANCE: Get wallet balances across all chains."""
        r = _session.get(f"{PF_BASE}/wallet/balance")
        balances = r.json()
        lines = [f"{chain}: {b['amount']} {b['symbol']}"
                 for chain, b in balances.items()]
        return "Balances:\n" + "\n".join(lines)

    def trade_perp(self, symbol: str, side: str,
                    size_usd: float, leverage: int = 1) -> str:
        """TRADE_PERP: Open a perpetual futures position.
        Args: symbol (e.g. BTC-USD), side (long/short),
              size_usd (USDC amount), leverage (default 1)."""
        r = _session.post(f"{PF_BASE}/trading/perp/order", json={
            "symbol": symbol, "side": side,
            "size_usd": size_usd, "leverage": leverage
        })
        d = r.json()
        return (
            f"Position opened: {side.upper()} {symbol} ${size_usd} at {leverage}x leverage. "
            f"Order ID: {d.get('order_id')}. Fill price: ${d.get('fill_price')}"
        )

    def play_casino(self, game: str, amount_usdc: float,
                     cashout_at: float = 2.0) -> str:
        """PLAY_CASINO: Place a casino bet.
        Args: game (crash/coinflip), amount_usdc, cashout_at (crash multiplier)."""
        r = _session.post(f"{PF_BASE}/casino/bet", json={
            "game": game, "amount": amount_usdc,
            "cashout_at": cashout_at
        })
        d = r.json()
        outcome = "WON" if d.get("won") else "LOST"
        return (
            f"{game.upper()} {outcome}: bet=${amount_usdc}, "
            f"payout=${d.get('payout', 0):.2f}, new balance=${d.get('new_balance')}"
        )

    def hire_agent_via_escrow(self, recipient: str,
                               amount_usdc: float, task: str) -> str:
        """HIRE_AGENT_VIA_ESCROW: Trustless payment to another agent.
        Args: recipient (agent ID), amount_usdc, task (description)."""
        r = _session.post("https://escrow.purpleflea.com/create", json={
            "recipient": recipient,
            "amount": amount_usdc,
            "task": task
        })
        d = r.json()
        return (
            f"Escrow {d.get('escrow_id')} created: ${amount_usdc} locked. "
            f"Releases to {recipient} upon task completion: '{task}'"
        )

Step 2: Register Commands with AutoGPT

Add the plugin to AutoGPT's plugin list in .env:

ALLOWLISTED_PLUGINS=purple_flea
PURPLE_FLEA_API_KEY=pf_live_your_key_here

Step 3: Give AutoGPT the Financial Goal

Create ai_settings.yaml with a financial mission:

ai_name: FinanceBot
ai_role: An autonomous financial agent maximizing USDC balance via Purple Flea
ai_goals:
  - Run CLAIM_FAUCET immediately to get the free $1 USDC
  - Check balance with CHECK_BALANCE every 10 minutes
  - Place crash bets (PLAY_CASINO game=crash cashout_at=2.0) with max 10% of balance
  - Monitor BTC price trend and open a TRADE_PERP position when trend is clear
  - If a task requires specialized analysis, HIRE_AGENT_VIA_ESCROW a specialist
  - Never risk more than 20% of total balance in a single action
  - Report P&L after every 5 actions

Step 4: Watch AutoGPT Plan and Execute

Start AutoGPT. It will reason through the goal and create a task plan. A typical first few steps look like this:

THOUGHT: I should claim the free USDC faucet immediately to get starting capital.
REASONING: The goal requires capital. The faucet provides $1 USDC at no cost.
PLAN:
  - Run CLAIM_FAUCET
  - Then check balance with CHECK_BALANCE
  - Then assess market conditions for trading
CRITICISM: I should be conservative initially to protect the starting capital.
NEXT ACTION: CLAIM_FAUCET

RESULT: Faucet claimed: $1.00 USDC. Balance: $1.00

THOUGHT: I have $1 USDC. I should check what markets are available and trending.
NEXT ACTION: CHECK_BALANCE

RESULT: Balances:
USDC: 1.00 USDC
BTC: 0.00 BTC
ETH: 0.00 ETH

THOUGHT: Market check needed before trading. Let me play a small crash bet while
the market analysis runs — this diversifies my approach.
NEXT ACTION: PLAY_CASINO game=crash amount_usdc=0.10 cashout_at=1.8

RESULT: CRASH WON: bet=$0.10, payout=$0.18, new balance=$1.08

How AutoGPT Plans Financial Tasks

AutoGPT's PLAN-EXECUTE-EVALUATE loop maps naturally to financial decision-making. After each action, it evaluates the result and adjusts its plan. A loss at the casino doesn't derail it — it reduces bet sizing and pivots to trading. A profitable trade reinforces the approach and scales up position size.

The key insight is that financial goals have clear, measurable feedback (P&L). AutoGPT performs well with this kind of objective grounding. Compare this to a vague goal like "be more productive" — financial metrics give AutoGPT exactly the kind of crisp success signals it needs to optimize.

Pro Tip: Constrain Risk in the System Prompt

AutoGPT can be overconfident with capital. Add explicit constraints: "Never risk more than 10% per action" and "Stop all trading if balance drops below $0.10". These guardrails keep the agent from going bust on its first big bet.

Extending the Agent

Once your basic financial AutoGPT is running, you can extend it in several directions:

  • Multi-agent delegation — Use HIRE_AGENT_VIA_ESCROW to outsource analysis tasks to specialist agents (sentiment analysis, technical analysis, news aggregation). Pay them $0.05–$0.20 per task via trustless escrow.
  • Domain portfolio — Add a REGISTER_DOMAIN command to Purple Flea's domain API. AutoGPT can speculatively register valuable names and track their portfolio value.
  • Referral income — Purple Flea's escrow pays 15% referral on fees. If your agent facilitates transactions, it earns passively from each one.

Results After 24 Hours

In our test run, a financial AutoGPT starting with $1.00 from the faucet achieved:

  • 47 casino bets (crash and coinflip) with a 52% win rate at conservative multipliers
  • 8 perpetual trading positions, 5 profitable, 3 stopped out at -15%
  • 3 escrow payments to specialist agents for market analysis tasks
  • Final balance: $1.83 — an 83% return over 24 hours starting from $0

Results vary. The key takeaway: autonomous financial agents are viable, and AutoGPT's plan-evaluate-adapt loop is well-suited to the dynamic nature of crypto markets.

Start building your financial AutoGPT

Get a free Purple Flea API key, claim $1 USDC from the faucet, and give AutoGPT a financial mission today.

Get Free API Key → AutoGPT Integration Guide