agentsclimarketplace

Llm cost optimizer

Skill wanghong5233/agent-engineering-kit/cursor/.cursor/skills/llm-cost-optimizer

A reusable, production-grade .cursor/ engineering package for Cursor / Claude Code / Agent IDEs. Rules, skills, commands, and deterministic safety hooks extracted from a real Agent project.

Install
npx -y skills add wanghong5233/agent-engineering-kit --skill llm-cost-optimizer

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Optimize LLM/Agent API cost without losing quality. Use when launching AI features, choosing models, prompt/context grows large, token spend rises, max_tokens/cache/model routing is unclear, or user asks to reduce LLM cost. Do NOT use for quality eval alone or RAG architecture alone.

SKILL.md

3.0 KB, as published. Nobody here has run it

LLM Cost Optimizer

一句话准则

LLM 成本不是账单问题,而是架构问题:先按 feature 计量,再按任务复杂度路由,最后用缓存和输出上限收口。

先分类

模式什么时候用第一产物
Cost Audit已有花费但不知道钱去哪了per-feature cost schema
Optimize Existing已知高成本路径top 3 ROI fixes
New Feature Design准备上线 Agent/LLM 功能cost guardrails before launch

没有 token/cost 日志时,不做 prompt compression;先补计量。

最小成本日志

每次 LLM/provider 调用记录:

字段说明
feature业务路径名(如 ask / summarize / research / parse)
provider / model供应商与模型
input_tokens / output_tokens原始 token
cache_hitprompt/cache 是否命中
latency_ms端到端和 provider 分段
cost_usd按当时价格表计算
route_reason为什么选这个模型
policy_version成本策略版本

优化顺序

  1. Model routing:按任务复杂度选最便宜可胜任模型;禁止默认全打大模型。
  2. Prompt caching:系统提示词、静态 few-shot、长文档上下文优先缓存。
  3. Output control:按 endpoint 设置 max_tokens,不要全局上限。
  4. Context pruning:删重复上下文、过期规则、无效 examples。
  5. Semantic cache:对重复问法高的查询做相似度缓存。
  6. Async / batch:非实时任务进队列,降低峰值成本和失败率。

Proactive Flags

信号动作
所有请求都打同一个大模型设计 model route
system prompt >2000 tokens 且每次发送加缓存或拆静态上下文
endpoint 没有 max_tokens按 p95 output 设置上限
没有 per-feature spend先加日志,不优化
free/user demo 与 paid path 同模型按用户层级 / 功能层级路由
重试导致 token 放大加 provider circuit breaker 与 retry budget

质量保护

成本优化必须有质量护栏:

  • 每个 route 变更跑 golden set。
  • 小模型替换大模型时记录 before/after pass rate。
  • 缓存命中必须带 cache_hit=true,并能强制 bypass。
  • prompt compression 只删 filler,不删 task-critical instruction。
  • 成本下降但失败重试上升,视为失败。

输出格式

## Baseline
## Cost Drivers
## Optimization Plan
## Quality Guardrails
## Expected Savings
## Rollout / Rollback

链接

  • 上游来源与改写说明:references/upstream.md
  • 质量验证:llm-observability-and-evals
  • Provider 级故障调试:agent-debugging

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.