Skip to content

Commit 6fbdb68

Browse files
authored
Merge pull request #3683 from GCWing/codex/router-classifier-compat-20261102
feat(router): add classifier-head compatibility and accurate probes
2 parents 2d436f1 + 3a6d174 commit 6fbdb68

24 files changed

Lines changed: 1537 additions & 65 deletions

File tree

‎src/apps/cli/src/peer_host/commands/models.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ pub(crate) async fn test_ai_config_connection(args: &Value) -> Result<Value, Str
120120
let config: AIModelConfig =
121121
serde_json::from_value(request.get("config").cloned().ok_or("Missing config")?)
122122
.map_err(|error| format!("Invalid model configuration: {error}"))?;
123+
if let Some(result) = openbitfun_core::agentic::execution::round_model_routing::configuration::test_configured_router_connection(&config)
124+
.await.map_err(|error| error.to_string())?
125+
{
126+
return serde_json::to_value(result).map_err(|error| error.to_string());
127+
}
123128
let image_input = config
124129
.capabilities
125130
.iter()

‎src/apps/desktop/README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,45 @@ Plain text continuation also applies the limit, including to old tool-image hist
862862
Each selected model or fallback channel uses its own limit at the executing host;
863863
older hosts must be upgraded to enforce this optional setting.
864864

865+
## Classifier Router services
866+
867+
On a development build with Smart mode enabled, a classifier service can use
868+
the existing OpenAI Chat Completions configuration. Add its API service and
869+
model in Settings > Models, then select it in the Smart mode configuration.
870+
For the local classifier service, use:
871+
872+
| Setting | Value |
873+
|---|---|
874+
| Request format | OpenAI Chat Completions |
875+
| Base URL | `http://127.0.0.1:8767/v1` |
876+
| Model | `router-qwen35-0.8b` |
877+
| API key | `local-router` placeholder when the model editor requires a value |
878+
| Context window | `32768` |
879+
| Router compatibility | Classifier Router |
880+
| Request timeout | Start with the service's documented allowance, such as 120 seconds for cold or long inputs |
881+
882+
Use **Save and check connections** in the Smart mode configuration. Once the
883+
model is selected as the Router service, its model-card and editor checks also
884+
use the same classifier protocol with the configuration being tested. An
885+
unselected ordinary model still receives chat/tool checks. The existing primary and
886+
economy models remain independently configured. Router classification and
887+
automatic history preparation do not change subagent model selection.
888+
889+
The Classifier Router profile sends exactly two full system/user messages,
890+
uses `router.probabilities.simple_type` for the existing economy threshold,
891+
and consumes complete `usage.prompt_tokens` for input-budget calibration.
892+
It serializes classifier calls across sessions within one execution host and
893+
connects directly to loopback endpoints. Other processes using the same
894+
single-concurrency service can still receive a busy response. Every request
895+
keeps the full prepared input; prefix caching stays on the service.
896+
897+
The default compatibility profile preserves the existing token-logprob Router
898+
wire format. An older execution host that does not advertise Classifier Router
899+
support cannot configure this profile through the GUI. Unsupported future
900+
profiles remain readable and fail explicitly rather than using another protocol.
901+
Loopback addresses refer to the machine running the Agent, including a Peer
902+
host; an SSH workspace alone does not move the Router off the execution host.
903+
865904
## Model pools
866905

867906
In **Settings → AI models → Model pools**, create named pools from existing model

‎src/apps/desktop/src/api/commands.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,13 @@ pub async fn test_ai_config_connection(
11641164
request: TestAIConfigConnectionRequest,
11651165
) -> Result<openbitfun_core::util::types::ConnectionTestResult, String> {
11661166
let model_name = request.config.name.clone();
1167+
if let Some(result) = openbitfun_core::agentic::execution::round_model_routing::configuration::test_configured_router_connection(&request.config)
1168+
.await.map_err(|error| error.to_string())?
1169+
{
1170+
info!("Router model connection test completed: model={}, success={}, response_time={}ms",
1171+
model_name, result.success, result.response_time_ms);
1172+
return Ok(result);
1173+
}
11671174
let supports_image_input = request.config.capabilities.iter().any(|cap| {
11681175
matches!(
11691176
cap,

‎src/crates/adapters/ai-adapters/AGENTS.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ cargo test --locked -p openbitfun-ai-adapters --lib round_router
265265
facts. Core retains thresholds, model-slot selection, context lifecycle, traces,
266266
and fallback; the adapter must not depend on Core config or Agent sessions.
267267

268+
The explicit `OpenAiRouterExtension` profile reads classifier probabilities from
269+
`router.probabilities.simple_type`, validates them against the content prediction,
270+
and sends only the supported non-streaming classification request. Legacy
271+
`OpenAiLogprobs` requests remain unchanged. Loopback extension services connect
272+
directly; other endpoints retain the configured proxy policy.
273+
274+
For an opt-in live classifier check, set `ROUTER_EXTENSION_TEST_URL`,
275+
`ROUTER_EXTENSION_TEST_MODEL`, and `ROUTER_EXTENSION_TEST_SYSTEM_PROMPT` (the path
276+
to the complete classifier system prompt), then run:
277+
278+
```bash
279+
cargo test --locked -p openbitfun-ai-adapters --lib live_router_extension_profile_returns_real_classifier_usage -- --ignored
280+
```
281+
282+
The normal fixtures exercise loopback HTTP and proxy behavior, not a deployed
283+
provider, SSH, Peer Device Mode, relay, or detached dispatch.
284+
268285
Local Router token counting (optional `local-tokenizer`, no model downloads):
269286

270287
```bash

‎src/crates/adapters/ai-adapters/src/client/http.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ pub(crate) fn create_router_http_client(
1010
timeout: std::time::Duration,
1111
proxy_config: Option<ProxyConfig>,
1212
skip_ssl_verify: bool,
13+
) -> Result<Client> {
14+
create_router_http_client_with_connection_mode(timeout, proxy_config, skip_ssl_verify, false)
15+
}
16+
17+
/// Only explicit local classifier profiles opt into a direct loopback connection.
18+
/// Other Router and model traffic keeps the existing shared proxy policy.
19+
pub(crate) fn create_router_http_client_with_connection_mode(
20+
timeout: std::time::Duration,
21+
proxy_config: Option<ProxyConfig>,
22+
skip_ssl_verify: bool,
23+
direct: bool,
1324
) -> Result<Client> {
1425
openbitfun_services_core::tls_provider::ensure_ring_crypto_provider();
1526
let builder = Client::builder()
1627
.timeout(timeout)
1728
.redirect(reqwest::redirect::Policy::none())
1829
.danger_accept_invalid_certs(skip_ssl_verify);
19-
Ok(apply_proxy_policy(builder, proxy_config).build()?)
30+
let builder = if direct {
31+
builder.no_proxy()
32+
} else {
33+
apply_proxy_policy(builder, proxy_config)
34+
};
35+
Ok(builder.build()?)
2036
}
2137

2238
pub(crate) fn create_http_client(

0 commit comments

Comments
 (0)