March 4, 2026 ยท 6 min read

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:

Expense Sources: The Hidden Costs That Kill Margins

The expense side is where most developers have gaps in their accounting:

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:

Target profit margin
>40%
Well-optimized agents. Below 20% = urgent review needed.
Gas as % of income
<10%
Above 30% = move to L2 immediately.
Trading fees as % of income
10โ€“15%
Use limit orders to earn maker rebates and push below 8%.
Referral as % of gross
>15%
High referral share = low-risk, uncorrelated income.

Optimization Levers

When your P&L report reveals underperformance, these are the highest-leverage areas to address:

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.