Feat/smart auto routing - #908
Conversation
…ano-Collective#891) - Add complexity classifier engine and AVA unit tests - Add SmartRoutingState to config types and app state - Add /smartroute slash command with on/off/simple/threshold subcommands - Integrate per-turn model switching into chat handler
akramcodez
left a comment
There was a problem hiding this comment.
Hey @atulya-srivastava, thanks for working on this! I went through the PR and the classifier itself looks really good - the fail-safe behavior, routing rules, and unit tests are all solid.
However, I don't think it's ready to merge yet. There are two important things I'd like you to address:
-
Integration tests: The current 16 tests only cover the pure classifier. Please add coverage for the actual
/smartroutehandler, preference persistence, and the per-turn model swap/restore behavior. We need to make sure the feature actually works end-to-end, not just that the classifier works. -
Model state mutation: The current implementation temporarily mutates the shared client's model inside
useChatHandler. I'd like us to discuss this approach before merging, particularly around concurrent submissions and ensuring the original model is always restored safely. If this approach is necessary, please document the invariants; otherwise, consider a safer way to pass the model to the LLM call.
Also, one small process note for future contributions: please ask for assignment on the issue before starting/opening a PR. It helps us coordinate contributors and avoid multiple people working on the same issue.
Once the integration coverage is added and we've discussed the model-state approach, we can take another look at this for review. The overall direction is good!
|
Hey @akramcodez , Thanks for the detailed feedback! glad to hear the classifier and routing logic look good. I took another look at how Right now, turns from the interactive CLI are submitted one at a time while streaming. That said, I agree this is a UI level behavior rather than an architectural guarantee at the client layer. Because of that, passing the model into each call is the safer approach. I propose adding an optional I will also add integration tests covering: • This avoids relying on shared mutable state and keeps the change fairly contained. I am happy to update the PR this way. What's you view regarding this approach? Also noted on asking for assignment before starting an issue. I will make sure to do that for future contributions. Thanks again for the review! |
Implements a Smart Auto-Routing cascading model strategy that dynamically routes user prompts between a lightweight model (for simple/trivial turns) and the primary "strong" model (for complex reasoning & code edits).
Closes #891.
Overview
When enabled:
/smartroute [on|off|simple <model>|threshold <low|medium|high>]to toggle and configure auto-routing at runtime.try...finallyblock guaranteeing model restoration for subsequent turns.nanocoder-preferences.jsonunder"smartRouting", ensuring choices survive terminal restarts.Notes for Reviewers
try...finallyblock insideuseChatHandler.tsxso that aborts, errors, or cancellations always restore the user's primary model cleanly.Files
source/ai-sdk-client/smart-router.ts— Core complexity classifier engine (classifyTurnComplexity&autoSelectSimpleModel)source/ai-sdk-client/smart-router.spec.ts— 16 unit tests for complexity classification rules, custom options, and model detectionsource/commands/lazy-registry.ts— Registered/smartroutein slash command lazy loadersource/app/utils/handlers/smartroute-handler.ts— Slash command handler for/smartroutesubcommandssource/app/utils/app-util.ts— Special command dispatch integrationsource/hooks/useAppState.tsx— ManagedsmartRoutingstate with persistence handlerssource/hooks/chat-handler/useChatHandler.tsx— Injected per-turn model swapping logic into the chat loopsource/hooks/useAppHandlers.tsx&source/types/app.ts— Prop-drilledsmartRoutingstate to message submission handlerssource/types/config.ts&source/config/preferences.ts— AddedSmartRoutingStateinterface & persistent storage methods fornanocoder-preferences.json.changeset/smart-auto-routing.md— Added changeset for release automationType of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm run test:typesandpnpm run buildcomplete with 0 errors)16 new tests in
source/ai-sdk-client/smart-router.spec.tscovering trivial prompts, code block detection, complex keywords, sensitivity thresholds, word boundary matching, custom options, and lightweight model auto-selection.pnpm run test:typespasses with 0 errors.Manual Testing
Manually verified via CLI non-interactive and interactive TUI sessions:
/smartroute on,/smartroute simple <model>, and/smartroute threshold <level>subcommands."smartRouting"state across CLI process restarts innanocoder-preferences.json.Checklist