07
帕累托前沿 · Pareto Front
多目标优化 · 用于 Agent 架构决策
核心直觉
在多目标优化中,不存在一个解在所有维度都最优
改善任何一个维度,必然牺牲另一个 — 这是数学必然
实践含义:
1. 先明确你的约束优先级
2. 找到帕累托前沿上对应的点
3. 不要在"前沿内部"浪费时间(存在同时更好的解)
Claude Code 场景 — Agent 配置选型
真实场景
为 AI 内容 agent 选择:模型、并发数、重试策略。速度/质量/成本三者不能同时最优,必须先明确优先级再选配置。
agent-config-selector.ts
// 三条产品线的帕累托配置 const paretoConfigs = { // 支付确认:速度 > 质量 > 成本 'payment-confirm': { model: 'claude-haiku-4-5', concurrency: 10, maxRetries: 1, // 宁可失败,不能超时 timeoutMs: 2000, streaming: true, tradeoff: 'speed=10, quality=6, cost=9', }, // 内容生成:质量 > 成本 > 速度 'xerpa-content': { model: 'claude-sonnet-4-6', concurrency: 3, maxRetries: 3, // 允许重试,追求质量 timeoutMs: 30000, streaming: false, tradeoff: 'speed=4, quality=9, cost=5', }, // 数据分析:成本 > 质量 > 速度 'data-analytics': { model: 'claude-haiku-4-5', concurrency: 1, // 串行,省 token maxRetries: 2, timeoutMs: 60000, // 允许慢 cacheEnabled: true, // 激进缓存 tradeoff: 'speed=2, quality=7, cost=10', }, }; // 关键:每条业务线明确自己在哪个前沿点,不混用 function getAgentConfig(productLine: string) { const config = paretoConfigs[productLine]; if (!config) throw new Error( `Unknown product line: ${productLine}. Must explicitly define tradeoffs first.` ); return config; }
帕累托支配检查 — 找出"绝对差"的配置
pareto-check.ts
// 帕累托支配:如果 A 在所有维度都 >= B,则 B 被支配(B 是次优的) function isDominated( candidate: Config, others: Config[], objectives: (keyof Config)[] ): boolean { return others.some(other => objectives.every(o => other[o] >= candidate[o]) && objectives.some(o => other[o] > candidate[o]) ); } // 使用:淘汰被支配的配置 const paretoFront = configs.filter(c => !isDominated(c, configs, ['speed', 'quality', 'cost']) ); // 剩下的才值得讨论,它们才是真正的 tradeoff 选择
⚠ 反模式
给同一个 agent 设置"又快又好又便宜"的目标,然后不停调参试图同时提升三个维度。这违反了帕累托定理。正确做法是先决定"什么最重要",再接受另外两个维度的牺牲。
拿走就能用 — 粘贴进你的 CLAUDE.md
CLAUDE.md
架构决策约束
## 架构决策原则(帕累托约束)
### 本项目的优先级(按顺序)
1. 正确性 > 速度 > 成本
- 宁可慢,不要错
- 宁可贵,不要用户不信任
### 禁止"同时优化三个维度"
- 每次架构讨论必须明确:这次牺牲哪个
- 如果有方案声称"全都能优化",必须质疑
### agent 配置时的 tradeoff 模板
- 高质量场景(对外输出):quality first,允许慢 3x、贵 5x
- 高频内部场景(数据处理):speed first,允许质量 -20%
- 实验/原型阶段:cost first,允许不稳定