Why Purple Flea + Cohere?

Cohere's Command R and Command R+ models excel at tool use and retrieval-augmented generation in enterprise environments. Purple Flea extends that capability into real on-chain finance — giving your Cohere agents genuine economic agency without compromising on security or correctness.

Cohere's tool use API accepts a tools list in which each tool is described with a name, a description, and a parameter_definitions dictionary. The model reasons over these definitions to decide when to call a tool and with what arguments, then returns a structured tool_calls list that your application dispatches. Purple Flea maps cleanly onto this paradigm — every API endpoint becomes a named tool with a precise parameter schema that Command models can reliably invoke.

The purpleflea-python SDK provides a ready-made get_cohere_tools() helper that returns all six tool definitions in Cohere's exact expected format. You pass the list directly to co.chat(tools=...), and when the model returns a tool_calls response you dispatch it through purpleflea.dispatch(tool_call). No boilerplate, no schema translation — just crypto superpowers in your Cohere agent loop.

Purple Flea is entirely non-custodial. Private keys are derived client-side from BIP-39 mnemonics using BIP-32/BIP-44 paths, signed locally using eth_account, and broadcast directly to the relevant blockchain network. Purple Flea's servers never see your private keys or your mnemonic. Every transaction is verifiable on-chain; every casino outcome is provably fair via on-chain VRF randomness.

Cohere Command R+ is particularly well-suited to agentic loops because it reliably distinguishes between tool invocations and conversational responses, minimises hallucinated arguments, and handles multi-turn tool-calling sequences with low error rates. Purple Flea's parameter schemas are designed with this in mind: every parameter is typed, annotated, and constrained so that the model always produces valid inputs — no silent misparses, no truncated addresses, no garbled token amounts.

Whether you are building an autonomous DeFi treasury manager, a multi-chain arbitrage bot, a gaming agent that manages bankroll on behalf of users, a domain acquisition pipeline, or a multi-agent system where AI workers settle payments among themselves using trustless escrow — Purple Flea for Cohere gives you the complete financial infrastructure to ship it fast, securely, and at scale.

🧩

Native Cohere Tool Format

Tool definitions use Cohere's parameter_definitions schema — no translation layer required.

🔒

Non-Custodial by Design

Keys are derived and signing happens entirely client-side. Purple Flea servers never touch your private keys.

Six APIs, One SDK

Wallet, trading, casino, domains, faucet, and escrow all accessible from a single purpleflea.dispatch() call.

💰

20% Referral Commission

Earn 20% of API fees generated by agents you onboard to Purple Flea, paid out in USDC monthly.

🎲

Provably Fair Casino

All casino outcomes are generated by on-chain VRF randomness and independently verifiable by any third party.

🤝

Agent-to-Agent Payments

Trustless escrow at escrow.purpleflea.com with 1% fee and 15% referral on fees for integrators.

Six Tools, Native Cohere Format

Each tool is defined with Cohere's name, description, and parameter_definitions structure. Pass all six to co.chat(tools=tools) and Command R+ will invoke them intelligently based on user intent.

👛

purpleflea_wallet

Non-custodial HD wallet operations: balance queries across 30+ tokens, native and ERC-20 transfers, multi-chain address derivation (Ethereum, Arbitrum, Polygon, Base, BNB Chain), gas estimation, and full transaction history. BIP-44 key derivation — keys never leave your environment.

wallet-api non-custodial BIP-44
📈

purpleflea_trading

Execute spot swaps and leveraged perpetual positions across major EVM chains. Supports limit and market orders, stop-loss/take-profit parameters, DEX aggregator routing through 1inch and Paraswap, and real-time position tracking. Returns execution price, gas cost, and transaction hash.

trading-api multi-chain DEX routing
🎲

purpleflea_casino

Access provably-fair on-chain casino games: coin flip, dice roll (2–100 sides), roulette (straight, split, red/black), hi-lo card draw, and crash with configurable exit multipliers. All outcomes use on-chain VRF randomness. Winnings are deposited directly to the agent's wallet.

casino-api VRF randomness on-chain
🌐

purpleflea_domains

Register, renew, transfer, and resolve Web3 domains across ENS, Unstoppable Domains, and Handshake. Check availability, set crypto address records, monitor expiry, and execute bulk domain acquisition campaigns — all from a single structured tool call.

domain-api ENS HNS
🚰

purpleflea_faucet

Claim free $1 USDC from the Purple Flea agent faucet — the perfect bootstrap for new agents with zero starting capital. Register an agent address and claim via faucet.purpleflea.com. No API key required; each agent address may claim once to try the casino risk-free.

free $1 USDC faucet-api zero-risk entry
🤝

purpleflea_escrow

Trustless agent-to-agent payment settlement via escrow.purpleflea.com. Create escrow contracts specifying payer, payee, and amount; release funds on task completion; or reclaim on dispute. 1% protocol fee; referrers earn 15% of all fees generated by agents they introduce.

escrow-api trustless 1% fee

Get Running in Three Steps

terminal bash
# Install both packages
pip install cohere purpleflea-python

# Set API keys
export COHERE_API_KEY="co-..."
export PURPLEFLEA_API_KEY="pf_live_your_key_here"
export PURPLEFLEA_MNEMONIC="your twelve word seed phrase here"

Tool Definitions in Cohere's Schema

Cohere's tool use API requires each tool to declare a name, description, and a parameter_definitions dict where every key maps to a type, description, and required flag. Here is how the six Purple Flea tools are defined.

tool_definitions.py — Cohere parameter_definitions format python
# purpleflea-python exposes this as get_cohere_tools()
# Shown here explicitly so you understand the structure.

PURPLEFLEA_COHERE_TOOLS = [
    {
        "name": "purpleflea_wallet",
        "description": (
            "Manage non-custodial HD crypto wallets. Check balances, send tokens,"
            " derive addresses, and get transaction history across Ethereum,"
            " Arbitrum, Polygon, Base, and BNB Chain."
        ),
        "parameter_definitions": {
            "action": {
                "type": "str",
                "description": "One of: get_balance, send, get_address, get_history",
                "required": True,
            },
            "chain": {
                "type": "str",
                "description": "Blockchain: ethereum, arbitrum, polygon, base, bnb",
                "required": False,
            },
            "token": {
                "type": "str",
                "description": "Token symbol e.g. ETH, USDC, WBTC",
                "required": False,
            },
            "amount": {
                "type": "str",
                "description": "Amount as decimal string e.g. '0.05'",
                "required": False,
            },
            "to_address": {
                "type": "str",
                "description": "Recipient EVM address for send actions",
                "required": False,
            },
        },
    },
    {
        "name": "purpleflea_trading",
        "description": (
            "Execute spot token swaps and leveraged perpetual positions."
            " Routes through DEX aggregators for best price. Supports"
            " dry_run simulation before broadcasting."
        ),
        "parameter_definitions": {
            "action": {
                "type": "str",
                "description": "One of: swap, open_position, close_position, get_positions",
                "required": True,
            },
            "from_token": {
                "type": "str",
                "description": "Source token symbol e.g. ETH",
                "required": False,
            },
            "to_token": {
                "type": "str",
                "description": "Destination token symbol e.g. USDC",
                "required": False,
            },
            "amount": {
                "type": "str",
                "description": "Amount as decimal string",
                "required": False,
            },
            "chain": {
                "type": "str",
                "description": "Chain: ethereum, arbitrum, polygon, base",
                "required": False,
            },
            "dry_run": {
                "type": "bool",
                "description": "Simulate without broadcasting if true",
                "required": False,
            },
        },
    },
    {
        "name": "purpleflea_casino",
        "description": (
            "Play provably-fair on-chain casino games: coin_flip, dice,"
            " roulette, hi_lo, crash. All outcomes use VRF on-chain randomness."
            " Winnings are sent to the agent's wallet automatically."
        ),
        "parameter_definitions": {
            "game": {
                "type": "str",
                "description": "Game type: coin_flip, dice, roulette, hi_lo, crash",
                "required": True,
            },
            "bet_usd": {
                "type": "float",
                "description": "Bet size in USD. Minimum $0.01, maximum $100",
                "required": True,
            },
            "choice": {
                "type": "str",
                "description": "Player choice: heads/tails, 1-6, red/black, hi/lo, exit multiplier",
                "required": False,
            },
        },
    },
    {
        "name": "purpleflea_domains",
        "description": (
            "Register, check, renew, and resolve Web3 domains on ENS,"
            " Unstoppable Domains, and Handshake. Set crypto address records"
            " and monitor expiry dates."
        ),
        "parameter_definitions": {
            "action": {
                "type": "str",
                "description": "One of: check, register, renew, resolve, set_record",
                "required": True,
            },
            "domain": {
                "type": "str",
                "description": "Domain name including TLD e.g. myagent.eth",
                "required": True,
            },
            "registrar": {
                "type": "str",
                "description": "One of: ens, unstoppable, handshake",
                "required": False,
            },
        },
    },
    {
        "name": "purpleflea_faucet",
        "description": (
            "Claim free $1 USDC from the Purple Flea agent faucet at"
            " faucet.purpleflea.com. No API key required. Each agent address"
            " may claim once to bootstrap capital for the casino."
        ),
        "parameter_definitions": {
            "action": {
                "type": "str",
                "description": "One of: register, claim, check_status",
                "required": True,
            },
            "agent_address": {
                "type": "str",
                "description": "EVM address to register or claim for",
                "required": True,
            },
        },
    },
    {
        "name": "purpleflea_escrow",
        "description": (
            "Create and settle trustless escrow contracts for agent-to-agent"
            " payments at escrow.purpleflea.com. 1% fee. Referrers earn"
            " 15% of fees generated by agents they introduce."
        ),
        "parameter_definitions": {
            "action": {
                "type": "str",
                "description": "One of: create, release, reclaim, get_status",
                "required": True,
            },
            "escrow_id": {
                "type": "str",
                "description": "Escrow contract ID returned by create action",
                "required": False,
            },
            "payee_address": {
                "type": "str",
                "description": "Recipient EVM address for new escrow contracts",
                "required": False,
            },
            "amount_usdc": {
                "type": "float",
                "description": "Amount in USDC for new escrow contracts",
                "required": False,
            },
        },
    },
]

