Commit Graph
9 Commits
Author SHA1 Message Date
Satya Devineni d397a6e8fa Add SystemOne decision models: /v1/systemone, GGUF zero-shot on /v1/classify, and the systemone router classifier (#3956)
* main into zero shot, post refactoring

* cleanup

* cleanup

* CR feedback: fixed the residency document clarification bug

* cr feedback: fake tests with propoer assertions

* stacks on the zero shot work in 3952

* pr feedback: better policy checks and logging for backend failures

* pr feedback: adding on_truncation

* pr feedback: adding the truncation support for classifier and fixing documentation issues

* CI fix and doc enhancement

* pr feedback: fixed edge cases

* added check for 0.3.7 truncated verification

* pr feedback: router validation and argument handling

* Added the example lfm2 ONNX model

* pr feedback: added max-length and 3 flag truncate flags

* pin bump to 0.4.0 and more tests for zero-shot

* CI fix

* pr feedback: model level filtering

* PR Feedback: CR feedback

* restricting decision models based on model family. 8k context limit by default for encoder decision models

* checks at router level to reject wrongly labeled systemone models with 400

* pr feedback: default set to 4k, limits passed down by llama-server, truncated  is added to systemone

* truncated documentation

* pr feedback: checks the token count instead of the template
2026-11-04 05:34:34 +00:00
Satya Devineni f9004ca0a8 Adding zero-shot classifier support (#3952)
* main into zero shot, post refactoring

* cleanup

* cleanup

* CR feedback: fixed the residency document clarification bug

* cr feedback: fake tests with propoer assertions

* pr feedback: better policy checks and logging for backend failures

* pr feedback: adding on_truncation

* pr feedback: adding the truncation support for classifier and fixing documentation issues

* CI fix and doc enhancement

* pr feedback: fixed edge cases

* added check for 0.3.7 truncated verification

* Added the example lfm2 ONNX model

* pr feedback: added max-length and 3 flag truncate flags

* pin bump to 0.4.0 and more tests for zero-shot

* CI fix

* pr feedback: clarified on the PII detector
2026-10-29 17:21:53 +00:00
0141ffb048 feat(routing): add expected_output_tokens signal to RouteContext (#3163)
* feat(routing): add expected_output_tokens signal to RouteContext

Read the caller's max_tokens / max_completion_tokens (max_tokens wins if
both are present) into RouteContext::Params::expected_output_tokens, a
ceiling rather than an estimate, left unset when neither field is sent or
the value is non-positive/non-integer.

No ranking logic changes yet: this is plumbing for a later token-weighted
cost_select ranking (raised in PR #3100 review), which will read this field
once it exists.

* fix(routing): read max_output_tokens for /v1/responses' expected_output_tokens

build_route_context only checked max_tokens/max_completion_tokens, so a
collection.router request through /v1/responses never populated
expected_output_tokens even when the caller set max_output_tokens — the
name that endpoint uses for the same limit. Once token-weighted
cost_select ranking lands, that endpoint would silently rank on a
guessed output length instead of the real one.

Addresses review feedback from meghsat on PR #3163.

* fix: close test function left open by the #3181 merge resolution

Both sides of the conflict in test_routing_classifier_services.cpp ended
mid-function, sharing the closing brace that sat below the conflict
region. Reordering the halves left #3181's last test function unclosed,
so every following definition parsed as nested.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: ramkrishna2910 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-08-25 04:58:36 +00:00
Satya Devineni e87a351219 feat(router): add min_total_chars / max_total_chars whole-conversation length conditions (#2958) (#3181)
* Adding a new server side leaf: min and max total chars

* Undo GUI bug fixes: created a separate PR #3180

* CI bug fixes
2026-08-24 21:33:12 +00:00
Salah Eddine BekhoucheandClaude Sonnet 5 10600f0921 feat(router): report estimated cost on collection.router decisions (#2763)
* feat(router): attach illustrative cost metadata to routing decisions

Wire a CostServices seam into RoutingPolicyEngine so that once route_to
is resolved (matched rule or default), per-candidate cost/latency info
(typed ModelInfo fields when known, hand-authored extras otherwise) is
merged into Decision::outputs.estimated_cost. Reporting only — this
does not change candidate selection, just surfaces cost visibility on
collection.router decisions the same way it's already shown on
/v1/models.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(router): address PR #2763 review feedback

Make cost attachment exception-safe by catching exceptions from cost_of,
preserve existing estimated_cost values, improve try_get_model_info()
error handling, and add tests for these scenarios.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(router): finish remaining PR #2763 review feedback

Replace the <0-means-unknown sentinel in resolve_cost_info with
std::optional<double>, add CostInfo::to_json() to remove the duplicated
field mapping, memoize CostServices::cost_of per candidate to avoid a
registry lookup on every routing decision, validate cost_tier against
free|low|medium|high, log cost_of failures once per candidate instead of
per-request, and add tests covering typed+extras precedence and the
rejected cost_tier case.

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
2026-08-10 22:55:43 +00:00
1d56aafa3a [Router] llm router classifier + routing.router desugaring (#2405) (#2698)
* [Router] llm router classifier + routing.router desugaring (#2405)

* Address review: authored-name labels, exact-only matching, trace label, schema alignment (#2698)

* clean the patch

* Address 2nd review: classifier slot, constrained router invocation, structured choice (#2698)

* Fixing CMakeLists afet -> Address 2nd review: classifier slot, constrained router invocation, structured choice (#2698)

* drop classifier-slot changes (deferred to #2725); enforce structured-reply contract (#2698)

* [Router] Structured routing context for llm router + per-candidate trace rationale (#2698)

* [CI] Build and run RoutingPolicyLlmRouterTest in Linux/macOS C++ test steps (#2698)

* [CI] Restore Tiny-Test-Model-GGUF to SmolLM2; add Tiny-Gemma-Test-Model-GGUF (#2698)

* Revert "[CI] Restore Tiny-Test-Model-GGUF to SmolLM2; add Tiny-Gemma-Test-Model-GGUF (#2698)"

This reverts commit 8e540437a7.

* [Router] Deterministic L0a live test via mock cloud router (#2698)

* fix(router): stabilize LLM router CI contract

---------

Co-authored-by: QuOussama <[email protected]>
Co-authored-by: Florian Reinle <[email protected]>
2026-07-20 13:24:43 +00:00
41ef688dab Wire collection.router classifiers to Router::classify + validate model capability at parse time (#2727)
* Wire routing classifier services to Router::classify for ModelType::CLASSIFICATION

run_classifier previously always called chat_completion, so a
collection.router classifier condition could never actually reach an
onnxruntime-backed model (WrappedServer's default chat_completion() is
an unsupported-capability error for backends that don't implement it).
Add classify/get_model_type callbacks (both optional, defaulting to
the prior chat-completion-only behavior) and route to Router::classify
when the target model is tagged ModelType::CLASSIFICATION.

Verified live: a collection.router policy using an onnxruntime
classifier now produces real per-request scores and routes benign vs.
flagged input differently, instead of always falling through to
on_error regardless of input.

* Validate classifier/semantic_similarity model capability at policy-parse time

routing.classifiers[].model was only checked for existence (via
resolve_component + require_declared), never for capability. A
"classifier" entry pointing at, say, an embedding or image model would
register successfully and only fail at request time with a generic
router error. Add an optional get_model_type resolver to
RoutingPolicyParseOptions and validate: "classifier" needs LLM (chat-
completion-based) or CLASSIFICATION (/v1/classify); "semantic_similarity"
needs EMBEDDING. Wired at both production parse sites (build_cache's
routing-policy parse and validate_collection_request's registration-time
compile-check); left unset in existing parser unit tests, which keeps
their behavior unchanged.

Verified live: registering a policy whose classifier model is an
embedding model is now rejected immediately with a clear error instead
of silently succeeding.

* Fix ModelType fallback ambiguity for unresolvable/inline components

RoutingModelTypeResolver returned a bare ModelType, defaulting to LLM
whenever a component couldn't be resolved (e.g. an inline collection
component not registered yet). Since LLM is an accepted classifier
type, this was asymmetric and registration-order-dependent: a valid
inline semantic_similarity + inline embedding model was rejected
("type llm, needs embedding"), while an invalid inline classifier +
inline image/embedding model was silently accepted.

Change the resolver to return std::optional<ModelType>; the parser
now throws a clear "unresolvable type" error instead of guessing.
validate_collection_request derives the type from the matching inline
`models[]` definition's labels when the component isn't registered
yet (reusing the existing find_inline_def matching), only falling
back to nullopt when genuinely nothing is known. build_cache's
resolver simplifies to nullopt on a cache miss, since everything real
is already present by that point.

Addresses fl0rianr's review on #2727.

* Preserve throw-before-load ordering in run_classifier

ensure_model now ran unconditionally before checking whether
chat_completion_call was configured, so a caller relying on
"missing chat_completion call throws before any load side effect"
would observe a different order than before the classify-routing
change. Check whether the classify path will be used first (a pure
function of the model's type, no side effects), then validate
chat_completion_call is configured before calling ensure_model when
falling back to it.

Nit from ramkrishna2910's review on #2727.

* Add unit tests for classify routing and capability validation

- run_classifier: a ModelType::CLASSIFICATION model routes through
  classify (not chat_completion); a non-CLASSIFICATION model falls
  back to the chat-completion path as before.
- Parser capability check: classifier accepts LLM/CLASSIFICATION and
  rejects EMBEDDING; semantic_similarity accepts EMBEDDING and rejects
  LLM; an unresolvable (nullopt) type is a hard error, not a silent
  pass.
- The exact regression pair from fl0rianr's review: an inline
  semantic_similarity condition backed by an inline embedding
  definition must pass, and an inline classifier condition backed by
  that same embedding definition must fail.

Requested by ramkrishna2910's review on #2727.

* Fix collection.router validation rejecting label-less inline models

validate_collection_request's get_model_type lambda only derived a type
from an inline models[] definition when it had a "labels" array, and
returned nullopt otherwise - even when the definition existed. An inline
model with no labels (a plain chat/completion model, the common case)
was thus treated as unresolvable and rejected as an invalid classifier
target, even though get_model_type_from_labels() would correctly default
it to ModelType::LLM. Now nullopt is only returned when no inline
definition is found at all.

Caught by CI: test_model_manager_collection_validation exercises exactly
this via valid_router_collection()'s label-less "pii-detector" fixture.

* Load model before resolving type in run_classifier (cold start)

Router::get_model_type() reports ModelType::LLM until the backend is loaded and
alive, so resolving the type before ensure_model() made the first request after
startup/eviction/restart pick the chat path for a classify-only model —
recreating the unsupported-capability / on_error failure this routing exists to
avoid. Resolve the type after loading; move the chat_completion-configured guard
onto the chat branch.

Adds a regression test simulating the cold-start transition (get_model_type
returns LLM before ensure_loaded, CLASSIFICATION after) — it fails on the old
ordering and passes now.

Addresses the second blocker in fl0rianr's review.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Centralize inline model-type derivation for collection.router validation

validate_collection_request() derived an unregistered inline component's type
from its explicit `labels` only, while register_user_model() also applies legacy
capability flags (embedding/reranking/vision/reasoning) and the backend
descriptor's default_labels. So a label-less sd-cpp model validated as LLM
(accepted as a classifier) but registered as IMAGE, and a legacy `embedding:true`
model was rejected for semantic_similarity though it registers as an embedder —
both recreating the runtime capability mismatch this PR prevents.

Extract normalized_definition_labels() and use it in both places so validation
and registration cannot drift. Adds ModelManagerCollectionValidationTest cases
(against the real resolver, not a fake): label-less sd-cpp as classifier fails,
legacy embedding:true for semantic_similarity passes, label-less llamacpp still
defaults to LLM.

Addresses fl0rianr's third review.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Make routing model-type backend-capability-aware (chat-indicator bypass)

get_model_type_from_labels() gives chat-indicator labels (reasoning/vision/
tools/chat-transcription) priority, so a non-chat backend plus a stray
chat-indicator label typed as LLM at BOTH validation and runtime
(router.cpp sets the runtime type from model_info.type). An onnxruntime model
with reasoning:true, or an sd-cpp model with vision:true, was therefore accepted
as a classifier and — for onnxruntime — sent down run_classifier's chat path,
which OnnxRuntimeServer cannot serve (IClassificationServer only): the original
unsupported-capability / on_error fail-open, back again.

Add get_deployment_model_type(recipe, labels): the backend descriptor's default
labels declare a definitive non-LLM deployment (onnxruntime->classification,
sd-cpp->image, whispercpp->transcription, ...), which wins over chat-indicator
labels because those backends do not implement chat_completion. Use it at every
ModelInfo::type derivation site (fixing runtime) and in the inline validation
resolver (fixing parse-time). Only affects models with a contradictory
chat-indicator label on a non-chat backend, so real catalog models are unchanged.

Tests: onnxruntime+reasoning is CLASSIFICATION (accepted, routes to classify);
sd-cpp+vision is IMAGE (rejected as classifier).

Addresses fl0rianr's fourth review.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Declare kokoro's TTS default label so it can't be typed as a classifier

kokoro is the only non-chat backend with empty default_labels, so a label-less
kokoro model still typed LLM and slipped past classifier-capability validation
into run_classifier's chat path (which KokoroServer cannot serve). Give the
descriptor its true default label ("tts") so get_deployment_model_type() pins it
to TTS. Catalog kokoro models already carry "tts" explicitly, so they are
unaffected. Adds a label-less-kokoro-as-classifier rejection test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Don't type a chat backend CLASSIFICATION from a spurious label

/v1/classify (IClassificationServer) is implemented only by the onnxruntime
backend. A `classification`/`classifier` label on a chat backend (llamacpp/flm/
ryzenai/vllm/cloud) previously typed the model CLASSIFICATION, so run_classifier
called Router::classify() and hit an unsupported-capability error — the inverse
of the chat-indicator bypass, and the same on_error fail-open.

get_deployment_model_type() now drops a classification claim once it has fallen
through to a backend with no definitive non-LLM deployment (onnxruntime already
returns CLASSIFICATION via its default label before this point), so such a model
stays LLM and is served via the chat-classifier path, never Router::classify.

Test: llamacpp + labels:["classification"] stays LLM and is accepted as a
classifier via the chat path.

Addresses fl0rianr's fifth review.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: QuManu <[email protected]>
Co-authored-by: ramkrishna2910 <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-20 08:29:07 +00:00
cc9ed37912 Router/2385 collection.router recipe dispatch (#2558)
* feat(router): add policy parser and hot-reload store

* feat(router): preserve collection routing metadata

* test(router): cover policy loading in CI

* fix(router): align pull validation with policy compilation

* fix(router): reject duplicate policy model names

* feat(router): wire classifier services to router calls

* Fixed parse_scores_payload to only check message.content not metadata

* Initial implementation

* Addressed five issues raised

* Addressed comments

* Addressed build_route_context comment

---------

Co-authored-by: Eddie Richter <[email protected]>
Co-authored-by: ramkrishna2910 <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-08 01:07:39 +00:00
eddierichter-amdandSlawomir Nowaczyk 75e9af27d1 feat(router): wire classifier services to router calls (#2548)
* feat(router): wire classifier services to router calls

* Fixed parse_scores_payload to only check message.content not metadata

* fix(router): validate classifier score ranges

---------

Co-authored-by: Slawomir Nowaczyk <[email protected]>
2026-07-07 06:55:32 +00:00