cost-optimize
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Optimize
成本优化
Analyze recent token usage across agents and models, identify waste, and recommend specific optimizations with estimated dollar savings.
分析各Agent和模型近期的令牌使用情况,识别浪费点,并提供带有预估美元节省金额的具体优化建议。
When to use
使用场景
When costs are higher than expected or you want to proactively reduce spending. Analyzes model selection efficiency, cache utilization, agent redundancy, and prompt efficiency.
当成本超出预期,或者您希望主动降低支出时使用。分析内容包括模型选择效率、缓存利用率、Agent冗余度以及提示词效率。
Steps
步骤
- Load usage data -- call to fetch recent token usage records from
mcp__claude-flow__agentdb_hierarchical-recallnamespace (last 7 days)cost-tracking - Analyze model fit -- for each agent, assess whether the model tier matches task complexity:
- Agents doing simple tasks (formatting, linting) on Sonnet/Opus -> suggest Haiku or Agent Booster
- Agents doing complex tasks (architecture, security) on Haiku -> flag quality risk
- Check cache rates -- compute cache hit rate per agent; if below 60%, recommend enabling or improving prompt caching (90% cost reduction on cache reads)
- Detect redundancy -- look for multiple agents performing overlapping tasks, or agents being spawned for work that could be batched
- Estimate savings -- for each recommendation, calculate: current cost, projected cost after optimization, dollar savings, percentage reduction
- Search patterns -- call for previously successful optimizations
mcp__claude-flow__agentdb_pattern-search - Store recommendations -- call to record optimization recommendations in
mcp__claude-flow__agentdb_pattern-storenamespacecost-patterns - Report -- display: ranked recommendations with savings estimate, total potential savings, implementation priority (quick wins first)
- 加载使用数据 —— 调用从
mcp__claude-flow__agentdb_hierarchical-recall命名空间获取最近7天的令牌使用记录cost-tracking - 分析模型适配性 —— 针对每个Agent,评估模型层级是否匹配任务复杂度:
- 执行简单任务(格式化、代码检查)的Agent使用Sonnet/Opus -> 建议改用Haiku或Agent Booster
- 执行复杂任务(架构设计、安全检测)的Agent使用Haiku -> 标记质量风险
- 检查缓存率 —— 计算每个Agent的缓存命中率;若低于60%,建议启用或改进提示词缓存(缓存读取可降低90%的成本)
- 检测冗余性 —— 查找执行重叠任务的多个Agent,或者可批量处理却单独生成Agent的情况
- 预估节省金额 —— 针对每项建议,计算:当前成本、优化后的预计成本、美元节省金额、成本降低百分比
- 搜索优化模式 —— 调用查找过往成功的优化方案
mcp__claude-flow__agentdb_pattern-search - 存储建议 —— 调用将优化建议记录到
mcp__claude-flow__agentdb_pattern-store命名空间cost-patterns - 生成报告 —— 展示:按节省金额排序的建议、潜在总节省金额、实施优先级(优先快速见效的方案)
CLI alternative
CLI替代方案
bash
npx @claude-flow/cli@latest memory search --query "cost optimization strategies" --namespace cost-patternsbash
npx @claude-flow/cli@latest memory search --query "cost optimization strategies" --namespace cost-patterns