Files
optimclaw/docs
69cddb10fd feat: integrate 13-dimension complexity scorer into smart routing (#529)
* feat(llm): add smart model routing based on request complexity

Automatically selects optimal model tier (flash/standard/pro/frontier) for each
request based on 13-dimension complexity scoring:

- Reasoning words, multi-step signals, code indicators
- Domain-specific terms, creativity, precision
- Safety sensitivity, tool likelihood, question complexity
- Token estimate, context dependency, sentence complexity

Features:
- Pattern overrides for fast-path routing (greetings → flash, security audits → frontier)
- Configurable tier-to-model mappings (defaults to -latest aliases)
- Thinking mode per tier (pro: low, frontier: medium)
- User-configurable pattern overrides
- Zero-config for default benefits, full control for power users

Expected cost savings: 50-70% vs always-using-frontier baseline.

Refs: smart-routing-spec.md

* fix(routing): address Gemini Code Assist review feedback

- Add tracing warnings for invalid tier/regex in user overrides (router.rs)
- Use unreachable!() for tier hint match since regex enforces valid tiers (scorer.rs)
- Refactor weighted total to array iteration for maintainability (scorer.rs)
- Add TODO for making domain keywords configurable (scorer.rs)

Refs: PR #208

* feat(routing): make domain keywords configurable

- Add ScorerConfig with optional domain_keywords field
- Add DEFAULT_DOMAIN_KEYWORDS constant (exported for reference)
- Add domain_keywords to RouterConfig for top-level configuration
- Build domain regex at runtime from config, fallback to defaults
- Add score_complexity_with_config() function
- Add test for custom domain keywords

Users can now provide project-specific keywords:

  RouterConfig {
      domain_keywords: Some(vec!["mycompany".into(), "myproduct".into()]),
      ..Default::default()
  }

Addresses Gemini Code Assist review feedback on PR #208.

Tests: 20/20 passing

* docs: add domain_keywords to routing config example

* feat: integrate 13-dimension complexity scorer into smart routing (takeover #208)

Folds the 13-dimension complexity scorer and pattern overrides from PR #208
into the existing SmartRoutingProvider, replacing the simpler keyword-based
classifier. Adds 4-tier system (Flash/Standard/Pro/Frontier), configurable
scorer weights, domain keywords, regex pattern overrides, tier hints, and
multi-dimensional boost. Removes separate routing/ directory and lazy_static
dependency in favor of std::sync::LazyLock. Includes 44 tests covering all
scoring dimensions, tier boundaries, pattern overrides, and provider routing.

Co-Authored-By: onlyamicrowave <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: address review feedback on smart routing PR (#529)

- Cache compiled domain regex in SmartRoutingProvider (built once at
  construction, not per-request) and add score_complexity_with_regex() API
- Check explicit tier hints before pattern overrides so user intent wins
  (e.g. "[tier:flash] security audit" routes as Flash, not Frontier)
- Trim input before matching/scoring so trailing whitespace doesn't break
  anchored override regexes or skew token-length scoring
- Fix token estimate comment (>=520 chars = 100, not >500)
- Update spec: check implementation plan boxes, fix file paths, add note
  that llm.routing YAML schema is target design (current config uses env vars)
- Add regression tests for tier hint precedence and trimmed greeting matching

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: restore Cargo.lock from main to fix html_to_markdown test

The lockfile was fully regenerated during the PR #208 merge conflict
resolution, which bumped html-to-markdown-rs from 2.25.1 to 2.27.2.
The new version produces different output that breaks the golden-file
snapshot test. Restore the original lockfile from main — lazy_static
was never in main's lockfile, so no further changes needed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: address second round of review feedback (#529)

- Tighten quick-lookup override regex with end anchor to prevent matching
  complex questions like "What time complexity is merge sort?"
- Handle empty domain keywords list by falling back to defaults instead of
  producing a broken regex that matches empty strings everywhere
- Clarify spec architecture diagram: current impl uses 2-provider split
  (cheap/primary), per-tier model mapping is target design
- Add regression tests for both fixes

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Microwave <[email protected]>
Co-authored-by: Joe <[email protected]>
Co-authored-by: onlyamicrowave <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-03-05 09:14:07 +00:00
..