You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(routing): Add cost-aware auto-routing with complexity estimation
- Add estimate_complexity() for trivial/standard/complex task classification
- Add get_tiered_agent() for complexity-based model selection
- Route trivial tasks to codex-mini/gemini-fast (cheaper models)
- Route complex tasks to codex/gemini-pro (premium models)
- Add CLI flags: -Q/--quick, -P/--premium, --tier
- Fix Bash 3.2 compatibility (macOS) for lowercase conversion
- Update help text with Cost Control section
Closes: Cost optimization for simple tasks
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
local word_count=$(echo "$prompt"| wc -w | tr -d '')
187
+
local score=2 # Default: standard
188
+
189
+
# TRIVIAL indicators (reduce score)
190
+
# Short, simple operations that don't need premium models
191
+
local trivial_patterns="typo|rename|update.?version|bump.?version|change.*to|fix.?typo|formatting|indent|whitespace|simple|quick|small"
192
+
local single_file_patterns="in readme|in package|in changelog|in config|\.json|\.md|\.txt|\.yml|\.yaml"
193
+
194
+
# Check for trivial indicators
195
+
if [[ $word_count-lt 12 ]];then
196
+
((score--))
197
+
fi
198
+
199
+
if [[ "$prompt_lower"=~ ($trivial_patterns) ]];then
200
+
((score--))
201
+
fi
202
+
203
+
if [[ "$prompt_lower"=~ ($single_file_patterns) ]];then
204
+
((score--))
205
+
fi
206
+
207
+
# COMPLEX indicators (increase score)
208
+
# Multi-step, architectural, or comprehensive tasks need premium models
209
+
local complex_patterns="implement|design|architect|build.*feature|create.*system|from.?scratch|comprehensive|full.?system|entire|integrate|authentication|api|database"
210
+
local multi_component="and.*and|multiple|across|throughout|all.?files|refactor.*entire|complete"
211
+
212
+
# Check for complex indicators
213
+
if [[ $word_count-gt 40 ]];then
214
+
((score++))
215
+
fi
216
+
217
+
if [[ "$prompt_lower"=~ ($complex_patterns) ]];then
218
+
((score++))
219
+
fi
220
+
221
+
if [[ "$prompt_lower"=~ ($multi_component) ]];then
222
+
((score++))
223
+
fi
224
+
225
+
# Clamp to 1-3 range
226
+
[[ $score-lt 1 ]] && score=1
227
+
[[ $score-gt 3 ]] && score=3
228
+
229
+
echo"$score"
230
+
}
231
+
232
+
# Get complexity tier name for display
233
+
get_tier_name() {
234
+
local complexity="$1"
235
+
case"$complexity"in
236
+
1) echo"trivial (🐙 quick mode)" ;;
237
+
2) echo"standard" ;;
238
+
3) echo"complex (premium)" ;;
239
+
*) echo"standard" ;;
240
+
esac
241
+
}
242
+
243
+
# Get agent based on task type AND complexity tier
244
+
# This replaces the simple get_agent_for_task for cost-aware routing
245
+
get_tiered_agent() {
246
+
local task_type="$1"
247
+
local complexity="${2:-2}"# Default: standard
248
+
249
+
case"$task_type"in
250
+
image)
251
+
# Image generation always uses gemini-image
252
+
echo"gemini-image"
253
+
;;
254
+
review)
255
+
# Reviews use standard tier (already cost-effective)
256
+
echo"codex-review"
257
+
;;
258
+
coding|general)
259
+
# Coding tasks: tier based on complexity
260
+
case"$complexity"in
261
+
1) echo"codex-mini" ;; # Trivial → mini (cheapest)
262
+
2) echo"codex-standard" ;; # Standard → standard tier
0 commit comments