Agent gastou 500B tokens (seu agente tá desperdiçando?)
Agent: 500B tokens pra decompile game. Seu agente? Token waste = custos ↑. Como otimizar em produção.
Equipe OpenClaw · Time de Engenharia & Produto
A Equipe OpenClaw é formada por engenheiros, designers e especialistas em IA dedicados a construir a melhor plataforma de agentes conversacionais para negócios brasileiros. Combinamos expertise…
Agent gastou 500B tokens (seu agente tá desperdiçando?)
Notícia: Desenvolvedor usou AI agent pra decompile um jogo (reverse engineer código). Resultado: Agent consumiu 500 BILHÕES de tokens. Em dinheiro: ~R$ 150K-300K (dependendo do modelo). Implicação: Se agent gasto MEIO BILHÃO de tokens pra uma task, SEU agente em produção PROVAVELMENTE tá gastando tokens desnecessariamente TODOS OS DIAS. Multiplica por 30 dias = R$ 5M-10M/ano em desperdício.
Problema: Você deployou agente. Ficou rápido, funcionou. Você não olhou pra token usage. Mês 1: R$ 10K. Mês 2: R$ 50K. Mês 6: R$ 500K. "Por quê tá tão caro?" Resposta: Seu agente tá fazendo coisas ineficientes (prompt repetidos, contexto gigante, retries desnecessários). Otimizar = 5-10x economia.
**"Você é CEO de SaaS com agente em WhatsApp.
Cenário: Agente sem otimização ├─ Customer: "Qual foi meu billing em setembro?" ├─ Agente (hoje): │ ├─ System prompt: 2000 tokens (mesmo pra cada request) │ ├─ Conversation history: 5000 tokens (full chat log) │ ├─ Query: 10 tokens (actual question) │ ├─ Response: 500 tokens │ └─ Total: 7510 tokens │ ├─ Cost: 7510 × R$ 0.015/1K tokens = R$ 0.11 per request ├─ Volume: 10K requests/day ├─ Cost/day: R$ 1.1K ├─ Cost/month: R$ 33K ├─ Cost/year: R$ 396K │ └─ Your reaction: "WHAT?! Why so expensive?"
Cenário: Agente otimizado ├─ Customer: "Qual foi meu billing em setembro?" ├─ Agente (otimizado): │ ├─ System prompt: 300 tokens (concise, smart) │ ├─ Context: 500 tokens (only relevant, not full history) │ ├─ Query: 10 tokens │ ├─ Response: 300 tokens (still good) │ └─ Total: 1110 tokens │ ├─ Cost: 1110 × R$ 0.015/1K tokens = R$ 0.017 per request ├─ Volume: 10K requests/day ├─ Cost/day: R$ 170 (87% reduction!) ├─ Cost/month: R$ 5.1K ├─ Cost/year: R$ 61K │ ├─ Your reaction: "Agora faz sentido! 6.5x mais barato." └─ Savings/year: R$ 335K (pode contrat 2 devs!) "**
O caso de 500B tokens: Entender o desperdício
Timeline: Como agent gastou tanto
Task: "Decompile a First-Person Shooter game" (reverse engineer closed-source code)
Approach (naive, wasteful): ├─ Step 1: Agent analyzes game binary │ ├─ Binary size: ~50MB │ ├─ Agent: "Send me the whole file" │ ├─ Tokens to read: ~200B tokens │ ├─ Analysis: Agent reads entire file (inefficient) │ └─ Result: Incomplete understanding (binary is noise) │ ├─ Step 2: Agent tries decompile approach #1 │ ├─ Prompt: "Decompile this game" │ ├─ Agent: Calls Claude API 1000x (retries) │ ├─ Tokens per call: 50K tokens │ ├─ Total: 1000 × 50K = 50B tokens │ ├─ Result: Fails (approach 1 doesn't work) │ └─ Lesson: Try different approach │ ├─ Step 3: Agent tries approach #2 │ ├─ Prompt: "Find strings in binary" │ ├─ Agent: Calls API 500x (retries, exploration) │ ├─ Tokens per call: 100K tokens (more context) │ ├─ Total: 500 × 100K = 50B tokens │ ├─ Result: Partial success (finds some strings) │ └─ Lesson: Combine approaches │ ├─ Step 4: Agent tries approach #3 │ ├─ Prompt: "Cross-reference strings + assembly" │ ├─ Agent: Calls API 500x │ ├─ Tokens per call: 150K tokens (full context) │ ├─ Total: 500 × 150K = 75B tokens │ ├─ Result: Working decompile │ └─ Lesson: Multi-approach needed │ ├─ Step 5: Agent refinement (make code readable) │ ├─ Prompt: "Clean up decompiled code" │ ├─ Agent: Calls API 100x (iterations) │ ├─ Tokens per call: 200K tokens │ ├─ Total: 100 × 200K = 20B tokens │ └─ Result: Readable code │ └─ TOTAL: 200B + 50B + 50B + 75B + 20B = 395B tokens (+ 100B overhead/retries) = 500B tokens
Why so expensive? ├─ Inefficient prompting: Too much context per call ├─ Trial-and-error: Multiple failed approaches ├─ No caching: Same context processed repeatedly ├─ No optimization: Could've used smaller models └─ No planning: Agent didn't plan before executing
How to do it cheaper? ├─ Use smaller model (Haiku instead of Sonnet): 5-10x cheaper ├─ Cache context: Read binary once, reuse tokens ├─ Plan approach: "Here's how we'll do it" (no trial-and-error) ├─ Compress context: 50MB binary → 100KB summary └─ Progressive refinement: Start simple, iterate
Result: 500B tokens → 50B tokens (10x savings) Cost: R$ 300K → R$ 30K
The economics: Why this matters to SaaS
Scenario: SaaS with 10K users, 1 request/day/user per agent
Token efficiency ├─ Wasteful (like game decompile): │ ├─ Tokens per request: 10K tokens │ ├─ Cost per request: R$ 0.15 │ ├─ Daily cost: 10K × R$ 0.15 = R$ 1.5K │ ├─ Monthly cost: R$ 45K │ └─ Yearly cost: R$ 540K │ ├─ Optimized: │ ├─ Tokens per request: 1K tokens (10x smaller prompts) │ ├─ Cost per request: R$ 0.015 │ ├─ Daily cost: 10K × R$ 0.015 = R$ 150 │ ├─ Monthly cost: R$ 4.5K │ └─ Yearly cost: R$ 54K │ └─ Savings: R$ 486K/year (10x cheaper!)
What you can do with R$ 486K: ├─ Hire 2 engineers (R$ 15K/mo = R$ 180K/year) ├─ Hire 2 support staff (R$ 8K/mo = R$ 96K/year) ├─ Invest in marketing (R$ 200K/year) └─ Profit improvement: R$ 10K/year
Bottom line: Token optimization isn't nice-to-have It's CRITICAL for unit economics (diff between profitable and unprofitable)
Como seu agente está desperdiçando tokens
Waste patterns (encontrados em 90% dos agentes)
WASTE 1: System Prompt Duplication Problem: ├─ System prompt: 2000 tokens ├─ Sent with EVERY request ├─ 10K requests/day ├─ Waste: 10K × 2000 = 20M tokens/day └─ Cost: ~R$ 300/dia em desperdício
Solution: Cache system prompt (token caching) ├─ Send once: 2000 tokens (full price) ├─ Cache for 5 minutes: Next calls = 80% discount ├─ 10K requests/day: 500M tokens → 100M tokens ├─ Savings: 400M tokens/day = R$ 6K/day └─ Yearly: R$ 2.1M (if you have this waste)
WASTE 2: Full Conversation History Problem: ├─ User chats for 10 messages ├─ By message 10, context = 5000 tokens ├─ You send FULL history with each request ├─ Request 10: 5000 token overhead └─ Cost: R$ 0.075/request just for history
Solution: Summarize old messages ├─ Keep last 3 messages (active context) ├─ Summarize rest into 200-token summary ├─ Total: 200 + (3 × 500) = 1700 tokens ├─ Savings: 5000 - 1700 = 3300 tokens/request └─ Monthly: 10K requests × 3300 = 33M tokens saved (R$ 495)
WASTE 3: Inefficient Prompts Problem: ├─ Prompt: "You are a helpful assistant...[500 words of instructions]..." ├─ Could be: "Answer billing questions." (10 words) ├─ Waste: 490 words = 490 tokens per request └─ Cost: 10K requests × 490 tokens = 4.9M tokens/day
Solution: Concise, focused prompts ├─ Refactor: Long prompt → Short prompt ├─ Savings: 490 tokens per request ├─ Daily: 10K × 490 = 4.9M tokens └─ Yearly: 4.9M × 365 = 1.78B tokens (R$ 26.7K/year)
WASTE 4: Unnecessary Retries Problem: ├─ Request fails (rate limit, timeout, etc) ├─ Agent: "Retry with full context again" ├─ Failed request: 5000 tokens (wasted) ├─ Retry: Another 5000 tokens ├─ Only 95% success rate: 5% retry = 500 requests/day └─ Cost: 500 × 5000 = 2.5M tokens/day wasted
Solution: Smart retries + backoff ├─ Don't retry full context (use cached version) ├─ Exponential backoff (not immediate retry) ├─ Use cheaper model for retry (Haiku instead of Sonnet) ├─ Savings: 2.5M tokens/day └─ Yearly: 900M tokens (R$ 13.5K/year)
WASTE 5: Processing Irrelevant Data Problem: ├─ Customer asks: "What's my billing?" ├─ You send: Full user profile (1000 tokens) ├─ Agent: Uses only 100 tokens, ignores rest ├─ Waste: 900 tokens per request └─ Cost: 10K requests × 900 = 9M tokens/day
Solution: Extract only relevant data ├─ Customer asks about billing → get billing only ├─ Don't send: Profile, preferences, history, etc ├─ Savings: 900 tokens per request ├─ Daily: 9M tokens saved └─ Yearly: 3.28B tokens (R$ 49.2K/year)
TOTAL WASTE (typical SaaS with 10K users): ├─ Waste 1 (system prompt): R$ 2.1M/year ├─ Waste 2 (full history): R$ 495/year ├─ Waste 3 (inefficient prompts): R$ 26.7K/year ├─ Waste 4 (unnecessary retries): R$ 13.5K/year ├─ Waste 5 (irrelevant data): R$ 49.2K/year └─ TOTAL: R$ 2.2M/year in pure waste
(If your company does R$ 10M revenue, this is 22% of revenue!)
Como otimizar: Checklist prático
Layer 1: Prompt Engineering (easiest, immediate gains)
✅ AUDIT: Measure current token usage ├─ Baseline request: 10K tokens (example) ├─ Log every request: input tokens, output tokens ├─ Calculate: Average tokens per request ├─ Cost: Average cost per request └─ Tool: Use Claude API logs (built-in)
✅ OPTIMIZE SYSTEM PROMPT From: "You are a helpful AI assistant. Your job is to help customers with billing questions. Be friendly, professional, accurate. Always double-check information. Never make up data. If unsure, ask for clarification. Remember to be empathetic..." (300+ words)
To: "Answer billing questions accurately. Ask for clarification if unsure." (15 words)
Impact: 285 words = 285 tokens saved per request Daily: 10K × 285 = 2.85M tokens saved Yearly: R$ 42.75K saved
✅ OPTIMIZE CONTEXT SENDING From: { "user_id": "123", "name": "João Silva", "email": "joao@empresa.com", "phone": "+55 11 98765-4321", "company": "Tech Corp", "plan": "Pro", "signup_date": "2024-01-15", "last_login": "2026-10-10", "preferences": {...}, "billing": {...}, "support_tickets": [...], "usage": {...} } (1000+ tokens if serialized)
To (if customer asks about billing): { "user_id": "123", "plan": "Pro", "billing": {...} (only 200 tokens) }
Impact: 800 tokens saved per request Daily: 10K × 800 = 8M tokens saved Yearly: R$ 120K saved
✅ REDUCE CONVERSATION HISTORY From: [Message 1: 500 tokens] [Message 2: 500 tokens] [Message 3: 500 tokens] ... [Message 10: 500 tokens] = 5000 tokens per request
To: [Summary of messages 1-7: 200 tokens] [Message 8: 500 tokens] [Message 9: 500 tokens] [Message 10: 500 tokens] = 1700 tokens per request
Impact: 3300 tokens saved per request Daily: 10K × 3300 = 33M tokens saved Yearly: R$ 495K saved
Total Layer 1 impact: ├─ System prompt optimization: R$ 42.75K/year ├─ Context optimization: R$ 120K/year ├─ History summarization: R$ 495K/year └─ Total Layer 1: R$ 657.75K/year (easy wins!)
Layer 2: Model Selection (medium effort, big savings)
✅ USE SMALLER MODEL FOR SIMPLE TASKS Current: Claude Sonnet (3.5x more expensive than Haiku) ├─ Cost: R$ 0.003 per 1K input tokens └─ Capability: Overkill for simple billing questions
Optimized: Claude Haiku (for 70% of requests) ├─ Cost: R$ 0.0008 per 1K input tokens ├─ Capability: Enough for FAQs, lookups, simple routing └─ Savings: 3.75x cheaper
Strategy: ├─ Classify request: Simple (40%) vs Complex (60%) ├─ Simple: Use Haiku (R$ 0.0008/1K tokens) ├─ Complex: Use Sonnet (R$ 0.003/1K tokens) ├─ Current cost: 10K requests × 2K tokens × R$ 0.003 = R$ 60/day ├─ Optimized cost: 4K×2K×R$0.0008 + 6K×2K×R$0.003 = R$ 42/day └─ Savings: R$ 18/day = R$ 6.5K/year
✅ BATCH REQUESTS (if applicable) If you have batch processing (not real-time): ├─ API: Claude Batch Processing (50% discount) ├─ Cost: R$ 0.0015 per 1K input tokens (instead of R$ 0.003) ├─ Trade-off: ~1 hour latency (not real-time) ├─ Use case: Email summaries, report generation, etc └─ Savings: 50% on batch requests
Total Layer 2 impact: ├─ Haiku for simple tasks: R$ 6.5K-50K/year (depending on % simple) ├─ Batch processing (if applicable): R$ 100K-500K/year └─ Total Layer 2: R$ 50K-550K/year
Layer 3: Caching & Infrastructure (advanced, continuous savings)
✅ TOKEN CACHING (API-level) Problem: System prompt sent 1M times/day ├─ Cost: 1M × 2000 tokens × R$ 0.003 = R$ 6K/day
Solution: Cache system prompt (5-minute TTL) ├─ First request: 2000 tokens (full price = R$ 0.006) ├─ Next 59 requests (5 min window): 80% discount = R$ 0.0012 each ├─ Average cost per prompt: R$ 0.0015 ├─ New cost: 1M × 2000 × R$ 0.0015 = R$ 3K/day └─ Savings: R$ 3K/day = R$ 1M/year (if you have this scale)
✅ LOCAL CACHING (your infra) ├─ Cache common responses (FAQ answers, templates) ├─ Cache embeddings (for similarity search) ├─ Cache API responses (user data, company data) ├─ Impact: Skip LLM call entirely (zero cost) ├─ Use case: 30% of requests can be answered from cache └─ Savings: 30% of token costs = R$ 162K/year (based on earlier)
✅ COMPRESSION & ABSTRACTION ├─ Compress long user histories into short summaries ├─ Abstract detailed data into key facts ├─ Use embeddings (cheaper than token processing) ├─ Impact: 50% reduction in tokens sent to LLM └─ Savings: R$ 300K/year
Total Layer 3 impact: ├─ Token caching: R$ 1M/year (massive scale) ├─ Local caching: R$ 162K/year ├─ Compression: R$ 300K/year └─ Total Layer 3: R$ 1.46M/year (if you have scale)
Implementation roadmap
WEEK 1: Audit & Quick Wins ├─ Day 1: Measure current token usage (logging) ├─ Day 2: Identify top 3 waste sources ├─ Day 3-4: Optimize system prompt + context ├─ Day 5: Deploy and measure └─ Expected savings: 20-30% (R$ 100K-300K/year)
WEEK 2-3: Model Selection ├─ Classify requests (simple vs complex) ├─ Switch 40% to Haiku for simple tasks ├─ Test quality (no regression) └─ Expected savings: Additional 10-20%
WEEK 4-6: Caching ├─ Implement local cache (responses, data) ├─ Implement token caching (API level) ├─ Monitor hit rates └─ Expected savings: Additional 20-30%
Total: 50-80% reduction in token costs Timeline: 6 weeks One-time cost: 200-300 engineering hours (R$ 50K-100K) ROI: Break-even in 1 month (savings > cost)
Conclusão: Token optimization é não-negotiável
Fatos:
✓ Agent decompile game = 500B tokens = R$ 150K-300K ✓ Your agente: Provavelmente com SIMILARES desperdícios ✓ Desperdício típico: 50-80% dos tokens (R$ 200K-500K/year) ✓ Causa: Inefficient prompts, full context, no caching ✓ Solução: Layer 1 (prompts) + Layer 2 (models) + Layer 3 (caching) ✓ Implementação: 6 weeks, R$ 50K-100K engineering ✓ ROI: Break-even em 1 mês (savings > cost) ✓ Scaling: Mais users = mais savings (economies of scale) ✓ Quality: Otimização preserva/melhora quality (melhor prompts) ✓ Trend: Industry moving to cost-optimized agents (survival)
Proximo passo:
- TODAY: Audit seu agente (quanto tá gastando?)
- WEEK 1: Measure token usage baseline
- WEEK 1-2: Quick wins (prompt optimization, context)
- WEEK 2-3: Model selection (Haiku for simple)
- WEEK 4-6: Caching (local + API level)
- MONTH 2: Monitor + iterate
- RESULT: 50-80% cost reduction, same or better quality
Problema resolvido quando: └─ Token cost per request: 2K → 400 tokens (5x) └─ Monthly bill: R$ 30K → R$ 6K (5x cheaper) └─ Quality: Maintained or improved └─ You're competitive (unit economics matter)
→ OpenClaw: Agentes com Otimização de Token Automática
500B tokens pra decompile game = carissímo. Seu agente? Provavelmente com desperdício similar. AUDITAR AGORA. 50-80% economia possível. 6 semanas implementação. Payback em 1 mês. 💰
Publicado em 11 de outubro de 2026