Expand description
§Module: Cost Optimizer
§Responsibility
Analyses historical request cost patterns and produces actionable
optimisation suggestions. Can optionally apply suggestions automatically
when auto_optimize = true.
§Detections
- Cache candidates — prompts whose responses are highly similar across invocations (response fingerprint collision rate above threshold).
- Model overuse — expensive models being used for structurally simple tasks (short prompt + short response).
§Guarantees
- Thread-safe (
Arc<CostOptimizer>shareable across tasks) - Bounded memory: observation windows capped at
window_size - Non-blocking: all methods are O(window_size), no I/O
- Advisory only unless
auto_optimize = true
Structs§
- Auto
Apply Action - An automatically applied optimisation action.
- Cost
Observation - A single cost observation recorded for one inference call.
- Cost
Optimizer - Analyses cost patterns and generates (or applies) optimisation suggestions.
- Cost
Optimizer Config - Cost optimizer configuration.
- Model
Tier Entry - An entry in the model tier table.
- Optimization
Suggestion - A single optimisation suggestion with computed ROI.
Enums§
- Cost
Optimizer Error - Errors produced by the cost optimizer.
- Model
Tier - Tier classification for a model.
- Suggestion
Kind - The kind of cost optimisation suggested.