ThinkingCap
ThinkingCap Research And Development CapCom Intent Engine for the Lab Console Chat

Intent Engine for the Lab Console Chat

Published 2026-09-22 Updated 2026-11-09 ThinkingCap
Research And Development

Intent Engine for the Lab Console Chat

Context

Campbell wants an intent engine between the console chat and FormCast: classify a chat turn, and on high confidence route directly to an action (open a form, show records, navigate a surface) with no LLM call — falling through to the LLM when unsure. Precision-first: a wrong auto-route is worse than an LLM call.

Why now: the 2026-09-14 chat-deflection postmortem — the model never called query_form_catalog on "basic settings" even though routeIntent scored that route 0.95. Deterministic pre-LLM routing removes that failure class, cuts a form-open turn from ≥3 LLM calls to zero, and drops latency from multi-second to ~300ms.

Confirmed decision (Campbell): TS-native embedding router inside phoenix for v1; AutoIntent (DeepPavlov) stays the Phase-6 graduation path, adopted only if shadow-mode data shows threshold/margin calibration insufficient. We adopt AutoIntent's decision contract (threshold + margin + OOS → null) from day one.

Companion document: Natural-Language Action Routing for Agentic Web Applications (research brief, Campbell, 2026-09-15) — the general version of this architecture (canonical intent object → deterministic policy/authz/confirmation → execution). Compared 2026-09-15: this plan already implements its core principle (probabilistic language in, deterministic action boundary) for the lowest-risk action class; the catalog + availableSurfaces gate is its "action registry" pattern. Adopted from the brief: negation/speech-act/adversarial eval cases (P0) and the canonical entities/missing object shape (P5 seam). Deferred to P6b: its mutation-side layers (action-registry metadata, confirmation step, workflow machine).

Key findings the plan builds on

Architecture (decided)

  1. Placement — server-side, pre-continueChat short-circuit in src/routes/chat.ts (insert ~line 566, after reconcile; before stream headers ~640). Gates on the turn's own availableSurfaces, so grants/allow-list hold by construction. Client-side and hybrid placements rejected (client has no catalog/grants/persistence; splits the routing brain across two operator-rolled deploys).
  2. Classifier — embedding KNN over OpenAI text-embedding-3-small. openai@^6.38.0 is already a phoenix dep. Class vectors (few hundred 1536-dim) computed once per catalog ETag, held in memory; per-turn = one ~20-token embed (~100-200ms) + in-process cosine KNN (<1ms). Embed error/timeout (800ms) → fall through. Local ONNX and AutoIntent sidecar rejected for v1 (image weight / ops burden; revisit at Phase 6 with data).

