Skip to content

Let Team model routers classify requests with a decision model, within its context - #348

Merged
Pengfei Ni (feiskyer) merged 3 commits into
mainfrom
feat/team-router-jev-classifier
Oct 29, 2026
Merged

Pengfei Ni (feiskyer) merged 3 commits into
mainfrom
feat/team-router-jev-classifier

Conversation

@Zhupku

@Zhupku Zhupku commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Team model routers (Team.spec.modelRouters) could classify requests only with LiteLLM's heuristic scorer or with a shared chat model (llm). Routers defined in the AI Gateway chart can also use a decision model, such as Microsoft-Decision-1, through LiteLLM's jev classifier. In our tests that classifier placed 39 of 40 English prompts and 39 of 40 of their Chinese translations on the expected tier (every pair on the same tier), where the heuristic classifier placed 15 and 11 and never chose the complex or reasoning tier. This change lets a Team's routers use it too, and keeps a decision classifier working for requests with a long system prompt.

Team routers with a decision model (first commit)

  • CRD. classifier.type takes jev besides heuristic and llm; classifier.model is required for llm and jev. For jev it names a shared decision model: a shared model whose model_info.mode is evaluation. The comment that said LiteLLM's licence limit keeps other classifier types away from Teams is corrected: LiteLLM limits a jev classifier only when it sets its own instructions.
  • Operator. The router is registered with classifier_type: jev, jev_classifier_config: {deployment_name: <model>} and classifier_fallback: default_model (second commit), and no instructions, so LiteLLM's own instructions apply and the router does not count against LiteLLM's licence limit. The router planner now sees every shared model, not only chat models, and refuses with a specific message:
    • a tier or an llm classifier that names a shared model that answers no conversation;
    • a jev classifier that names a shared model that is not a decision model;
    • a router named like any shared model (before, only like a chat model).
      The classifier is granted as before: it must be a shared model, need not be listed by the AgentPolicy, is not put on the Agent's key, and its calls are charged to the Agent. A classifier change replaces the router's registration without changing Agents' configuration.
  • Catalog. The operator publishes the Gateway's decision models in the catalog the Portal reads (decisionModels), still apart from the shared models Agents are configured with, and seeds them on start like the shared models.
  • Portal. The Team page offers a "Decision model" classifier with the Gateway's decision models; the Team API accepts jev. Agent creation options are unchanged.

Decision classifier requests within the decision model's context (second commit)

Measured directly, Microsoft-Decision-1 refuses a request over its 32,768-token context with 422 ("Question prompt exceeds the 32768-token context limit including the decision token"), in any language: about 31,000 English words or 40,000 Chinese characters. LiteLLM sends a jev classifier the caller's whole system prompt and its latest user messages, however long they are, so every request of an Agent with a long system prompt was refused, and the router silently classified it with the heuristic scorer.

  • Guard. A router's classifier call to a decision model is shortened to as many bytes as the model takes tokens: the smallest model_info.max_input_tokens of the decision model's deployments, or 32,768 when none sets it, less the questions LiteLLM asks and 512 bytes for the service's own template. A token of a decision model stands for at least one byte of text, so the shortened request fits in any language. It keeps the newest user message whole where it fits, and the beginning and the end of the rest; a newest message that does not fit keeps its beginning and its end. The Gateway logs a warning with the decision model and the sizes, not the content. A client's own calls to the Decisions API, and classifier calls to a chat model, are left as they are.
  • Fallback. Routers with a jev classifier, Team routers and the Gateway chart's own alike, send a request whose classification failed anyway (for example while the decision model is unavailable) to their default model, the medium tier, instead of to the heuristic scorer. A chart router that sets classifier_fallback keeps its value; one with its own tier_definitions keeps its fallback_tier.
  • Docs. teams.md (smart routing, with a jev example and the behaviour above), crds.md, models.md, and the Gateway chart README (the router defaults and the guard callback).

Related issue

Follow-up to #263, which added Team model routers, and to #344. No separate issue.

Validation

