agentleFS
kuker24kuker24/OpenCodeBestFriend/skills/cost-aware-llm-pipeline/SKILL.md

cost-aware-llm-pipeline

Skill0 starsChanged 2 months agoMITView on GitHub

Design and optimize cost-efficient LLM application architectures. Covers model tiering, task complexity routing, prompt caching strategies, token budget fences, and retry backoff. Use when reducing API spend, establishing token budgets, or architecting multi-model fallback cascades. Not for client runtime latency/bundle audits (full-performance-audit) or prompt phrasing refinement (prompt-optimizer).

21 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

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 18 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Place volatile per-request dynamic data, user queries, and timestamps strictly at the end of the prompt buffer.

    line 36

“Common” is measured: kept by at least 6 in 10 of the 18 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-Aware LLM Pipeline

Specialist for architecting cost-disciplined LLM applications and API integrations.

This skill balances output quality against token expenditure using complexity-based model routing, aggressive prompt caching, token budget ceilings, and graceful degradation cascades.

Boundaries & Handoffs

NeedRoute
Application bundle size, page latency, web vitals, database query profilingfull-performance-audit
Refining individual prompt wording, instructions, or negative constraintsprompt-optimizer
Benchmarking accuracy tradeoffs across cheaper models or prompt versionseval-harness
Investigating failure loops or context pollution in an agent loopagent-architecture-audit
Engineering cost-optimized LLM architectures, routing, and token budgetscost-aware-llm-pipeline

Core Patterns

Consult references/patterns.md for concrete implementation patterns:

  1. Complexity-Based Model Tiering:
    • Tier 1 (Fast/Cheap): Simple classification, routing, entity extraction, straightforward summarization, unit-test parsing.
    • Tier 2 (Balanced): Standard code generation, multi-file refactoring, initial technical writing, triage.
    • Tier 3 (Frontier Reasoning): Architectural synthesis, deep multi-hop debugging, security threat modeling, formal verification.
    • Rule: Always route to the lowest sufficient tier; escalate only on detected ambiguity or failed evaluation checks.
  2. Prompt Caching Structure:
    • Organize prompts with invariant static prefixes (system instructions, tool definitions, reference schemas) at the top to maximize prefix-cache hits.
    • Place volatile per-request dynamic data, user queries, and timestamps strictly at the end of the prompt buffer.
  3. Token Budget Fences:
    • Establish hard limits on max completion tokens per turn.
    • Enforce sliding context compaction thresholds (e.g. compact conversation at 60% of window capacity rather than overflowing at 95%).
  4. Retry Backoff & Fallback Cascades:
    • Implement exponential backoff with full jitter for rate limits (429) and server errors (5xx).
    • Cascade down to smaller models or cached responses when upstream limits are encountered.
  5. Cost Telemetry:
    • Log input tokens, output tokens, cache-read tokens, and calculated cost per transaction.
    • Set automated circuit breakers that halt autonomous loops when a cost threshold is exceeded.

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.