Local LLM Model Router: NeuralWatt routing service + context-aware framing and pruning #6
Reference in New Issue
Block a user
Delete Branch "neuralwatt-router-service"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements the Local LLM Model Router (see
design/local-llm-model-router.md,README.md) as a FastAPI dispatcher against NeuralWatt Cloud, pluscontext-aware classification framing and relevance-based context pruning.
Highlights
filters + quality-first ranking dispatch to the cheapest/best-fit open-weight
model on NeuralWatt, weighted by cost, per-category proficiency, and a
per-request energy ceiling. Cost is priced per request from catalog token
prices scaled to the request's shape.
/v1):auto/auto:batchvirtual modelsand any real model id, streaming proxy with SSE energy/cost telemetry
scraping, capability gates (vision / JSON mode / tools), local vision
fallback.
classifier.context_framing):_previous_contextfeeds the classifier the prior assistant turn so short follow-ups inherit its
complexity; framing instruction travels only with content that justifies it.
pinch.*, off by default): trims old tool results oncepast
budget_tokens; user/assistant/system always kept verbatim, non-textblocks preserved, honest
tokens_savedaccounting, image payloads stubbed sotrimming actually shrinks what ships upstream.
route_decisionspersistence,GET /metrics, TUIdashboard, router_cli probe.
POST /outcome,feedback.pyfolding real outcomes into proficiency.Reviewed
Both rounds of fixes (the 11 confirmed review findings plus the
image-accounting regression found on second pass) are included and verified:
545 offline tests pass,
lsp_diagnosticsclean.Port two ideas from the MIT-licensed alexrudloff/llmrouter: 1. Context-aware classification. chat_completions now feeds the classifier the message before the last user turn, framed as llmrouter's "Context: <prior>\n---\nMessage: <current>" (classifier.context_framing, default on). A short follow-up ("Yes", "Try now?") inherits the prior turn's complexity instead of being classified in isolation as trivial. _classifier_user_content is a pure, testable framing helper; the system prompt gains the inherit-from-context rule. 2. Relevance-based context pruning (context_prune.py). An optional, pre-dispatch stage that trims old tool results from the provider-bound conversation once it exceeds pinch.budget_tokens (pinch.enabled defaults off). User/assistant/system messages are always kept verbatim; only old tool results are summarized (head+tail with an elision marker) or dropped to a placeholder, with role pairing preserved so the result still parses as a conversation. Applies to both the streaming and non-streaming upstream bodies; the classifier input is exempt (it already clamps). Tests: +23 (pruning invariants, framing, previous-context extraction, pinch config validation). 529 pass.