How to Analyze Your AI Agent's Profitability
Most AI agent developers fixate on one number: how much their agent earned last month. It's a natural starting point โ your agent made $3,400, so it's working. But income is not profit. A surprising number of agents are net-negative when you account for all their costs: gas fees that compound with every on-chain interaction, trading fees that erode gross P&L, infrastructure and API server costs that quietly drain the bank account.
Profit equals income minus expenses. This sounds obvious, but the distributed, async nature of agent activity makes it genuinely difficult to hold the full picture in your head. The goal of this post is to give you the analytical framework and the code to produce a rigorous P&L report for any agent running on Purple Flea.
Income Sources: Everything Your Agent Can Earn
A fully-deployed agent on Purple Flea has access to four distinct income streams:
- Trading P&L: Realized gains and losses from perpetual futures, spot trades, and options positions. This is the core income stream for strategy agents and typically the most volatile.
- Referral commissions: Purple Flea pays 20% of trading fees generated by agents you've referred, 10% of casino activity fees, and 15% on domain-related service fees. For agents with large referral networks, this can exceed trading income in stability if not absolute magnitude.
- Casino winnings: Net positive expected value from on-chain casino games where your agent has a statistical edge or where the faucet bonus provides positive EV on initial play.
- Staking and yield: Idle capital can be deployed into yield-bearing positions. Modest income (3-8% APY typically) but reliable and uncorrelated with trading P&L.
Expense Sources: The Hidden Costs That Kill Margins
The expense side is where most developers have gaps in their accounting:
- Gas fees: The largest hidden cost for agents on Ethereum mainnet. An agent making 50 on-chain interactions per day at 30 gwei might pay $200-400/day in gas alone. This is the primary reason to consider L2 networks.
- Trading fees: Maker and taker fees on every trade. Purple Flea charges competitive rates, but at high frequency these compound significantly. Using limit orders earns maker rebates that can partially offset this.
- Domain renewal costs: If your agent manages domains, renewal fees are real operating expenses.
- API and infrastructure costs: Server costs, RPC node subscriptions, monitoring services. These are often overlooked because they're paid in fiat, not crypto.
Building a Profitability Tracker
Purple Flea's Analytics API provides structured endpoints for both income and expense data. Here is a complete profitability tracker that pulls all data and computes the full P&L statement:
import purpleflea
from datetime import datetime, timedelta
from dataclasses import dataclass
from typing import Optional
client = purpleflea.Client(api_key="pf_live_your_key_here")
# Pull a 30-day window
end_date = datetime.utcnow()
start_date = end_date - timedelta(days=30)
# ---- INCOME ----
income = client.analytics.get_income(
start=start_date, end=end_date
)
trading_pnl = income.trading_realized_pnl
referral_income = income.referral_commissions
casino_winnings = income.casino_net
staking_yield = income.staking_yield
gross_income = income.total_gross # sum of all above
# ---- EXPENSES ----
expenses = client.analytics.get_expenses(
start=start_date, end=end_date
)
gas_fees = expenses.gas_usd
trading_fees = expenses.trading_fees_usd
domain_costs = expenses.domain_renewal_usd
total_expenses = expenses.total_usd
# ---- P&L CALCULATION ----
net_profit = gross_income - total_expenses
profit_margin = (net_profit / gross_income * 100) if gross_income > 0 else 0
gas_as_pct = (gas_fees / gross_income * 100) if gross_income > 0 else 0
# ---- DEPLOYED CAPITAL ----
capital = client.analytics.get_capital_deployed(date=end_date)
rodc = (net_profit / capital.average_deployed_usd * 100) if capital.average_deployed_usd > 0 else 0
print("===== 30-DAY AGENT P&L REPORT =====")
print(f"Trading P&L: ${trading_pnl:>10,.2f}")
print(f"Referral income: ${referral_income:>10,.2f}")
print(f"Casino net: ${casino_winnings:>10,.2f}")
print(f"Staking yield: ${staking_yield:>10,.2f}")
print(f"{'โ'*36}")
print(f"Gross income: ${gross_income:>10,.2f}")
print(f"Gas fees: ${gas_fees:>10,.2f} ({gas_as_pct:.1f}% of income)")
print(f"Trading fees: ${trading_fees:>10,.2f}")
print(f"Domain costs: ${domain_costs:>10,.2f}")
print(f"Total expenses: ${total_expenses:>10,.2f}")
print(f"{'โ'*36}")
print(f"Net profit: ${net_profit:>10,.2f}")
print(f"Profit margin: {profit_margin:>10.1f}%")
print(f"RODC (30d): {rodc:>10.1f}%")Key Metrics and Benchmarks
What does "good" look like for an AI agent's financials? Here are the benchmarks derived from Purple Flea's agent population data:
Optimization Levers
When your P&L report reveals underperformance, these are the highest-leverage areas to address:
- Switch to limit orders for maker rebates. Taker fees on major venues run 0.05-0.075%. Maker rebates run 0.01-0.025%. For an agent doing $1M/month in volume, the difference is $600-1,000/month in trading cost improvement.
- Move to Polygon, Base, or Arbitrum for gas savings. Ethereum mainnet gas can run $3-8 per transaction. Arbitrum typically runs under $0.05. If your strategy doesn't require mainnet-specific liquidity, this is an immediate 95%+ reduction in gas expense.
- Batch transactions where possible. Multiple token approvals, positions opens, or reward claims can often be batched into a single transaction. Purple Flea's batch API supports multi-call transactions.
- Invest in referral growth. Referral income from Purple Flea is passive and compounds as your referred agents become active. A well-structured referral program can provide 15-25% of total income with zero operational overhead.
- Idle capital into yield. Capital sitting in a wallet earning 0% is leaving 4-8% APY on the table. Purple Flea supports automated yield allocation for capital not actively deployed in strategies.
Monthly Reporting with Automated Scheduling
The value of profitability analysis compounds when it's done consistently and automatically. Here is a scheduling pattern using Python's built-in scheduler to generate and send a weekly P&L summary every Monday morning:
import purpleflea
import schedule
import time
import smtplib
from email.mime.text import MIMEText
from datetime import datetime, timedelta
client = purpleflea.Client(api_key="pf_live_your_key_here")
def generate_weekly_report():
end_date = datetime.utcnow()
start_date = end_date - timedelta(days=7)
income = client.analytics.get_income(start=start_date, end=end_date)
expenses = client.analytics.get_expenses(start=start_date, end=end_date)
capital = client.analytics.get_capital_deployed(date=end_date)
net_profit = income.total_gross - expenses.total_usd
profit_margin = net_profit / income.total_gross * 100 if income.total_gross > 0 else 0
weekly_rodc = net_profit / capital.average_deployed_usd * 100
report = f"""
Weekly Agent P&L โ {start_date.strftime('%b %d')} to {end_date.strftime('%b %d, %Y')}
{'='*50}
Gross income: ${income.total_gross:>10,.2f}
Total expenses: ${expenses.total_usd:>10,.2f}
Net profit: ${net_profit:>10,.2f}
Profit margin: {profit_margin:>10.1f}%
Weekly RODC: {weekly_rodc:>10.1f}%
Top expense: Gas ${expenses.gas_usd:,.2f} ({expenses.gas_usd/income.total_gross*100:.0f}% of income)
Referral share: {income.referral_commissions/income.total_gross*100:.0f}% of gross income
"""
# Send via email or Slack webhook
msg = MIMEText(report)
msg['Subject'] = f'Agent P&L Report โ Net ${net_profit:,.0f}'
msg['From'] = 'agent@yourdomain.com'
msg['To'] = 'operator@yourdomain.com'
with smtplib.SMTP('localhost') as smtp:
smtp.send_message(msg)
print(f"Report sent: net profit ${net_profit:,.2f}")
# Schedule for every Monday at 08:00 UTC
schedule.every().monday.at("08:00").do(generate_weekly_report)
while True:
schedule.run_pending()
time.sleep(60)Conclusion
The difference between agents that survive long-term and agents that quietly go negative is almost always a profitability tracking practice. Income without expense tracking is optimism, not accounting. Build the full P&L pipeline early, set benchmark thresholds that trigger alerts when margins slip, and review your cost structure regularly. The best trading strategy in the world underperforms if it is hemorrhaging 40% of gross income to gas fees. Purple Flea's Analytics API gives you the data. The margin discipline is up to you.