cost-aware-llm-pipeline
成本感知 LLM 管道,根据任务复杂度选择合适模型, 管理上下文预算,避免在长会话末尾做大型重构。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- cost-aware-llm-pipeline
- origin
- adapted from ECC
- description
- 成本感知 LLM 管道,根据任务复杂度选择合适模型, 管理上下文预算,避免在长会话末尾做大型重构。
03 SKILL.md 正文
Cost-Aware LLM Pipeline Skill
成本感知 LLM 管道,根据任务复杂度选择合适模型,管理上下文预算。
何时激活
- 需要优化模型选择以控制成本
- 需要管理上下文使用预算
- 需要为不同复杂度任务选择合适模型
- 需要在长会话中避免上下文溢出
模型选择策略
Haiku (轻量级)
使用场景:
- 简单任务:语法修正、格式化、小改动
- 频繁调用:grep、glob、文件探索
- 工具调用规划
成本: ~$0.001/1K tokens
Sonnet (主开发)
使用场景:
- 主要开发工作
- 复杂编码任务
- 多文件重构
- 代码审查
成本: ~$0.01/1K tokens
Opus (深度推理)
使用场景:
- 复杂架构决策
- 深度推理任务
- 新技术调研
- 关键问题调试
成本: ~$0.05/1K tokens
上下文预算管理
预算规则
| 上下文位置 | 可用空间 | 建议 |
|---|---|---|
| 前 20% | 宽松 | 探索、研究、讨论 |
| 中间 60% | 谨慎 | 核心实现、详细代码 |
| 最后 20% | 压缩 | 整理、总结、收尾 |
避免的错误
- ❌ 在上下文最后 10% 做大型重构
- ❌ 在低上下文空间启动复杂任务
- ❌ 用 Opus 处理 Haiku 就能完成的任务
正确做法
- ✅ 在上下文中间启动复杂任务
- ✅ 在低空间使用 Haiku 做简单任务
- ✅ 定期压缩上下文避免溢出
任务复杂度分级
L1: 简单(用 Haiku)
- 语法修正
- 文件格式化
- 简单搜索替换
- README 更新
L2: 中等(用 Sonnet)
- 函数实现
- 单元测试编写
- 代码审查
- Bug 修复
L3: 复杂(用 Sonnet 或 Opus)
- 多文件重构
- 架构设计
- 复杂调试
- 新模块设计
L4: 深度(用 Opus)
- ADR 编写
- 架构决策
- 性能优化
- 跨系统设计
成本优化技巧
1. 批处理相似任务
# 不好:多次调用,每次都加载上下文
/edit file1.ts
/edit file2.ts
/edit file3.ts
# 好:一次调用处理多个文件
/multi-edit file1.ts file2.ts file3.ts
2. 使用上下文压缩
长会话后运行: /compact
保留决策和结论,丢弃中间追踪
3. 选择正确模型
# 不好的做法
用 Opus 写 README
# 好的做法
用 Haiku 写 README
用 Sonnet 实现核心逻辑
用 Opus 做架构决策
与其他 Skills 的关系
| Skill | 关系 |
|---|---|
| Strategic Compact | 提供上下文压缩以保持低使用率 |
| Continuous Learning | 从成本数据中学习优化模型选择 |
| Memory Persistence | 保存会话摘要以支持上下文重建 |
命令接入
/cost-estimate <task>- 估算任务成本/model-select <complexity>- 建议模型选择/context-budget- 显示当前上下文预算
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.