Route reform/distributional questions to Opus#89
Open
vahid-ahmadi wants to merge 1 commit into
Open
Conversation
Haiku tends to burn the iteration budget guessing the reform-API shape on distributional / reform-shape questions; Opus converges in 2–4 iterations on the same prompt, so net cost goes down even though per-turn cost is higher. Add a cheap pure-Python heuristic in `_select_chat_model` that looks at the latest user message for: - distributional vocabulary (decile, quintile, distributional, winners, losers, poverty, inequality, gini) - reform-shape verbs/nouns (reform, increase/raise/cut/change the, replace, freeze, uprate, bump) - marginal/effective rate reasoning - magnitude expressions (1pp, "percentage point", "by N%", "from X% to Y%") via a small compiled regex `charts_mode=True` also upgrades (charts usually imply distributional analysis). `plan_mode=True` ALWAYS keeps the fast model — plan turns are just clarifying questions, low cognitive load. Length-based Sonnet fallback is preserved for non-reform questions whose input exceeds the fast-model context budget. Closes #83 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Beta preview is ready.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_select_chat_modelinbackend/routes/chatbot.pyto upgrade reform / distributional / reasoning-heavy turns from Haiku to Opus.Why
Live test: a user asked a distributional/reform question, the stream confirmed routing to
claude-haiku-4-5, and Haiku never converged on the reform API shape — it blew the 60-iteration budget guessing. Opus converges in 2–4 iterations on the same prompt. Per-turn Opus is ~5x Haiku, but reforms on Haiku reach the iteration cap and waste ~15x more turns, so net cost should go DOWN.Heuristic
Case-insensitive substring/regex match on the latest user message only:
Keywords (substring, case-insensitive):
decile,quintile,distributional,winners,losers,poverty,inequality,ginireform,increase the,raise the,cut the,change the,replace,freeze,uprate,bumpmarginal rate,effective rate,marginal tax,effective taxpercentage point(catches "points" too),1ppRegex for magnitudes not captured as substrings:
This catches
by 5%,from 20% to 25%,2pp.Wiring
chat_request.plan_modeandchat_request.charts_modeare passed as kwargs to_select_chat_model(preferred over overriding outside — keeps the routing decision in one place).charts_mode=Truealso upgrades to Opus (charts usually imply distributional analysis).plan_mode=TrueALWAYS returnsDEFAULT_FAST_MODEL, regardless of any other signal.Model constant
Added
DEFAULT_REASONING_MODEL(defaults toclaude-opus-4-5, env-overridable viaANTHROPIC_REASONING_MODEL) — there was no Opus constant in this file yet despite the issue's wording. Naming/version follows the same convention asclaude-haiku-4-5/claude-sonnet-4-6.Logging
Each Opus upgrade emits:
Cost note
Opus ~5x Haiku per turn. But on reform questions Haiku reaches
max_iterations=60; Opus converges in 2–4. Net cost should drop.Test plan
TestSelectChatModelunit tests inbackend/tests/test_api.py:"model": "claude-opus-4-5"Closes #83
🤖 Generated with Claude Code