Offline (Linux container: Go 1.27.3, Helm 3.22.0, Python 3.11; Windows: Go 1.27.3, Node with vitest):
  gofmt -l on the changed Go files: empty
  app/cetirun-operator: go vet OK; go test ./api/... ./internal/aigateway/... ./internal/controller/...: pass
    (first commit: 3019 passed, 4 skipped; again after merging main and after the second commit)
  app/cetirun-portal: go vet OK; go test ./internal/...: 907 passed
  CRDs and deepcopy regenerated with controller-gen v0.21.0; regenerating after the merge of main gives no
    diff; the two CRD copies are identical
  bash scripts/cetirun-platform-helm-test.sh and scripts/cetirun-ai-gateway-helm-test.sh: pass;
    python3 -B scripts/ci/validate.py chart-check: pass
  python3 -B -m unittest discover -s scripts/tests: 738 OK, 26 skipped (guard tests: 79 OK)
  Portal web: tsc --noEmit OK; vitest 45 files, 472 tests pass
  Site unit tests 106 OK; source content/style checks: no errors; license headers OK; git diff --check clean
New tests:
  CRD schema: enum is heuristic, llm, jev; CEL cases for jev with and without a model
  planner: registration IDs of existing heuristic and llm routers are pinned to the values main produced
    (no re-registration on upgrade), and they carry no classifier_fallback; the jev registration carries
    deployment_name and classifier_fallback default_model only; non-chat tier, non-chat llm classifier,
    non-decision jev classifier and a router named like a non-chat model are refused
  end to end in the controller: a jev router is registered and granted to a policy-bound Agent whose
    policy does not list the decision model; the key gets the router only; changing the decision model
    re-registers the router without changing the Agent's configuration; removing the decision model
    withdraws the router
  catalog: decision models found (every deployment of a name must be one), published, seeded on start; a
    start during a Gateway outage keeps the jev router's registration
  Portal handler and web: jev accepted with a model, refused without one or with copilot/; the decision
    classifier offers decision models only
  guard (12 new): an oversized English or Chinese request is shortened within the byte budget, keeps the
    newest message whole and valid UTF-8; an oversized newest message keeps its two ends; a request without
    LiteLLM's marker keeps its two ends; a deployment's max_input_tokens lowers the budget; the questions
    count; a client's own Decisions API call and a chat classifier call are never changed; a second pass
    changes nothing
  chart: a jev router renders classifier_fallback default_model; its own value and tier_definitions are
    kept; heuristic and llm routers get none
  Mutation checks: 23 (first commit) and 21 (second commit: guard 14, operator 3, chart 4), all caught
Live, LiteLLM side only:
  a test cluster's AI Gateway (LiteLLM 1.105.6): a temporary router with the exact body the operator built
    for a jev Team router in the first commit, and a temporary key holding only the router's and the tier
    models' groups, not the decision model's: /model/new 200; 8 requests 200, all classified by
    jev_classifier (REASONING for a proof, SIMPLE for a factual question, REASONING for a proof written in
    Chinese, COMPLEX for a coding task); the key cannot call the decision model directly (403); deleted
  local proxy, LiteLLM 1.105.1 (the router, filter and classifier code paths involved are identical in
    1.105.6) with Microsoft-Decision-1 and mock tier models, main's guard and settings against this branch's:
      system prompt of 40,000 English words: main heuristic_scorer (Decision-1 422) -> branch jev_classifier,
        request shortened 242,641 -> 31,680 bytes, which Decision-1 counted at 5,687 tokens
      system prompt of 60,004 Chinese characters: main heuristic_scorer (422) -> branch jev_classifier,
        180,153 -> 31,678 bytes (6,541 tokens)
      a 122 KB log as the message: main heuristic_scorer (422) -> branch jev_classifier, both ends of the
        message kept (13,300 tokens)
      a decision model answering 500: main heuristic_scorer -> branch default_model_fallback, answered by the
        medium tier model
      a short request: jev_classifier in both
Not run: envtest suites (no binaries here); Hugo build (make docs-check; CI runs it); the operator and
  Portal from this branch on a cluster