Amended 2026-09-22 (Campbell) — engine swap to LOCAL MiniLM. Day-1 soak produced the "with data" trigger this line asked for: per-turn embeds measured 200–470ms typical with an 800ms-timeout failure row (the plan's own ~300ms latency promise couldn't hold over this estate's network path). The bake-off (out/intent-corpus/eval-local-*.md) ran all-MiniLM-L6-v2 (q8 ONNX, 384-dim, in-process via @huggingface/transformers) through the same harness: 98.5% precision / 78.9% recall / 44.7% coverage at 0.80/0.04/0.08 — matching OpenAI's 98.3/79.4/45.0 to one decimal — at 27.6ms median / 78ms p95, with zero network failure classes and zero per-turn cost. Default is now INTENT_EMBED_IMPL=local (weights baked into the image, ~25MB); OpenAI stays the hot rollback (INTENT_EMBED_IMPL=openai, threshold default follows the impl: 0.80 local / 0.75 openai). The AutoIntent sidecar comparison is unaffected — that remains P6a.

  1. Intent model — two-stage: classify to form identity (one class per catalog blobDir, ~50 classes), then a deterministic verb classifier resolves fill vs records. Non-form navigation intents come from a small curated surface table (Phase 4), never from the catalog.
  2. Fall-through guards — v1 extracts nothing, and guarded messages fall through. Slot detectors (email regex, quoted strings, named|called|name is|@, key=value) → LLM, so typed values are never silently dropped. Negation cues (don't|do not|not yet|hold off|instead of|rather than) → LLM, because embedding cosine is weak on negation ("don't open the settings form" embeds ≈ "open the settings form") — the router's biggest known false-positive class. Only value-free, unnegated open-phrases short-circuit. Slot seeding (enum/boolean only, via pure choicePlan) is Phase 5.
  3. One router, two consumers: pre-LLM path uses decide() (thresholded → one action or null); query_form_catalog keeps its RouteCandidate[] contract but swaps internals via FORMS_ROUTER_IMPL=embed|llm|keyword (default embed) — removes the per-turn haiku classify from model-driven opens too (Phase 3).

Files

New (~/phoenix):

Modified (~/phoenix):

Modified (~/tc-console): nothing. Markers ride the existing wire shapes.

Response synthesis (short-circuit turn)

Intent schema

type IntentAction =
  | { kind: 'open-form-fill';    blobDir: string; title: string }
  | { kind: 'open-form-records'; blobDir: string; title: string }
  | { kind: 'open-surface';      surfaceId: string; label: string;
      target?: { view?: string; params?: Record<string,string> } };

interface IntentDecision {
  action: IntentAction; confidence: number; margin: number;
  matchedClass: string; matchedExample: string; embedMs: number;
}

blobDir ∈ loadCatalog() and surfaceId ∈ turn's availableSurfaces re-verified at decision time (mirrors the tool's registration+dispatch double-gate, chat.ts:1740-1745).

P5 extension seam: slot seeding extends IntentAction with the research brief's canonical entities/missing shape (entities: Record<string,string>, missing: string[]) rather than attaching set_fields directly to the decision — the decision object stays the single contract between classifier and synthesis.

Eval, thresholds, rollout measurement

Negative quality is what makes precision-first real.

Flags (env, operator-flippable, no client deploy)

EnvDefaultEffect
INTENT_ENABLEDfalseMaster kill-switch.
INTENT_LOG_ONLYfalseShadow: decide + log, always fall through.
INTENT_EMBED_IMPLlocalEngine: in-process MiniLM, or openai (hot rollback). (Added 2026-09-22.)
INTENT_LOCAL_MODEL / INTENT_LOCAL_MODEL_CACHE_DIRXenova/all-MiniLM-L6-v2 / image /app/.hf-cacheLocal weights + where they live (baked at image build). (Added 2026-09-22.)
INTENT_THRESHOLD / INTENT_MARGIN / INTENT_SURFACE_THRESHOLD0.80 (local) / 0.04 / 0.82 — threshold default follows the impl (0.75 for openai)Tuning without redeploy.
INTENT_EMBED_MODELtext-embedding-3-smallRollback engine's embedding model.
FORMS_ROUTER_IMPLembedTool-path internals: embed/llm/keyword.

Telemetry

One new server event (recordServerEvent, pattern at routes/chat.ts:483): intent_route: { outcome: 'routed'|'fell_through'|'shadow', kind, matchedClass, confidence, margin, runnerUpClass, embedMs, threshold, marginRequired, reason? } — logged on every eligible typed turn when enabled or shadowing. Fell-through rows = recall data; routed rows join to chat_reply for override analysis (correction next turn, form dismissed in next surfaceContext sweep).

Phases

Risks

  1. Embed-API latency/outage on typed turns — deleted by the 2026-09-22 engine swap for the default local engine (in-process; no network on the embed path). Remains on the openai rollback path, bounded by 800ms timeout + fall-through. New sibling risk: image weight (+~25MB model, +onnxruntime/sharp native deps) and a baked-weights failure mode — both self-tested at image build by the preload step.
  2. intentExamples quality unproven (dead data; sibling settings dirs may collide) — margin rule + confusion report surface it; per-dir curation is real content work (Forminator team).
  3. Offline operating point optimistic vs live — Phase-1 soak is the control.
  4. UX delta: routed open turn asks no first-field question — accepted; P5 closes it via choicePlan.
  5. Multi-intent messages ("open X and show Y") — cross-family ties fall through; residual single-half routing is rare + low-harm.
  6. Negation/speech-act false positives — embeddings score "don't open X" ≈ "open X", and "how do I X" ≈ "open X". Mitigated by hasNegationCue + explicit question-form/negated eval negatives; shadow-mode override analysis is the live control.
  7. Grant-scope drift — structurally gated on the turn's availableSurfaces; mirror any future change (e.g. staff bypass) in tests.
  8. AutoIntent + mutation-framework risk deferred, not eliminated — if P6a triggers: pin version, vendored artifact, TS fallback stays hot. P6b pulls in the brief's registry/confirmation/workflow layers only when the action risk class changes.

Verification

Read this page as Markdown: https://console.thinkingcap.com/guest/Research-and-Development/CapCom/intent-engine-plan.md
Same content, machine form. The whole corpus: /guest/all.md.