Repository navigation
Description
Revised per ADR-036 and senior-architect review. The original framing (mandatory
search_skillsgate, "empty skill descriptions", skill-to-skill references, gate-all-tools) is superseded: skill descriptions are NOT empty (that was a query bug); the routing is LLM-judged retrieval, not a hard system gate; the instruction-delivery data fix is split to #1356.
Overview
Implement the routing pipeline from ADR-036: the model reaches capabilities through skills discovered by semantic retrieval over the registry, with the LLM as judge at two gates and a clarification fallback when confidence is low. Retrieval is a deterministic system step (not a model tool-call) — that is where the candidate set is bounded and the external-tool trust boundary is enforced.
This replaces ADR-030's silent push pipeline (select_tools) and its pattern-match + fixed-cosine routing.
Canonical flow (2 model turns happy-path, 3 only on clarify)
Turn 1 (model): read message (+ relevant prior turns)
→ emit EITHER a search query OR a clarification request
(a STRUCTURAL choice, not a self-reported confidence number)
[system step]: semantic retrieval over the registry → top-K, score-gated,
trust-filtered. NOT a model tool-call.
Turn 2 (model): judge top-K candidates (each WITH full instructions, #1356)
→ pick one + emit the typed action call in the same turn
→ OR clarify, offering the candidates as concrete options
[execute]: deterministic handler runs.
Two independently-sourced gates
- Stage-1 gate = the model's structural choice (query vs clarify) — NOT a numeric self-rating (small models are overconfident; two numeric self-reports are not independent).
- Stage-2 gate = retrieval score (mechanical) AND the model's yes/no on the candidate (judged, re-checked against message + prior context).
Clarification contract
- At most one clarification per intent; if still unresolved, fall through to the general
semantic_searchskill and answer with what's available. Never clarify twice. - Clarification is specific — surfaces the concrete candidate(s): "Did you want to track who owes you money (set up an invoice/receivable type), or search existing notes?"
- Many intents legitimately resolve to a general search skill (normal, not a failure).
Blast-radius-aware gate
The Stage-2 bar is a property of the matched skill, not a global constant. Mutating skills (schema creation, deletion) require a higher bar than read-only skills, because firing the wrong mutating tool changes the graph.
Remove the silent push path
- Remove
select_tools' silent pre-inference tool-scoping (tools.rs:1530). A degraded fallback (full tool list when no embedding service is available,:1538) MAY be retained, but silent injection is replaced by the model-judged flow.
Acceptance Criteria
- Turn 1 emits a structural
{search_query | clarify}choice (not a confidence number). - Retrieval runs as a deterministic system step returning a bounded, score-gated, trust-filtered top-K.
- Turn 2 judges candidates (with instructions from find_skills/search_skills returns each matched skill's full instruction subtree, not just its description #1356) and either acts (typed call) or clarifies with concrete options.
- Clarification is bounded to one round, then falls through to general search.
- Mutating skills use a higher Stage-2 bar than read-only skills.
- Silent
select_toolsinjection removed (degraded fallback decision documented). - Happy path is 2 model turns; clarification adds at most one.
- Routing eval fixtures (Routing eval harness: repeatable fixtures for skill-discovery accuracy (indirect phrasing, clarification, mis-route) #1357) pass against the upgraded engine.
-
architecture/prompt-skill-system.mdrewritten to describe the shipped routing (replacing the ADR-030 push description currently banner-flagged as superseded). - Code passes
bun run quality:fix; tests pass.
Technical Specifications
Reference Files
packages/core/src/ops/skill_ops.rs—find_skills(retrieval + score); deliberate0.0long-tail threshold.packages/agent/src/local_agent/tools.rs—select_tools(:1530, remove silent injection;0.3floor:1522),exec_search_skills.packages/agent/src/local_agent/agent_loop.rs— turn loop (intent → retrieval → judge/act).../nodespace-docs/decisions/036-skill-mediated-tool-routing.md— the decision.../nodespace-docs/architecture/prompt-skill-system.md— rewrite target.
Dependencies
- llama.cpp upgrade issue (gates this — design validated on the upgraded engine)
- find_skills/search_skills returns each matched skill's full instruction subtree, not just its description #1356 (find_skills returns instruction subtree — Stage-2 needs it)
Related Issues
- ADR-036 (the decision)
- Tools as nodes: deterministic-handler bridge with TYPED tools generated from nodes (no universal invoker), plus external-tool trust boundary #1353 (tools as nodes / typed tools — the action surface this routes to)
- Routing eval harness: repeatable fixtures for skill-discovery accuracy (indirect phrasing, clarification, mis-route) #1357 (routing eval harness — the regression guard)
- Store schema descriptions as a node subtree (markdown) instead of properties.description, and embed them for semantic schema discovery #1351 (schema description subtree — feeds schema_metadata)
Non-Goals
- Universal
invoke_tool(rejected by ADR-036 / Tools as nodes: deterministic-handler bridge with TYPED tools generated from nodes (no universal invoker), plus external-tool trust boundary #1353 — tools stay typed). - Grammar-constrained decoding.
Activity
malibio commentedon Jun 6, 2026
Depends on #1353 (tools as nodes)
The "gate tools behind skills" and "skill → tool reference" parts of this issue depend on tools existing as nodes. #1353 promotes each tool to a
node_type='tool'node with a stable handler key and flat parameter schema, invoked via a universalinvoke_tool(tool_id, args), and is the deterministic-execution bridge below skills.With #1353 in place:
[create_schema](nodespace://<tool-uuid>).tool_whitelistholds tool node IDs.search_skills(discover) +invoke_tool(act), with all specific tools reached as nodes through the matched skill.Architecture stack: user intent → skill (instructions) → tool node (bridge) → deterministic handler.
[-]Skills as the universal entry point for agent actions: deliver instruction subtree, embed description, gate tools behind skills, allow skill-to-skill references[/-][+]Skill-mediated tool routing: LLM-judged two-stage retrieval pipeline with clarification fallback[/+]malibio commentedon Jun 6, 2026
Frontend: 134 passed (3844 tests)
Skill-mediated tool routing: LLM-judged two-stage retrieval pipeline (c…
Skill-mediated tool routing: LLM-judged two-stage retrieval pipeline (c…