Compatibility and operational impact

  • CRD: the enum gains jev and the classifier rule now also requires a model for jev. Existing Teams stay valid. Upgrade the CRD with the operator, as the charts do.
  • Existing heuristic and llm routers keep their registration IDs, so an upgrade does not register them again.
  • A Team router named like a shared model that answers no conversation, such as a decision model, is now refused as misconfigured. Agents that had such a router lose it.
  • The published catalog gains decisionModels; the Portal's Agent creation options do not include them.
  • Gateway chart routers with a jev classifier that do not set classifier_fallback send a request whose classification failed to their default model after the upgrade, instead of to the heuristic scorer; on that path a request is not moved to another tier by its length. The Gateway pods roll once, as for any configuration change.
  • A router's classifier request to a decision model over the model's context is shortened instead of refused; the Gateway logs a warning for each.
  • Changing a router's classifier, for example from llm to jev, replaces its registration in the Gateway and leaves legacy Agents' configuration unchanged. Adding a router, as before, adds a model to the Agents granted it, which restarts them once. Native Sandbox Agents take the whole Team spec as an execution input, so any router edit restarts them once.

Checklist

  • The change is focused and preserves unrelated work.
  • Tests cover the changed behavior, or I explained why no new test is needed.
  • Documentation and examples match any public behavior changes.
  • Generated artifacts were updated from source, or none are affected.
  • Dependency changes include lockfiles, source attribution, and license information, or none are affected.
  • I checked the diff and attachments for secrets, private endpoints or identifiers, customer data, agent conversations, and internal information.
  • I followed the applicable CLA instructions, or asked a maintainer about an unclear check.
  • I identified checks that need credentials or a live environment and did not run them without authorization.

Team model routers take a third classifier type, jev: the router asks a
shared decision model of the AI Gateway, such as Microsoft-Decision-1,
to pick the tier. The operator registers it with LiteLLM's
jev_classifier_config naming the decision model only, so LiteLLM's own
instructions apply and the router does not count against LiteLLM's
licence limit. The operator publishes the Gateway's decision models in
its catalog, the Portal offers them for the new classifier, and the
router planner now sees every shared model: it refuses a tier or an llm
classifier that answers no conversation, and a jev classifier that is
not a decision model.

In our tests Decision-1 placed 39 of 40 English and 39 of 40 Chinese
prompts on the expected tier, where the heuristic classifier placed 15
and 11. Until now only routers defined in the Gateway chart could use
it.

The registrations of existing heuristic and llm routers are unchanged,
so an upgrade does not register them again. A Team router named like a
shared model that answers no conversation, such as a decision model, is
now refused as misconfigured. Apart from that case, the operator change
itself restarts no Agent.
@Zhupku Zhupku self-assigned this Oct 28, 2026
The guard shortens the request a router sends a decision model to
classify a request to as many bytes as the model takes tokens: the
smallest model_info.max_input_tokens of its deployments, or 32,768,
Microsoft-Decision-1's, less the questions and 512 bytes for the
service's own template. Each token is at least one byte of text, so the
request fits in any language. The newest user message stays whole where
it fits, and the rest keeps its beginning and its end; the Gateway logs
each change without its content. A client's own calls to the Decisions
API are left as they are.

Routers with a jev classifier, Team routers the operator registers and
routers in the Gateway chart alike, now send a request whose
classification failed to their default model, the medium tier, instead
of to LiteLLM's heuristic scorer. A router that sets classifier_fallback
keeps its value; one with its own tier_definitions keeps its
fallback_tier.

Measured directly, Microsoft-Decision-1 refuses a request over 32,768
tokens with a 422. LiteLLM sends the classifier the caller's whole
system prompt, so every request with a long system prompt was refused,
and the router silently used the heuristic scorer, which placed 15 of
40 English and 11 of 40 Chinese prompts on the expected tier in our
tests. With LiteLLM 1.105.1 and Microsoft-Decision-1 on a local rig,
requests with a 40,000-word English or a 60,000-character Chinese system
prompt, or a 120 KB log as the message, were classified by the decision
model after the change and by the heuristic scorer before it.

Chart routers with a jev classifier that do not set classifier_fallback
send a failed classification to their default model after the upgrade,
which rolls the Gateway pods. Team routers with a jev classifier are new
on this branch and are registered with the setting from the start.
Heuristic and llm routers, and their registrations, are unchanged.
@Zhupku Zhupku changed the title Let Team model routers classify requests with a decision model Let Team model routers classify requests with a decision model, within its context Oct 28, 2026

@feiskyer Pengfei Ni (feiskyer) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@feiskyer
Pengfei Ni (feiskyer) merged commit db58ddf into main Oct 29, 2026
34 checks passed
@feiskyer
Pengfei Ni (feiskyer) deleted the feat/team-router-jev-classifier branch October 29, 2026 08:31
Zhupku added a commit that referenced this pull request Nov 2, 2026
…re it writes (#397)

* Align the install, Sandbox and smart-routing docs with make deploy, decision-model Team routers and optional Teams

Since #364, make deploy DEPLOY_CONFIG=<environment.yaml> installs the
platform. The site still told readers to run the platform helper with DOMAIN
and VALUES_FILE, which now exits with an error, and to install Sandbox
admission without enforcement themselves, which make deploy refuses.

- Install CetiRun: make publish with the VS Code Server license acceptance,
  what must exist before the first make deploy (with the Gateway's Secrets),
  the environment file, make deploy-plan and make deploy.
- Policy-bound Teams: the admission certificate and administrators before the
  first run, then the registration, the peer labels, and a second make deploy
  that enables Sandbox execution.
- Smart routing: models in the environment file, with the auto router and the
  decision model that make deploy requires; a Team router named auto-team,
  because auto is the Gateway's; decision models for Team routers (#348);
  default_model_fallback, and a log query on routing_cause.
- Gateway chart README, teams.md and models.md: a jev router falls back to its
  default model, and the guard shortens its classifier requests (#348). make
  publish needs the license flag.
- first-instance.md: a Team is optional (#353), and the form's model switches,
  default model and Agent Identity switch.
- helm.md, scripts.md, infrastructure.md, and the platform README and values
  comments: make deploy instead of the earlier helper's variables.
- The site test now expects make deploy on the installation page, and no
  VALUES_FILE invocation.

* Say that LiteLLM's spend log keeps prompts and responses by default

Since #363, spendLogs.storePrompts defaults to true, so each row of
LiteLLM_SpendLogs holds the call's prompt and response. The Helm reference
and the platform values comment still said that neither is stored. The
stdout request log still carries no content.

* Name a wrong managed Istio Deployment or mesh ConfigMap before make deploy writes

AKS managed Istio adds the revision to the name of the ingress gateway
Deployment, but the example environment file had the name without it. The
preflight then failed at kubectl rollout status, and the helper withholds
tool output, so the run only said "kubectl --context failed with exit 1".

The preflight now makes sure that the configured control plane and ingress
Deployments exist before it waits for them. If one does not exist, it names
the input, and the name with the revision when that Deployment exists. It
does not replace a configured name.

A mesh ConfigMap that does not exist is created by the helper. AKS managed
Istio reads only istio-shared-configmap-<revision>, so a different name left
the OAuth2 provider out of the mesh without an error. The preflight now stops
when the configured ConfigMap does not exist but that one does.

* Give the example's ingress Deployment its revision, and say how to read the AKS Istio names

The example named the control plane Deployment and the mesh ConfigMap with
the revision placeholder, but not the ingress gateway Deployment. Install
CetiRun and the platform README now say which managed Istio names carry the
revision, how to read them from the cluster, and when make deploy stops.

---------

Co-authored-by: Scott Zhu <mengzezhu@microsoft.com>
Pengfei Ni (feiskyer) pushed a commit that referenced this pull request Nov 3, 2026
… router names (#396)

* Give Gateway routers the smallest limits of their models

A router configured in the Gateway's models had no context window or output limit in Agent configurations unless the administrator set them on the router, so Agents used their own defaults, which can exceed a tier model's window. The catalog now gives such a router the smallest limits among its tier and default models, as for a Team's router; limits set on the router are kept. Only Agents configured with the router are reconfigured when its limits change.

* Send a router's request on to its other models when its tier fails

A complexity router's tier model that failed, such as an Agent's GitHub Copilot model while its proxy was down, failed the request with 503 although the router's other tiers could answer, and the error named the router's internal model group. The guard now gives a router request fallbacks for that request only: the tier's other models, the higher tiers, the default model, then the lower tiers. Fallbacks the administrator, a key, a team or the request names apply instead; refusals and unreadable encrypted reasoning still go to no other model. LiteLLM's router details are kept out of errors, retry fields are dropped from router_settings_override as from the body, and the request log records fallback_from, attempted_fallbacks and fallback_cause.

* Let Agents use a Team's router by its name

Hermes showed a Team router by its internal name, cetirun-router-<hash>, and clients that list the key's models saw that name. The operator now keeps a key alias for each granted Team router, the router's name for its internal name, unless the Agent reaches another model by that name, and records it on the router's status. Hermes is configured with the router's name; OpenClaw keeps the internal name its sessions hold. The Gateway lists such a router under its name only. A Policy's per-model limit for a Team router's name is set under the internal name, which the Gateway counts.

* Describe the jev classifier of Team routers and its fallback in the routing docs

The smart-routing page and the Gateway README still said that Team routers classify with heuristic or llm only and that a failed decision classifier falls back to the heuristic scorer. Team routers take a decision model since #348, the Gateway shortens a request to fit the decision model, and a jev router sends a request it cannot classify to its default model.

* Say what attempted_fallbacks counts and record the live tier-fallback measurement

On the e2e cluster, a router request whose Copilot tier failed was answered after a fallback to the router's Azure tier and a failover within that model, and the request log reported attempted_fallbacks 2 where the response header said 1: LiteLLM counts failovers to another deployment of the same model as well.

* Keep a policy limit on a Team router's name when another model keeps the name

A per-model limit that an AgentPolicy sets for a Team router's name was
moved to the router's internal name. When one of the Agent's GitHub Copilot
models has the same name, the key gets no alias for the router, and the
Agent still requests the Copilot model by that name. The Copilot model then
had no per-model limit, on every reconcile, also when the router was not
granted.

The operator now copies the limit to the internal name and keeps it under
the router's name. The Gateway counts the router's requests under the
internal name, also those sent by the alias. The name's limit applies to the
other model when the name is not the router's alias. The copy does not
depend on the alias, which the same pass decides later, after the Copilot
routes are registered, so no pass leaves either model without its limit. If
the policy limits both names, the internal name gets the smaller value.

Tests: the existing limit test now expects the name to keep its limit and
checks the smaller-value rule in both directions; a new test covers a router
named like a Copilot model with RPM and TPM limits, granted and withdrawn.

* Say that a standalone Gateway does not limit a router's tier fallbacks to the key

The README said that LiteLLM uses only the models that the caller's key can
use for the fallbacks that the guard adds to a router's request. LiteLLM
examines the key for fallback targets only with
general_settings.enforce_fallback_model_access, which the chart sets with
operatorIntegration. main now says the same for router.fallbacks. A
standalone Gateway does not examine the key, but these fallbacks go only to
the router's own models, which the router can select for the key anyway.

---------

Co-authored-by: Scott Zhu <mengzezhu@microsoft.com>
Pengfei Ni (feiskyer) pushed a commit that referenced this pull request Nov 3, 2026
* Give Gateway routers the smallest limits of their models

A router configured in the Gateway's models had no context window or output limit in Agent configurations unless the administrator set them on the router, so Agents used their own defaults, which can exceed a tier model's window. The catalog now gives such a router the smallest limits among its tier and default models, as for a Team's router; limits set on the router are kept. Only Agents configured with the router are reconfigured when its limits change.

* Send a router's request on to its other models when its tier fails

A complexity router's tier model that failed, such as an Agent's GitHub Copilot model while its proxy was down, failed the request with 503 although the router's other tiers could answer, and the error named the router's internal model group. The guard now gives a router request fallbacks for that request only: the tier's other models, the higher tiers, the default model, then the lower tiers. Fallbacks the administrator, a key, a team or the request names apply instead; refusals and unreadable encrypted reasoning still go to no other model. LiteLLM's router details are kept out of errors, retry fields are dropped from router_settings_override as from the body, and the request log records fallback_from, attempted_fallbacks and fallback_cause.

* Let Agents use a Team's router by its name

Hermes showed a Team router by its internal name, cetirun-router-<hash>, and clients that list the key's models saw that name. The operator now keeps a key alias for each granted Team router, the router's name for its internal name, unless the Agent reaches another model by that name, and records it on the router's status. Hermes is configured with the router's name; OpenClaw keeps the internal name its sessions hold. The Gateway lists such a router under its name only. A Policy's per-model limit for a Team router's name is set under the internal name, which the Gateway counts.

* Describe the jev classifier of Team routers and its fallback in the routing docs

The smart-routing page and the Gateway README still said that Team routers classify with heuristic or llm only and that a failed decision classifier falls back to the heuristic scorer. Team routers take a decision model since #348, the Gateway shortens a request to fit the decision model, and a jev router sends a request it cannot classify to its default model.

* Say what attempted_fallbacks counts and record the live tier-fallback measurement

On the e2e cluster, a router request whose Copilot tier failed was answered after a fallback to the router's Azure tier and a failover within that model, and the request log reported attempted_fallbacks 2 where the response header said 1: LiteLLM counts failovers to another deployment of the same model as well.

* Send images to the Gateway models that accept them

OpenClaw and Hermes treated most Gateway models as text-only: Hermes every
one, OpenClaw every name its own catalog does not know (routers, Copilot
Claude and Gemini, merged names). Hermes had the model describe each image
in an extra call; OpenClaw had another model describe it and offered no
computer tool.

The operator now reads supports_vision from the Gateway's model info and
the price table. A shared name accepts images when every deployment does,
and the Agent's own Copilot route under the name too; a router when every
model it sends requests to answer does. A chart that declares
aiGateway.visionModels gets the list: OpenClaw sets input text and image,
Hermes supports_vision, for those models only.

* Keep the label of OpenClaw's tool-result images out of router classification

With images, OpenClaw passes on the images of a tool result, such as a
screenshot of its computer tool, in a user message of their own, labelled
"Image(s) from tool result #1 (computer):". A complexity router classifies
the newest message a person wrote and took that label for it: measured on
LiteLLM 1.105.6, a request for a design that a heuristic router put in the
medium tier went to the simple tier after one screenshot. A jev router kept
the complex tier.

Team routers and the routers of the Gateway chart that set no markers of
their own now leave the label out, as they leave out OpenClaw's context.
Each Team router is registered again once, as its configuration changes.

* Keep a policy limit on a Team router's name when another model keeps the name

A per-model limit that an AgentPolicy sets for a Team router's name was
moved to the router's internal name. When one of the Agent's GitHub Copilot
models has the same name, the key gets no alias for the router, and the
Agent still requests the Copilot model by that name. The Copilot model then
had no per-model limit, on every reconcile, also when the router was not
granted.

The operator now copies the limit to the internal name and keeps it under
the router's name. The Gateway counts the router's requests under the
internal name, also those sent by the alias. The name's limit applies to the
other model when the name is not the router's alias. The copy does not
depend on the alias, which the same pass decides later, after the Copilot
routes are registered, so no pass leaves either model without its limit. If
the policy limits both names, the internal name gets the smaller value.

Tests: the existing limit test now expects the name to keep its limit and
checks the smaller-value rule in both directions; a new test covers a router
named like a Copilot model with RPM and TPM limits, granted and withdrawn.

* Say that a standalone Gateway does not limit a router's tier fallbacks to the key

The README said that LiteLLM uses only the models that the caller's key can
use for the fallbacks that the guard adds to a router's request. LiteLLM
examines the key for fallback targets only with
general_settings.enforce_fallback_model_access, which the chart sets with
operatorIntegration. main now says the same for router.fallbacks. A
standalone Gateway does not examine the key, but these fallbacks go only to
the router's own models, which the router can select for the key anyway.

---------

Co-authored-by: Scott Zhu <mengzezhu@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants