Repository navigation
Description
Overview
Stage-1 routing (ADR-038) decides whether a user's message is clear enough to search the skill registry (route_query), too ambiguous to describe at all (route_clarify), or contains multiple distinct intents (route_multi) — entirely before any information about NodeSpace's actual data model reaches the model. This causes it to over-clarify on words that are, in fact, unambiguous built-in or user-defined types.
Problem Statement
Captured directly from a live session (via the NODESPACE_PROMPT_DUMP mechanism added in #1956): the message "Could you tell me how many tasks we have here?" produced a route_clarify decision, asking the user to disambiguate between "count existing tasks" and "explain how task management works in general."
Tracing the exact Stage-1 prompt sent to the model (STAGE1_SYSTEM_PROMPT + the three route_* tool declarations in packages/agent/src/local_agent/routing.rs) shows it contains no information about NodeSpace's domain at all — no built-in type names (task, text, date), no user-defined entity types, no schema descriptions. The model has to guess, from English alone, whether "tasks" refers to something concrete in this system.
By contrast, Stage 2's system prompt (built in packages/agent/src/local_agent/agent_loop.rs, ~1180) already includes a RELEVANT ENTITY TYPES block populated by context_ops.rs's semantic schema retrieval (emb.semantic_search_nodes_of_type(query, "schema", MAX_SEMANTIC_SCHEMAS, SCHEMA_SIMILARITY_THRESHOLD)), which Stage 1 never sees because route() (line ~1096) runs before workspace_context is assembled (line ~1180) in the current turn sequence.
The result: a request Stage 2 could resolve trivially, because it already knows task is a real built-in type, gets an unnecessary clarification round-trip at Stage 1 because Stage 1 doesn't have that context yet.
Proposed Solution
Give Stage 1 a bounded signal about what NodeSpace actually knows about, without reintroducing the unbounded-registry-enumeration problem ADR-038 was built to avoid. Two complementary, low-risk additions:
- Built-in type names (
task,text,date, and any other hardcoded core types) — a small, fixed list, cheap to include directly inSTAGE1_SYSTEM_PROMPTor as adjacent context. This never grows unboundedly regardless of how many custom schemas a user defines. - Semantically-retrieved candidate schemas — reuse the existing
semantic_search_nodes_of_type(query, "schema", MAX_SEMANTIC_SCHEMAS, SCHEMA_SIMILARITY_THRESHOLD)call (already used for Stage 2'sRELEVANT ENTITY TYPESblock) with the raw user message as the query, run before or alongside Stage 1 instead of only afterward for Stage 2. Bounded by the sameMAX_SEMANTIC_SCHEMAS/SCHEMA_SIMILARITY_THRESHOLDconstants already governing Stage 2's retrieval, so this does not reopen the "enumerate the whole registry" problem — it is the same bounded, score-gated retrieval Stage 2 already performs, just also made available to Stage 1's decision.
This does not change ADR-038's core architecture (routing stays retrieval-based, not enumeration-based; the model still judges ambiguity itself rather than a rule-based gate) — it extends what Stage 1 is allowed to see before making that judgment, using retrieval machinery that already exists.
Architecture Impact
This extends, rather than reverses, ADR-038 (skill-mediated tool routing). ADR-038's Stage 1 is deliberately minimal today — no domain context, only the raw message and the three routing tool declarations — which was correct for avoiding unbounded registry enumeration, but as this issue's captured example shows, it also means Stage 1 cannot distinguish "genuinely ambiguous English" from "unambiguous NodeSpace vocabulary the model just hasn't been told about." The proposed fix reuses ADR-038's own retrieval-not-enumeration principle (bounded, score-gated semantic search) rather than abandoning it, so no companion ADR change is required unless the resulting design meaningfully changes Stage 1's contract (e.g. adds a new turn/latency cost worth documenting the way ADR-038 documented its own +12% wall-clock measurement).
(Note: ../decisions/018-two-stage-intent-classification.md also nominally covers "two-stage" routing but describes an entirely different, apparently-abandoned architecture — DistilBERT gatekeeper, Gemma 3, Turso/Text-to-SQL — that does not match the current Gemma-4/tool-call-based implementation this issue is about. It is not marked Superseded despite clearly not describing current behavior; flagging this as a documentation gap, but resolving it is out of scope for this issue.)
Acceptance Criteria
- Stage 1's prompt includes built-in type names (
task,text,date, etc.) so it can recognize them as known vocabulary rather than ambiguous English - Stage 1's prompt includes (or has access to) semantically-retrieved candidate schema names/descriptions for the user's message, reusing the existing
semantic_search_nodes_of_typeretrieval bound byMAX_SEMANTIC_SCHEMAS/SCHEMA_SIMILARITY_THRESHOLD - The "Could you tell me how many tasks we have here?" case (or an equivalent captured via
NODESPACE_PROMPT_DUMP/the agent-matrix eval) resolves viaroute_querywithout an unnecessaryroute_clarifyround-trip - Latency/turn-count cost of the added retrieval is measured and documented (per ADR-038's own precedent of measuring its extra-turn cost), since this issue proposes moving or duplicating a retrieval call earlier in the turn sequence
-
route_clarifystill fires correctly for requests that are genuinely ambiguous even with schema context (verify this isn't over-corrected into never clarifying) - Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
packages/agent/src/local_agent/routing.rs—stage1_tool_definitions(), the threeroute_*tool declarations Stage 1 is shownpackages/agent/src/local_agent/agent_loop.rs—STAGE1_SYSTEM_PROMPT(~line 58);route()(~line 2188, called at ~line 1096);workspace_contextassembly (~line 1180) that currently runs afterroute()and is Stage-2-onlypackages/core/src/ops/context_ops.rs— existing bounded semantic schema retrieval (~line 312-341):emb.semantic_search_nodes_of_type(query, "schema", MAX_SEMANTIC_SCHEMAS, SCHEMA_SIMILARITY_THRESHOLD),parse_and_filter_non_core_schemaspackages/nlp-engine/src/chat/prompt_dump.rs— the dump mechanism (added in Expose Gemma 4 12B as a selectable native model (once verified on adequate hardware) #1956) used to capture the exact Stage-1 prompt/response evidence cited above; setNODESPACE_PROMPT_DUMP=<path>to reproduce
Example Captured Evidence
Stage-1 raw response for "Could you tell me how many tasks we have here?" (captured via the prompt dump):
<|tool_call>call:route_clarify{options:[<|"|>Count the number of tasks in a specific list or project.<|"|>,<|"|>Provide information about task management capabilities (e.g., how to create/delete tasks).<|"|>],question:<|"|>Are you asking me to count existing tasks within this application, or are you looking for general information on how tasks work?<|"|>}<tool_call|>
Related Issues
- Expose Gemma 4 12B as a selectable native model (once verified on adequate hardware) #1956 (the session during which this was traced and discovered, using the
NODESPACE_PROMPT_DUMPmechanism added there; unrelated to that issue's actual scope — model picker changes)
Activity
Expose Gemma 4 26B-A4B as an optional model tier, park 12B, fix per-m…
mstomar125 commentedon Sep 12, 2026
Status-confirmation triage (2026-09-12): the technical claim in this issue is still accurate against current
main(0435c4d).STAGE1_SYSTEM_PROMPT(packages/agent/src/local_agent/agent_loop.rs:59-67) is unchanged — still no built-in type names or domain vocabulary, just the routing instructions.route()(agent_loop.rs:2928) builds its Stage-1 chat message fromstage1_query()(agent_loop.rs:782), which blends only prior-turn text + the current message viabuild_retrieval_query— no schema/entity signal enters it.session.dynamic_context(the schema/collection/playbook block Stage 2 uses) is populated once viaset_session_context()(agent_loop.rs:3521) after session creation, and is read atagent_loop.rs:1655— afterroute()is called atagent_loop.rs:1528. Stage 1 still runs with zero visibility into it.packages/core/src/ops/context_ops.rs's bounded semantic schema retrieval (semantic_search_nodes_of_type,MAX_SEMANTIC_SCHEMAS=5,SCHEMA_SIMILARITY_THRESHOLD=0.2) is unchanged and still only feeds Stage 2's candidate block, never Stage 1.No PR has touched this since filing (only related work found: #1981, unrelated model-tier changes). Line numbers have drifted slightly from the issue's own citations due to intervening commits, but the architecture described is unchanged. This remains a real, well-scoped enhancement — leaving open in Backlog, not implementing (routing-latency-sensitive change, needs its own measurement per the issue's own acceptance criteria).
malibio commentedon Oct 2, 2026
Baseline — Frontend: 309 test files passed, 5606 tests passed
Name the record types a request names to Stage-1 routing (closes #1980)
Name the record types a request names to Stage-1 routing (closes #1980)
Name the record types a request names to Stage-1 routing (closes #1980)