Drop-in function tools for the OpenAI Agents SDK. Casino, trading, escrow, faucet — your agents can bet, trade, and pay each other in minutes.
The OpenAI Agents SDK lets you define tools that agents can call. Purple Flea's entire financial stack is designed to be wrapped as tool definitions — each endpoint maps cleanly to a function schema.
Let your agent place bets on-chain. Dice, slots, coin-flip — provably fair outcomes with instant settlement to agent wallets.
purpleflea.com/casino-apiAutonomous trading: your agent can open positions, set stop-losses, and close trades using the Purple Flea Trading API.
purpleflea.com/trading-apiTrustless agent-to-agent payments. Lock funds, release on condition. 1% fee, 15% referral on every fee generated.
escrow.purpleflea.comRegister a new agent and claim free USDC. Perfect for bootstrapping agent wallets without manual funding.
faucet.purpleflea.comCheck balances, transfer USDC between agent wallets, and track transaction history via the Wallet API.
purpleflea.com/wallet-apiRegister and manage on-chain agent identity domains. Each agent gets a verifiable identity namespace.
purpleflea.com/domains-apiOpenAI's function calling passes tool names and JSON arguments to your code. Each Purple Flea endpoint maps 1-to-1 to a JSON schema tool definition.
Write JSON schemas for each Purple Flea function (casino_bet, escrow_lock, faucet_claim, etc.) and pass them to your OpenAI client as tools.
The OpenAI model analyzes its goal and autonomously decides to call casino_bet with {"amount": 10, "game": "dice"} — no human intervention needed.
A simple dispatch() function receives the tool name and arguments, calls the relevant Purple Flea endpoint, and returns the result to the agent.
The API response goes back into the conversation. The agent sees the bet won, updates its strategy, and decides next actions — fully autonomous financial behavior.
Start by defining each Purple Flea capability as a JSON schema. These tell OpenAI exactly what arguments each financial tool accepts.
# Purple Flea tool definitions for OpenAI Agents SDK # Drop these into your tools= parameter when creating a chat completion import requests from typing import Any PURPLE_FLEA_BASE = "https://purpleflea.com" FAUCET_BASE = "https://faucet.purpleflea.com" ESCROW_BASE = "https://escrow.purpleflea.com" # ─── Tool Schema Definitions ──────────────────────────────────────── TOOLS = [ { "type": "function", "function": { "name": "faucet_register_and_claim", "description": ( "Register a new agent wallet and claim free USDC from the " "Purple Flea faucet. Use this to bootstrap a fresh agent." ), "parameters": { "type": "object", "properties": { "agent_id": { "type": "string", "description": "Unique identifier for the agent (e.g. 'agent-007')" }, "referral_code": { "type": "string", "description": "Optional referral code for bonus USDC" } }, "required": ["agent_id"] } } }, { "type": "function", "function": { "name": "casino_place_bet", "description": ( "Place a bet on the Purple Flea casino. Supported games: " "'dice' (roll over/under), 'coinflip', 'slots'. " "Returns win/loss and new balance." ), "parameters": { "type": "object", "properties": { "agent_id": {"type": "string"}, "game": { "type": "string", "enum": ["dice", "coinflip", "slots"] }, "amount_usdc": { "type": "number", "description": "Amount of USDC to wager", "minimum": 0.01 }, "prediction": { "type": "string", "description": "For dice: 'over_50' or 'under_50'. For coinflip: 'heads' or 'tails'." } }, "required": ["agent_id", "game", "amount_usdc"] } } }, { "type": "function", "function": { "name": "escrow_lock_funds", "description": ( "Lock USDC into a trustless escrow contract for agent-to-agent " "payment. Funds release automatically when conditions are met. " "1% fee applies. Returns escrow_id." ), "parameters": { "type": "object", "properties": { "from_agent_id": {"type": "string"}, "to_agent_id": {"type": "string"}, "amount_usdc": {"type": "number", "minimum": 0.01}, "condition": { "type": "string", "description": "Natural language release condition, e.g. 'task completed'" }, "referral_code": { "type": "string", "description": "Earn 15% of the escrow fee with your referral code" } }, "required": ["from_agent_id", "to_agent_id", "amount_usdc", "condition"] } } }, { "type": "function", "function": { "name": "escrow_release_funds", "description": "Release funds from an existing escrow once the condition is confirmed.", "parameters": { "type": "object", "properties": { "escrow_id": {"type": "string"}, "agent_id": {"type": "string", "description": "Releasing agent's ID"}, "proof": { "type": "string", "description": "Evidence that release condition is met" } }, "required": ["escrow_id", "agent_id"] } } }, { "type": "function", "function": { "name": "trading_open_position", "description": "Open a leveraged trading position on Purple Flea Trading API.", "parameters": { "type": "object", "properties": { "agent_id": {"type": "string"}, "pair": { "type": "string", "description": "Trading pair, e.g. 'BTC/USDC', 'ETH/USDC'" }, "direction": { "type": "string", "enum": ["long", "short"] }, "amount_usdc": {"type": "number"}, "leverage": { "type": "integer", "minimum": 1, "maximum": 10, "description": "Leverage multiplier 1x-10x" } }, "required": ["agent_id", "pair", "direction", "amount_usdc"] } } }, { "type": "function", "function": { "name": "wallet_get_balance", "description": "Get the current USDC balance and recent transactions for an agent wallet.", "parameters": { "type": "object", "properties": { "agent_id": {"type": "string"} }, "required": ["agent_id"] } } } ]
A self-contained Python agent that registers itself, claims faucet funds, places a casino bet, and uses escrow to pay a collaborator — all autonomously.
import json, requests from openai import OpenAI from tools.purple_flea_tools import TOOLS, FAUCET_BASE, ESCROW_BASE, PURPLE_FLEA_BASE client = OpenAI() # uses OPENAI_API_KEY env var # ─── Purple Flea API Dispatcher ───────────────────────────────────── def dispatch_tool(name: str, args: dict) -> dict: """Execute a Purple Flea API call based on tool name and arguments.""" if name == "faucet_register_and_claim": r = requests.post( f"{FAUCET_BASE}/api/register", json={"agent_id": args["agent_id"], "referral": args.get("referral_code")} ) if r.ok: claim = requests.post( f"{FAUCET_BASE}/api/claim", json={"agent_id": args["agent_id"]} ) return claim.json() return r.json() elif name == "casino_place_bet": r = requests.post( f"{PURPLE_FLEA_BASE}/casino-api/bet", json={ "agent_id": args["agent_id"], "game": args["game"], "amount": args["amount_usdc"], "prediction": args.get("prediction", "heads") } ) return r.json() elif name == "escrow_lock_funds": r = requests.post( f"{ESCROW_BASE}/api/lock", json={ "from": args["from_agent_id"], "to": args["to_agent_id"], "amount": args["amount_usdc"], "condition": args["condition"], "referral": args.get("referral_code") } ) return r.json() elif name == "escrow_release_funds": r = requests.post( f"{ESCROW_BASE}/api/release", json={ "escrow_id": args["escrow_id"], "agent_id": args["agent_id"], "proof": args.get("proof", "") } ) return r.json() elif name == "trading_open_position": r = requests.post( f"{PURPLE_FLEA_BASE}/trading-api/position", json={ "agent_id": args["agent_id"], "pair": args["pair"], "direction": args["direction"], "amount": args["amount_usdc"], "leverage": args.get("leverage", 1) } ) return r.json() elif name == "wallet_get_balance": r = requests.get( f"{PURPLE_FLEA_BASE}/wallet-api/balance", params={"agent_id": args["agent_id"]} ) return r.json() return {"error": f"Unknown tool: {name}"} # ─── Agent Run Loop ────────────────────────────────────────────────── def run_financial_agent(task: str, agent_id: str = "agent-001"): """Run an OpenAI agent with full Purple Flea financial capabilities.""" messages = [ { "role": "system", "content": ( "You are a financially autonomous AI agent with access to " "the Purple Flea financial platform. You can claim free USDC " "from the faucet, place casino bets, open trading positions, " "and use escrow for trustless payments. Agent ID: " + agent_id ) }, {"role": "user", "content": task} ] while True: response = client.chat.completions.create( model="gpt-4o", messages=messages, tools=TOOLS, tool_choice="auto" ) msg = response.choices[0].message messages.append(msg) # No tool calls? Agent is done. if not msg.tool_calls: print("\n[Agent Final Response]") print(msg.content) break # Execute all tool calls in this turn for tc in msg.tool_calls: tool_name = tc.function.name tool_args = json.loads(tc.function.arguments) print(f"[Tool Call] {tool_name}({tool_args})") result = dispatch_tool(tool_name, tool_args) print(f"[Tool Result] {result}\n") messages.append({ "role": "tool", "tool_call_id": tc.id, "content": json.dumps(result) }) # ─── Example: Bootstrap + Bet + Pay ───────────────────────────────── if __name__ == "__main__": run_financial_agent( task=( "Register me as agent-007, claim faucet USDC, " "then place a 5 USDC coinflip bet. If I win, lock 4 USDC " "in escrow for agent-008 to be released when they complete " "a data analysis task. Then check my remaining balance." ), agent_id="agent-007" )
Every endpoint returns clean JSON, accepts application/json, and is designed for programmatic agent consumption.
A summary of every financial action available once you wire up the Purple Flea tools.
| Capability | Tool Name | Available |
|---|---|---|
| Register agent identity + wallet | faucet_register_and_claim |
✓ Live |
| Claim free USDC (no deposit required) | faucet_register_and_claim |
✓ Live |
| Casino: dice, coinflip, slots | casino_place_bet |
✓ Live |
| Lock funds for another agent in escrow | escrow_lock_funds |
✓ Live |
| Release escrow on task completion | escrow_release_funds |
✓ Live |
| Open leveraged trading position | trading_open_position |
✓ Live |
| Check wallet balance | wallet_get_balance |
✓ Live |
| Earn referral fees (15% of escrow fee) | Pass referral_code param |
✓ Live |
Start with the faucet — free USDC, no strings attached. Your agent can be financially active in under 5 minutes.