code wiki / (root) / nx_llm_route.nx

nx_llm_route.nx

buildroot/runtime/nx_llm_route.nx

7393 B156 linesdepth 2pulls 2 transitivereach 8 importersview sourcekind librarytopic llm
docsdependenciesstructsconstsfunctions

about

nx_llm_route.nx -- MIXED-LLM ROUTING (companionchat CC6, 2026-08-30): a DATA ROW can send a chat turn to a stronger backend FIRST; the local encoder-LLM stays the fallback; and the reply records which one answered (model_route), so a route is never silent and an absent backend is never a mystery. Operator ask: "the companion intelligent, use your mixed llm". CONF llm_routes.conf, rows `tag|trigger|a.b.c.d|port`: the FIRST row whose trigger appears (case-insensitive) in the user turn selects the backend; trigger `*` matches every turn (a default route). Comments `#` and blank lines ignored. The conf is read PER TURN (data, no rebuild) from the daemon cwd, then from the nishihost knowledge tree. No conf, no match, or a malformed row = NO ROUTE, never a guess. The backend must speak the same OpenAI-shape /v1/chat/completions the local worker speaks; nothing here re-implements dispatch -- the orchestrator prepends the routed candidate to its own list. Contract symbol: go_llm_route. Gate: nx_llm_route_gate (fixture confs under /tmp, neg-controls for no-match and no-conf). license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_llm_route.nx nx_gen_orchestrator.nx nx_llm_route_gate.nx

imports: nx_syscalls.nx

imported by: nx_gen_orchestrator.nxnx_llm_route_gate.nx

structs

none

consts

13const LLR_CONF: *u8 = "llm_routes.conf" as *u8
14const LLR_CONF_ABS: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/llm_routes.conf" as *u8
16const LLR_MAXW: i64 = 8
17const LLR_TAG_CAP: i64 = 48
18const LLR_CH_PIPE: i64 = 124
19const LLR_CH_NL: i64 = 10
20const LLR_CH_CR: i64 = 13
21const LLR_CH_HASH: i64 = 35
22const LLR_CH_STAR: i64 = 42
23const LLR_CH_DOT: i64 = 46
24const LLR_CH_D0: i64 = 48
25const LLR_CH_D9: i64 = 57
26const LLR_PORT_MAX: i64 = 65535

functions

28func llr_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
29func llr_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } return o }
called by 1: go_llm_route_label
30func llr_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: llr_has_ci
33func llr_has_ci(hay: *u8, hn: i64, nd: *u8, nn: i64) -> i64
called by 1: go_llm_route_from calls 1: llr_lower
52func llr_parse_target(s: *u8, i0: i64, n: i64, w: *i64) -> i64
called by 1: go_llm_route_from
81func go_llm_route_from(path: *u8, umsg: *u8, umlen: i64, out_tag: *u8, out_w: *i64) -> i64
134func go_llm_route(umsg: *u8, umlen: i64, out_tag: *u8, out_w: *i64) -> i64
140func go_llm_route_prepend(rw: *i64, wa: *i64, wb: *i64, wc: *i64, wd: *i64, wpa: *i64, wcount: i64) -> i64
150func go_llm_route_label(routed: i64, rwin: i64, tag: *u8, dst: *u8, off: i64) -> i64
called by 2: go_handle_chat_modemain calls 1: llr_cat