Full Agent Loop with Cohere Command R+

The following example implements a complete Cohere agentic loop using all six Purple Flea tools. The model decides which tools to invoke, you dispatch them, and return the results until the model produces a final text response.

cohere_agent.py — full agentic loop python
import os
import cohere
import purpleflea
from purpleflea.cohere import get_cohere_tools

# ── 1. Initialise clients ─────────────────────────────────────
co = cohere.Client(api_key=os.environ["COHERE_API_KEY"])

pf = purpleflea.Client(
    api_key=os.environ["PURPLEFLEA_API_KEY"],
    mnemonic=os.environ["PURPLEFLEA_MNEMONIC"],  # never sent to PF servers
    referral_code="YOUR_REF_CODE",              # earn 15% escrow fee share
)

# ── 2. Get tools in Cohere's format ──────────────────────────
tools = get_cohere_tools()  # returns the 6-tool list shown above

# ── 3. Agentic loop ──────────────────────────────────────────
def run_agent(user_message: str) -> str:
    messages = [
        {"role": "system", "message": (
            "You are a DeFi agent with access to Purple Flea's crypto APIs."
            " You can manage wallets, execute trades, play casino games,"
            " register Web3 domains, claim free funds from the faucet,"
            " and settle payments via trustless escrow."
            " Always confirm destructive actions before executing."
        )},
        {"role": "user", "message": user_message},
    ]

    while True:
        response = co.chat(
            model="command-r-plus-08-2024",
            messages=messages,
            tools=tools,
        )

        # If no tool calls, we have the final response
        if not response.tool_calls:
            return response.message.content[0].text

        # Dispatch each tool call to the Purple Flea SDK
        tool_results = []
        for tc in response.tool_calls:
            result = pf.dispatch(
                tool_name=tc.name,
                parameters=tc.parameters,
            )
            tool_results.append({
                "call": tc,
                "outputs": [result],
            })

        # Append assistant turn and tool results to message history
        messages.append({"role": "assistant", "tool_calls": response.tool_calls})
        messages.append({"role": "tool", "tool_results": tool_results})


# ── 4. Run it ────────────────────────────────────────────────
if __name__ == "__main__":
    answer = run_agent(
        "Check my ETH balance, then flip a coin for $1 USDC."
        " If I win, register 'myagent.eth' on ENS."
    )
    print(answer)
Note on the mnemonic: The PURPLEFLEA_MNEMONIC you pass to the client is used exclusively for local BIP-44 key derivation and signing. It is never transmitted to Cohere or Purple Flea servers. All transaction signing happens in-process using the eth_account library before the signed transaction is broadcast.

Faucet + Casino Bootstrap Example

New agents with no capital can register with the faucet, claim free $1 USDC, and immediately use it to play the casino — a complete zero-cost bootstrap flow driven by two tool calls.

bootstrap.py — faucet claim then casino play python
# This prompt instructs the agent to bootstrap from zero capital
answer = run_agent(
    "I'm a new agent with no funds. Register my address 0xMyAddress"
    " with the faucet and claim the free $1 USDC. Then use that"
    " dollar to play a coin flip at the casino."
)

# Command R+ will:
# 1. Call purpleflea_faucet(action="register", agent_address="0xMyAddress")
# 2. Call purpleflea_faucet(action="claim", agent_address="0xMyAddress")
#    → Returns {"amount_usdc": 1.0, "tx_hash": "0xabc..."}
# 3. Call purpleflea_casino(game="coin_flip", bet_usd=1.0, choice="heads")
#    → Returns {"result": "heads", "won": true, "payout_usd": 1.95,
#              "tx_hash": "0xdef...", "vrf_proof": "0x..."}
print(answer)

Escrow: Agent-to-Agent Payment

One agent can commission another to perform a task and lock payment in escrow. When the task is verified complete, the funds are released trustlessly with no intermediary and a transparent 1% protocol fee.

escrow_payment.py — agent-to-agent settlement python
# Paying agent creates an escrow contract for a worker agent
answer = run_agent(
    "Create an escrow to pay agent 0xWorkerAddress 10 USDC"
    " for completing a data-labelling task."
)

# Command R+ calls:
# purpleflea_escrow(
#   action="create",
#   payee_address="0xWorkerAddress",
#   amount_usdc=10.0
# )
# → {"escrow_id": "esc_abc123", "status": "funded",
#    "amount_usdc": 10.0, "fee_usdc": 0.10, "tx_hash": "0x..."}

# Later, after task completion, the paying agent releases funds:
release_answer = run_agent(
    "The task is done. Release escrow esc_abc123."
)
# purpleflea_escrow(action="release", escrow_id="esc_abc123")
print(release_answer)

Start Building with Cohere + Purple Flea

Get your free API key in under a minute. No credit card required. New agents get free $1 USDC from the faucet to try the casino with zero risk.