Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Local-First AI Coding: Routing Simple Tasks to Qwen3.8-27B, Hard Ones to Qwen4-Max with d3 Decision Model

The author integrates vLLM's d3 decision model with HiRoute gateway to route coding tasks between a local Qwen3.8-27B and cloud Qwen4-Max. In an 11-turn session, 7 turns stayed local for file operations, while 4 difficult turns went to the cloud. The local decision model evaluates task difficulty and prior performance, keeping routing decisions on-premises.

Motivation: Most Coding Tasks Are Simple

The author observes that Coding Agents spend many turns on trivial work—listing files, reading READMEs, confirming writes—which a local 27B model can handle without sending data off-premises. Only a few turns (bug root-cause, verified fixes) justify cloud inference. The goal: keep daily work and routing decisions local, upgrading to cloud only when a turn is sufficiently hard or the previous phase performed poorly.

Architecture: HiRoute + d3 Decision Model

HiRoute (Higress team, Apache-2.0) runs on the developer's machine between the Agent (Codex) and models. The Agent points its base URL to HiRoute, unaware of multiple backends. Models are grouped: Regular (local Qwen3.8-27B) and Primary (cloud Qwen4-Max via DashScope compatible-mode).

d3 (Decision 3.0, from vLLM Semantic Router, Apache-2.0) is a 27B model (26.09B params, BF16, ~52 GB) deployed via vllm serve --tensor-parallel-size 2 on two L40 GPUs. It exposes the /v1/systemone endpoint, answering structured questions (Choice, Yes/No, Score) with probabilities in a single call. A 4B variant d3-mini runs on one L40 (~55 ms median latency vs ~122 ms for d3).

Routing Logic

On each new user message, HiRoute asks d3 three questions:

How well did the previous phase complete? (competence score)

How simple is the current turn? ( P(simple))

Does the previous issue persist?

Thresholds (defaults): P(simple) ≥ 0.80 → Regular group; previous competence < 0.50 with persistent issue → Primary group (low-score protection). HiRoute calls these Familiar trust level and Low-score protection.

Experimental Setup

Decision : d3 (System One) on 2×L40, vllm serve :8900 -tp 2, endpoint :8900/v1/systemone Regular : Qwen3.8-27B on same node, port 8910 via local proxy :18081 Primary : Qwen4-Max (Alibaba Cloud Bailian) via local shim :18084 → DashScope compatible-mode

Agent : Codex, base URL → local HiRoute /v1/responses HiRoute version 0.6.3 in Singularity (Ubuntu 22.04). Routing plan d3-bailian-route uses difficulty routing with default thresholds.

Experiment 1: Human Points Out Fix Is Wrong

Repo: small memory rate limiter with broken allow() (no timestamp eviction). First message: "Simple task: fix window eviction." d3 returns P(simple)=0.98 → local Qwen produces draft. Author replies "Wrong. Test test_blocks_over_limit_then_recovers fails after sleep window." This turn gets P(simple)=0.79 and previous competence 0.37 (<0.50) → low-score protection triggers, routed to Qwen4-Max, which rewrites eviction logic; tests pass.

Experiment 2: Gate Failure Without New Requirements

Two-turn session. Turn 1: simple fix, P(simple)=0.98 → local Qwen, competence 0.44. Turn 2: gate failure message ("pytest still fails…"), P(simple)=0.89 (above 0.80) but previous competence 0.44 < 0.50 → low-score protection routes to Qwen4-Max. Shows protection works on gate feedback, not just difficulty.

Experiment 3: 11-Turn Session Until Both Gates Pass

Repo demo-vllm-sr-decision with five broken files. Two gates: pytest tests/ (14 passed) and python diagnose.py (healthy, route_ok, latency_ok, endpoints_ok, log_ok all true). Author drives step-by-step (one action per message). Turns 1-3: list/read files → local (P(simple) 0.99-1.00). Turn 4: first real fix → cloud. Then alternates: T5 local, T6 cloud (0.69), T7 local, T8 cloud (0.60), T9 local, T10 cloud (reason unknown), T11 local (done). Demonstrates upgrade/downgrade: after hard turns, simple ones return to local.

Single Request vs Tool Continuation

In author-driven sessions, one message = one request = one routing decision. With tool-using Agents, one user message triggers multiple model requests (read → edit → test…); HiRoute keeps the same model for the whole turn to preserve prompt cache. Video recording shows T4: one decision, four requests, all on local Qwen.

What Stays Local, What Goes Cloud

Local: all routing decisions (d3 on own GPUs), 7/11 turns in long session (file ops, confirmations), any session that never upgrades.

Cloud: every turn routed to Primary group, plus full context sent in that request (including history if Agent resends).

d3 latency: ~122 ms (2×L40), d3-mini ~55 ms (1×L40) median on 12 System One test cases (coding, writing, math, ops). Both pass 12/12 System One and 8/8 HiRoute decision tests.

Key Takeaways

Two triggers are distinct: P(simple) is a pre-turn difficulty estimate; competence score is post-turn retrospective. Experiment 2 shows a turn with high P(simple) still upgraded due to low prior competence.

Design is model-agnostic: thresholds in HiRoute, decision model swappable, Agent sees single model name.

Small-scale demo, not a benchmark; but proves the local-decision + local-regular + cloud-primary pattern works end-to-end.

Reproduction Pointers

HiRoute: GitHub, hiroute.ai, local-model-routing docs. Add local model as Custom API, decision model as Other Compatible with full /v1/systemone URL, create difficulty-routing plan.

vLLM Semantic Router: GitHub, vllm-sr.ai, blog. d3 and d3-mini on Hugging Face. Deploy with

vllm serve /path/to/d3 --max-model-len 32768 --tensor-parallel-size 2 --host 0.0.0.0 --port 8900

.

VRAM: d3 ~62-65 GiB (MI325X), d3-mini ~15-23 GiB. vLLM defaults to 92% GPU memory; adjust --gpu-memory-utilization for co-location. This experiment adds NVIDIA L40 data point: both models deploy and pass tests via vllm serve.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

local inferencecloud-native AImodel routingQwen3.8-27BHiRouteQwen4-Maxd3 decision modelvLLM Semantic Router

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion