agentleFS
salmandevsalmandev/everything-gemini/skills/cost-oracle-finops/SKILL.md

cost-oracle-finops

Skill2 starsChanged 29 days agoApache-2.0View on GitHub

Pre-flight predictive token cost modeling, spend budgeting, and pricing tier optimization for Gemini 2.0 Flash, Pro, and Gemini 3.8 extended reasoning agents.

The file

Files
SKILL.md

Cost Oracle & FinOps Agent Modeling

Implements pre-flight predictive token cost estimation, model pricing tier arbitrage, and autonomous budget forecasting for multi-agent workflows across Google Gemini 2.0 Flash, Gemini 2.0 Pro, and Gemini 3.8 models.


1. Architecture: Pre-Flight Financial Oracle

┌─────────────────────────────────────────────────────────────────────────────┐
│                        PRE-FLIGHT COST ORACLE ENGINE                        │
│                                                                             │
│   ┌─────────────────────┐                                                   │
│   │ Proposed Task &     │                                                   │
│   │ Subagent Trajectory │                                                   │
│   └──────────┬──────────┘                                                   │
│              │                                                              │
│              ▼                                                              │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │ 1. Token Predictor (Context Caching vs. Dynamic Suffix Heuristics)  │   │
│   │    • System & Skill Frontmatter Tokens                              │   │
│   │    • Expected Reasoning Depth (Extended Thinking Tokens)            │   │
│   │    • Tool Call Frequency & Speculative Probing Branches             │   │
│   └──────────────────────────────────┬──────────────────────────────────┘   │
│                                      │                                      │
│                                      ▼                                      │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │ 2. FinOps Pricing Engine (Per Model Rates & Discount Tiers)        │   │
│   │    • Gemini 2.0 Flash: $0.075 / 1M input, $0.30 / 1M output         │   │
│   │    • Context Caching: 75% input discount ($0.01875 / 1M input)      │   │
│   │    • Gemini 2.0 Pro: $1.25 / 1M input, $5.00 / 1M output            │   │
│   └──────────────────────────────────┬──────────────────────────────────┘   │
│                                      │                                      │
│                                      ▼                                      │
│   ┌─────────────────────────────────────────────────────────────────────┐   │
│   │ 3. Pre-Flight Financial Gating (Pass / Downgrade / Deny)            │   │
│   │    • If Expected Cost > MAX_USD_BUDGET -> Abort or switch to Flash  │   │
│   │    • If Expected Cost <= Budget Ceiling -> Issue Financial Clearance │ │
│   └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

2. Mathematical Cost Modeling Formula

Let $T_{in}$ be input tokens, $T_{cache}$ be context-cached prefix tokens, $T_{out}$ be output generation tokens, and $T_{think}$ be internal reasoning tokens:

$$\text{Cost} = (T_{cache} \times P_{cache}) + ((T_{in} - T_{cache}) \times P_{in}) + ((T_{out} + T_{think}) \times P_{out})$$

Where for Gemini 2.0 Flash:

  • $P_{in} = $0.075 / 10^6$
  • $P_{cache} = $0.01875 / 10^6$
  • $P_{out} = $0.30 / 10^6$

3. Python Pre-Flight Cost Estimator

from dataclasses import dataclass
from typing import Dict, Any

@dataclass
class CostEstimate:
    model: str
    expected_input_tokens: int
    cached_prefix_tokens: int
    expected_output_tokens: int
    expected_thinking_tokens: int
    estimated_usd: float
    confidence_interval: tuple[float, float]

class FinOpsCostOracle:
    RATES = {
        "gemini-2.0-flash": {
            "input": 0.075 / 1_000_000,
            "cache": 0.01875 / 1_000_000,
            "output": 0.30 / 1_000_000
        },
        "gemini-2.0-pro": {
            "input": 1.25 / 1_000_000,
            "cache": 0.3125 / 1_000_000,
            "output": 5.00 / 1_000_000
        }
    }

    def estimate_task_cost(
        self,
        model: str,
        prompt_length: int,
        active_skills_count: int,
        estimated_turns: int = 5,
        uses_extended_thinking: bool = False
    ) -> CostEstimate:
        rates = self.RATES.get(model, self.RATES["gemini-2.0-flash"])
        
        # Heuristics based on empirical benchmarks
        cached_prefix = 32_768 if active_skills_count > 10 else 0
        input_per_turn = prompt_length + (active_skills_count * 250)
        output_per_turn = 800
        thinking_per_turn = 2048 if uses_extended_thinking else 0
        
        total_input = input_per_turn * estimated_turns
        total_output = output_per_turn * estimated_turns
        total_thinking = thinking_per_turn * estimated_turns
        
        cost = (
            (cached_prefix * rates["cache"]) +
            (max(0, total_input - cached_prefix) * rates["input"]) +
            ((total_output + total_thinking) * rates["output"])
        )
        
        # 95% Confidence Interval (+/- 25% due to variable branching)
        ci = (round(cost * 0.75, 4), round(cost * 1.35, 4))
        
        return CostEstimate(
            model=model,
            expected_input_tokens=total_input,
            cached_prefix_tokens=cached_prefix,
            expected_output_tokens=total_output,
            expected_thinking_tokens=total_thinking,
            estimated_usd=round(cost, 4),
            confidence_interval=ci
        )

4. Enterprise FinOps Best Practices

StrategyActionBenefit
Model CascadingUse Gemini 2.0 Flash for verification; reserve Pro for system designUp to 80% cost reduction
Prefix FreezingMaintain minimum 32,768 tokens in static prefix to qualify for context caching75% discount on repeated turns
Budget CeilingEnforce --max-usd via hooks/budget-guardGuarantees zero surprise runaway charges
Thinking CapsConstrain max_thinking_tokens on speculative probesPrevents unbounded internal reasoning loops

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.