agent-cost-and-latency
Skill3 starsChanged 38 days agoMITView on GitHub
Optimize AI-system cost and latency per verified successful outcome using measured budgets. Use when profiling model/tool/retrieval spend or delays, setting agent run ceilings, choosing model routing/escalation, caching, batching or parallelism under quality constraints. Do not use for general application performance without model/agent costs, speculative model recommendations, or reducing tokens without outcome measurements.
In this repository18 other files it gives its agents.
- agent-architectureSkill
- agent-development-workflowSkill
- agent-evalsSkill
- agent-failure-recoverySkill
- agent-guardrailsSkill
- agent-observabilitySkill
- agent-orchestrationSkill
- agent-securitySkill
- agent-state-and-memorySkill
- agent-testingSkill
- deterministic-authoritySkill
- evidence-provenanceSkill
- human-in-the-loopSkill
- prompt-engineeringSkill
- rag-engineeringSkill
- structured-output-designSkill
- tool-designSkill
- tool-evalsSkill
The file
Files
Agent Cost and Latency
Measure the full logical task before optimizing it. Token savings are not a win if errors, retries or incomplete results make successful outcomes more expensive.
Establish the baseline and ceilings
- Define verified success, safe abstention, quality/safety floors and user-facing latency target. Measure representative task slices, p50/p95 wall time, token categories, tool/retrieval time, number of steps/calls, cache behavior and all failed/retried work. Pin model/prompt/tool versions and pricing timestamp; use measured billing when available and label estimates.
- Compute cost per successful task = total attributable spend across all attempts / verified successes. Report success rate and abstention mix alongside it; if successes=0 the metric is undefined, not zero. Include queueing, human wait time where relevant and coordination costs. Separate interactive response latency from completion latency.
- Enforce maximum steps, model calls, tool calls, retrieved candidates/context, fan-out, deadline and spend in software. Reserve aggregate worker budgets and preserve them across resume. Stop or return a supported partial/abstained result when limits are exhausted; do not silently drop validation to hit a budget.
Optimize the measured bottleneck
- Route to the smallest model/workflow that satisfies the eval gate; escalate on calibrated hard-case/validation signals within explicit call/spend limits. A cheap failed call followed by a large model can cost more than direct routing. Compare routing end to end, including fallbacks.
- Reduce context by removing irrelevant/redundant evidence and verbose tool outputs while preserving needed provenance and constraints. Improve retrieval/assembly before raising context limits. Measure recall and groundedness after reduction.
- Cache only stable reusable work with keys covering principal/tenant, permissions, input, model/prompt/schema/tool/index versions and freshness requirements. Never reuse approvals, authoritative changing state or cross-tenant output as if current. Define expiry/invalidation and charge cache creation/read costs correctly.
- Parallelize independent reads/model tasks only when it reduces critical-path latency within rate/concurrency/spend limits. Keep dependent actions ordered. Batch offline independent work when supported and latency tolerance permits; bound queue time and retry blast radius. Use deterministic orchestration where sufficient.
- Reduce loops and needless calls before adding clever routing. Coalesce coherent tool operations where semantics/authority remain clear. Do not hide side effects inside a read tool to save a round trip.
Compare and verify
- Change one variable, run matched eval tasks under comparable load/cache conditions, repeat noisy measurements and examine tail behavior. Keep gains only if success, safety, groundedness and latency floors hold. Report cost per success, failures and p95, not only average tokens. Read cost comparison for a worked denominator trap.
Deliver a baseline ledger, bottleneck evidence, enforced ceilings, one optimization experiment and a quality-gated retain/revert decision. Generic profiling belongs to ordinary performance work (or a performance-optimization skill, if available); this skill owns model/retrieval/trajectory economics. Do not recommend a provider/model by reputation without current measured evidence.
Evaluate model choices per role (extraction, reasoning, routing, verification, grounded generation, multimodal interpretation, embedding/reranking), then measure the assembled system. One model may satisfy several roles; an extra verifier/model needs an on/off or matched-routing ablation on the same gold set. Record role errors and whole-task quality, cost per success and latency to verified completion. Participation statistics and provider reputation do not prescribe models. agent-evals owns rigor; agent-orchestration owns route transitions.
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
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.

