agentleFS
XORwellXORwell/archeflow/skills/cost-tracking/SKILL.md

cost-tracking

Skill0 starsChanged 52 days agoMITView on GitHub

ArcheFlow cost tracking: per-agent and per-run token cost, budget enforcement, cheapest adequate model per role and domain.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When models.provider: ollama in .archeflow/config.yaml or ARCHEFLOW_MODEL_PROVIDER=ollama (legacy ARCHFLOW_MODEL_PROVIDER also accepted):

    line 22
  2. Very specific:

    If only some steps use <archeflow-root>/lib/archeflow-ollama.sh and the rest use Claude, split ledger entries by provider per agent.

    line 26
  3. Very specific:

    If exact tokens unavailable, estimate: tokens ~= chars / 4.

    line 39
  4. Very specific:

    After 10+ runs, use actual averages from metrics.jsonl instead.

    line 69
  5. Distinctive:

    Post-agent: Update total. Warn at threshold.

    line 87

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cost Tracking -- Budget-Aware Orchestration

Tracks costs per agent and per run, enforces budgets, and selects cost-optimal models.

Model Pricing

ModelInput ($/M tok)Output ($/M tok)
claude-opus-4-615.0075.00
claude-sonnet-4-63.0015.00
claude-haiku-4-50.804.00

Local provider (Ollama)

When models.provider: ollama in .archeflow/config.yaml or ARCHEFLOW_MODEL_PROVIDER=ollama (legacy ARCHFLOW_MODEL_PROVIDER also accepted):

  • Record USD 0 for API spend on those runs. Optionally log compute: local in the daily ledger line for transparency.
  • Skip cloud budget enforcement for Ollama-backed steps (still respect wall-clock and disk if logging huge artifacts).
  • If only some steps use <archeflow-root>/lib/archeflow-ollama.sh and the rest use Claude, split ledger entries by provider per agent.

Prompt caching: 90% discount on cached input tokens. Structure system prompts for cache hits. Batches API: 50% discount. Use for non-time-sensitive bulk ops.

Cost Calculation

cost = (input - cache_read) * input_price/1M
     + cache_read * input_price * 0.10/1M
     + output * output_price/1M

If exact tokens unavailable, estimate: tokens ~= chars / 4. Mark with cost_estimated: true.

Default Model Assignments

ArchetypeCodeWriting
Explorerhaikuhaiku
Creatorsonnetsonnet
Makersonnetsonnet
Guardianhaikuhaiku
Skeptichaikuhaiku
Sagesonnetsonnet
Tricksterhaikuhaiku

Opus is user-opt-in only (team preset model_overrides).

Resolution order: team preset override > domain override > archetype default.

Pre-Agent Cost Estimates

ArchetypeTypical InputTypical Output
Explorer8k4k
Creator12k6k
Maker15k12k
Guardian10k3k
Skeptic8k3k
Sage12k4k
Trickster8k4k

After 10+ runs, use actual averages from metrics.jsonl instead.

Budget Configuration

costs:
  budget_usd: 10.00        # per run; wiggum-check soft-breaks above 95%
  per_agent_usd: 3.00
  daily_usd: 50.00
  warn_at_percent: 75

Team preset budget overrides global config. No budget = unlimited (costs still tracked).

Budget Enforcement

Pre-agent: Estimate cost. If > remaining budget: stop (autonomous) or warn (attended).

Post-agent: Update total. Warn at threshold. Stop if budget exceeded.

Cost Optimization

  1. Prompt caching: Stable content first (archetype instructions, voice profiles). Saves 30-50% on input.
  2. Guardian fast-path (A2): 0 issues = skip remaining reviewers. Saves $0.30-0.80/cycle.
  3. Explorer cache: Reuse recent research. Saves $0.02-0.05/hit.
  4. Batches API: For autonomous/overnight review passes (50% discount).
  5. Early termination: Clean Guardian + clean Maker self-review = skip remaining cycles.

Daily Cost Tracking

Ledger at .archeflow/costs/<YYYY-MM-DD>.jsonl. One line per run with cost, tokens, models, domain. Daily budget enforcement reads this before starting new runs.

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.