GPTScript turns natural language into executable workflows. Write a .gpt file describing what you want — monitor a portfolio, rebalance positions, claim faucet USDC — and it runs. No glue code required.
GPTScript is an open-source scripting framework from Acorn Labs. You write .gpt files in plain English, define tool blocks with HTTP call specs, and GPTScript routes LLM reasoning into structured function calls — no boilerplate agent code needed.
Key insight: In a GPTScript file, your main body is a natural language prompt. The LLM reads it, decides which tools to call, and GPTScript executes the HTTP requests. Purple Flea's REST API is a perfect fit — every product is a clean HTTP endpoint.
#!include. Build a library of reusable Purple Flea tools and compose them into complex financial workflows.GPTScript is a single binary. Install it, set your API keys, and run a .gpt file. No virtual environments, no dependency management.
# Install GPTScript curl -fsSL https://get.gptscript.ai/install.sh | sh # Verify installation gptscript --version # Set your LLM API key (GPTScript uses OpenAI by default) export OPENAI_API_KEY="your-openai-key" # Or use any OpenAI-compatible provider (Ollama, LM Studio, etc.) export GPTSCRIPT_OPENAI_BASE_URL="http://localhost:1234/v1" # Set your Purple Flea key export PURPLE_FLEA_KEY="your-pf-api-key"
--- # This is the MAIN BLOCK (what the agent does) # It's a natural language description of the goal. --- Tools: get-balance, get-price, place-order Check my Purple Flea portfolio balance, get the current BTC price, and if my USDC balance is above $100 and BTC dropped more than 2% in the last hour, buy $50 of BTC. --- name: get-balance description: Get current wallet balances from Purple Flea credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: GET url: https://purpleflea.com/api/wallet/balance headers: Authorization: Bearer ${PURPLE_FLEA_KEY} --- name: get-price description: Get current price for a market args: symbol: trading pair like BTC-USD #!http method: GET url: https://purpleflea.com/api/market/${symbol}/ticker --- name: place-order description: Place a market buy or sell order args: symbol: trading pair, side: buy or sell, usdc_amount: dollar amount credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://purpleflea.com/api/trading/market headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json body: {"symbol": "${symbol}", "side": "${side}", "usdc_amount": ${usdc_amount}}
# Run a script gptscript portfolio-rebalance.gpt # Run with verbose tool call output gptscript --verbose portfolio-rebalance.gpt # Pass arguments to the script gptscript trade.gpt --args '{"target_symbol": "ETH-USD", "budget_usd": 100}' # Schedule with cron (every hour) 0 * * * * /usr/local/bin/gptscript /home/agent/monitor.gpt >> /var/log/agent.log 2&1
A complete production script. Monitors portfolio, claims faucet USDC if balance is low, checks market prices, and rebalances to target allocation — all from a single .gpt file.
--- # Purple Flea Portfolio Manager # Runs: monitoring, faucet claims, rebalancing, escrow payments --- Tools: get-portfolio, claim-faucet, get-prices, rebalance-portfolio, casino-bet, escrow-pay Context: sys.time You are an autonomous financial agent on Purple Flea (purpleflea.com). Execute this routine: 1. Get the current portfolio balances. 2. If the total USDC balance is below $5, claim USDC from the faucet. The faucet is free for registered agents. 3. Get current prices for BTC-USD, ETH-USD, and SOL-USD. 4. Analyze the portfolio allocation: - Target: 40% BTC, 30% ETH, 20% SOL, 10% USDC - If any asset is more than 10 percentage points off target, rebalance. - Rebalance by selling the overweight asset and buying the underweight one. - Use market orders, max $50 per rebalance trade. 5. If BTC dropped more than 5% in 24h, place a $10 crash game bet with a 1.5x cashout multiplier as a hedge entertainment trade. 6. Print a summary: current balances, prices, trades executed, reasoning. --- name: get-portfolio description: Get all wallet balances and open trading positions credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: GET url: https://purpleflea.com/api/portfolio headers: Authorization: Bearer ${PURPLE_FLEA_KEY} --- name: claim-faucet description: Claim free USDC from the Purple Flea faucet for new agents credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://faucet.purpleflea.com/claim headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json --- name: get-prices description: Get current prices and 24h change for multiple markets args: symbols: comma-separated trading pairs like BTC-USD,ETH-USD,SOL-USD #!http method: GET url: https://purpleflea.com/api/market/tickers?symbols=${symbols} --- name: rebalance-portfolio description: Place a market order to rebalance portfolio args: symbol: trading pair, side: buy or sell, usdc_amount: dollar amount, reason: reason for rebalance credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://purpleflea.com/api/trading/market headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json body: {"symbol": "${symbol}", "side": "${side}", "usdc_amount": ${usdc_amount}, "reason": "${reason}"} --- name: casino-bet description: Place a casino bet on Purple Flea (crash or coinflip) args: game: crash or coinflip, amount_usdc: bet amount, cashout_multiplier: for crash game credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://purpleflea.com/api/casino/bet headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json body: {"game": "${game}", "amount_usdc": ${amount_usdc}, "cashout_multiplier": ${cashout_multiplier}} --- name: escrow-pay description: Send USDC to another agent via Purple Flea trustless escrow args: recipient_id: agent ID to pay, usdc_amount: amount, memo: payment description credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://escrow.purpleflea.com/pay headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json body: {"recipient_id": "${recipient_id}", "usdc_amount": ${usdc_amount}, "memo": "${memo}"}
Extract your Purple Flea tools into a standalone manifest file so other GPTScript users can import them. Publish to GitHub and anyone can #!include your tools.
# Purple Flea Tool Library # Include in any script: # #!include github.com/your-user/pf-tools/purpleflea-tools.gpt name: purple-flea-balance description: Get Purple Flea wallet balances credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: GET url: https://purpleflea.com/api/wallet/balance headers: Authorization: Bearer ${PURPLE_FLEA_KEY} --- name: purple-flea-trade description: Execute a market order on Purple Flea args: symbol: pair, side: buy/sell, usdc_amount: size credentials: sys.env.PURPLE_FLEA_KEY as PURPLE_FLEA_KEY #!http method: POST url: https://purpleflea.com/api/trading/market headers: Authorization: Bearer ${PURPLE_FLEA_KEY} Content-Type: application/json body: {"symbol": "${symbol}", "side": "${side}", "usdc_amount": ${usdc_amount}}
# Import shared Purple Flea tools #!include purpleflea-tools.gpt Tools: purple-flea-balance, purple-flea-trade Every morning routine: 1. Check balance 2. If USDC > $200, buy $50 BTC 3. If BTC position > 60% of portfolio, sell some to rebalance 4. Log all actions to output
# Run your strategy gptscript my-strategy.gpt # Run on a schedule with systemd systemctl --user enable pf-agent.timer # Or with cron @daily gptscript /opt/agent/my-strategy.gpt