#70

Intelligent model routing for Claude Code

Openjzgarcia27opened 9mo ago

Problem

When running Ralph with Claude Code, all stories use the same model regardless of complexity. This means:

  • Simple tasks (text changes, config tweaks) use expensive Opus tokens unnecessarily
  • Complex tasks that need Opus get the same treatment as trivial ones
  • No way to optimize for cost vs. quality tradeoffs

Proposed Solution

Add intelligent model routing that assigns the appropriate Claude model (opus/sonnet/haiku) to each user story based on complexity and risk.

Two modes:

  • --mode max-quality: Opus for everything (current behavior, default)
  • --mode cost-efficient: Right model for each story (explicit choice)

Key design decisions:

  • Opus is always the "orchestrator" that analyzes stories and assigns models during PRD conversion
  • Decision principle: when in doubt, round up (prefer more capable models when uncertain)
  • Users can override any assignment by editing prd.json before running

Model assignment criteria:

  • opus: Schema changes, auth, payments, complex logic, any uncertainty
  • sonnet: Standard CRUD, typical UI, well-defined scope
  • haiku: Trivial text changes, obvious pattern repetition, config tweaks

Auto-escalation: If a story fails twice, Ralph automatically escalates to a more capable model:

  • haiku → sonnet (after 2 failures) → opus (after 4 failures)
  • sonnet → opus (after 2 failures)

This self-corrects when the assigned model can't handle a task.

Implementation

I have a working implementation ready that touches:

  • ralph.sh - adds --mode flag, model selection, and auto-escalation
  • skills/ralph/SKILL.md - model assignment rules for PRD conversion
  • prd.json schema - adds model and failures fields to stories
  • Documentation updates

Open to feedback on the approach.

Activity

0

No activity yet.