Skip to content

Skill-mediated tool routing: LLM-judged two-stage retrieval pipeline with clarification fallback #1352

Closed

Description

@malibio

Revised per ADR-036 and senior-architect review. The original framing (mandatory search_skills gate, "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_search skill 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

Technical Specifications

Reference Files

  • packages/core/src/ops/skill_ops.rs — find_skills (retrieval + score); deliberate 0.0 long-tail threshold.
  • packages/agent/src/local_agent/tools.rs — select_tools (:1530, remove silent injection; 0.3 floor :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

Related Issues

Non-Goals

Activity

  1. malibio commented on Jun 6, 2026

    @malibio
    CollaboratorAuthor

    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 universal invoke_tool(tool_id, args), and is the deterministic-execution bridge below skills.

    With #1353 in place:

    • A skill references a tool via the same node-mention syntax it uses to reference other skills: [create_schema](nodespace://<tool-uuid>).
    • A skill's tool_whitelist holds tool node IDs.
    • The model's tool surface collapses to 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.

  2. changed the title [-]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[/+] on Jun 6, 2026
  3. malibio commented on Jun 6, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 134 passed (3844 tests)

  4. self-assigned this
    on Jun 6, 2026
  5. added a commit that references this issue on Jun 6, 2026
    9c4c704
  6. added a commit that references this issue on Jun 22, 2026
    e9142ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions