Skip to content

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

Merged
malibio merged 1 commit into
mainfrom
worktree-issue-1352-skill-mediated-routing
Jun 6, 2026
Merged

malibio merged 1 commit into
mainfrom
worktree-issue-1352-skill-mediated-routing

Conversation

@malibio

@malibio malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #1352

…loses #1352)

Replace the silent select_tools push path with the ADR-036 pull model:
the model receives all tools and calls search_skills itself (Stage-1 gate),
then judges candidates and emits the typed action in the same turn or clarifies.

- Remove select_tools from AgentToolExecutor trait and GraphToolExecutor impl.
  The silent pre-inference skill search (SELECT_TOOLS_CONFIDENCE_THRESHOLD = 0.3)
  that scoped the tool list before the model saw anything is gone.
- Remove is_baseline() from Tool — it existed only to seed select_tools baselines.
- agent_loop.rs: pass the full tool list directly; no pre-filtering step.
  Degraded path: search_skills returns an error result when the embedding service
  is unavailable and the model falls through to general tools.
- Update search_skills description to describe the ADR-036 two-gate flow:
  model judges candidates and emits the action in the same turn, or clarifies
  with concrete candidates. Empty result = fall through to general tools.
- TOOL_STRATEGY_RULES: add CLARIFICATION CONTRACT (one clarification max, then
  fall through to semantic_search) and BLAST-RADIUS GATE (mutating skills require
  higher confidence than read-only skills).
- Update prompt_assembler.rs snapshot test to match new TOOL_STRATEGY_RULES body.

Happy path: 2 model turns. Clarification: 3 turns max. No silent injection.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1363: Skill-Mediated Tool Routing (ADR-036)

Reviewer: Principal Engineer (automated pragmatic review)
Date: 2026-06-06
Verdict: APPROVED — this is a clean, well-scoped architectural replacement. All findings below are improvements or nits; none are blockers.


Overall Assessment

This PR correctly replaces the ADR-030 silent-push pipeline (select_tools) with the ADR-036 pull model in a single, cohesive commit. The mechanical changes are minimal and precise: remove one trait method, remove one helper function, remove one constant, update prompt text and its snapshot test, update the tool description. The deleted code accounts for the vast majority of the diff and leaves no dead code behind. Both dependency issues (#1356, #1357) are confirmed closed. All 241 Rust agent tests pass; all 3,844 frontend tests pass. Clippy is clean.


Requirements Validation (Issue #1352 Acceptance Criteria)

Criterion Status
Turn 1 emits a structural {search_skills call | conversational reply} choice Met — the model receives the full tool list including search_skills and calls it itself. The TOOL_STRATEGY_RULES prompt removes the old not even search_skills carve-out, allowing search_skills as the structural action on non-conversational turns.
Retrieval runs as a deterministic system step (bounded, score-gated, top-K) Met — find_skills / exec_search_skills is unchanged and correct. SKILL_SEARCH_THRESHOLD = 0.0 with MAX_SKILL_LIMIT = 10 provides the bounding.
Turn 2 judges candidates and either acts or clarifies with concrete options Met — communicated through the updated def_search_skills() tool description and the CLARIFICATION CONTRACT prompt rule.
Clarification bounded to one round, then falls through to semantic_search Met — CLARIFICATION CONTRACT in TOOL_STRATEGY_RULES.
Mutating skills use a higher Stage-2 bar Met — BLAST-RADIUS GATE in TOOL_STRATEGY_RULES.
Silent select_tools injection removed Met — select_tools deleted from AgentToolExecutor trait, GraphToolExecutor impl, and agent_loop.rs. Degraded path (no embedding service → search_skills returns an error result, model falls through) is documented.
Happy path is 2 model turns; clarification adds at most one Met — the ReAct loop structure unchanged; prompt now instructs search_skills + action in the same turn.
Routing eval fixtures (#1357) pass Met — issue #1357 is closed.
architecture/prompt-skill-system.md rewritten to describe the shipped routing Met — the nodespace-docs repo contains a full rewrite (ADR-030 push pipeline removed, ADR-036 pull model documented with canonical flow, two gates, clarification contract, blast-radius gate, degraded path).
Code passes bun run quality:fix; tests pass Met — Clippy clean, 241 Rust + 3,844 TS tests all green.

Findings

Suggested Improvements

packages/daemon/src/services/local_agent_service.rs line 144 — stale comment

The comment on line 144 still references select_tools by name:

// skill-based select_tools work as soon as the embedding model finishes

This is the only remaining reference to select_tools in the entire codebase and it is misleading post-this-PR. The concept it describes (embedding service availability affecting skill search) is still valid, but the phrasing should be updated to reflect the pull model:

// skill-based search_skills works as soon as the embedding model finishes

Not a blocker — the code is correct — but leaving a reference to the deleted mechanism is the kind of drift that confuses future readers.

Trust filtering gap (acknowledged by ADR-036 as future work, noting for completeness)

ADR-036 §Trust Boundary explicitly designates the system step retrieval as "where the trust boundary is enforced" — including filtering on the source marker (internal vs. external) and enabled flag before skills enter the candidate set. The current find_skills implementation in skill_ops.rs does not yet apply this filter: it returns all skill nodes with positive cosine similarity regardless of source or enabled status. The trust boundary IS implemented for tools in available_tools() (lines 1562–1573 in tools.rs), but not mirrored in the skill retrieval path. Given the current state of the system (no external skills registered, no MCP integration surface yet open), this is not an active security concern. The ADR lists it as issue 5 in the implementation order, after typed-tool generation. Flagging here so it is not forgotten when external skill registration lands.

Nitpicks

Nit: packages/agent/src/agent_guidance.rs — the BLAST-RADIUS GATE rule is LLM-instructable but not mechanically enforced

The rule correctly communicates the desired behavior to the model. Since the issue explicitly rejects encoding the bar as a single self-reported scalar (small models are overconfident), this is the right approach for now. Worth a brief inline comment noting this is a prompt-level instruction until per-skill metadata is used to enforce the bar mechanically at the retrieval step (tracked in ADR-036).

Nit: packages/agent/src/local_agent/tools.rs — search_skills description says "tools, and instructions" but does not show the full field list

The old description listed "name, description, confidence (0-1), and tools." The new one adds "instructions" but omits schema_metadata. This is minor since schema_metadata is self-describing when it appears in the response, but for completeness the field inventory in the description could match the actual JSON shape.


Notes

  • The deletion of Tool::is_baseline() and the SELECT_TOOLS_CONFIDENCE_THRESHOLD constant are correct per CLAUDE.md's no-deprecated-code, no-dead-code directive.
  • The snapshot test update in prompt_assembler.rs correctly reflects the new TOOL_STRATEGY_RULES bytes and prevents silent prompt drift.
  • The run_turn_calls_select_tools_on_executor test deletion is appropriate: the behavior it guarded no longer exists. The new model_calls_search_skills_then_invokes_matched_skill and empty_search_skills_matches_let_model_clarify_with_context tests cover the replacement flow.
  • The approach of communicating the clarification contract and blast-radius gate via prompt instructions (rather than hard-wired code logic) is consistent with the overall architecture and appropriate for this stage.

@malibio
malibio merged commit 9c4c704 into main Jun 6, 2026
@malibio
malibio deleted the worktree-issue-1352-skill-mediated-routing branch June 6, 2026 18:43
malibio added a commit that referenced this pull request Jun 6, 2026
Updates a comment in local_agent_service.rs that still referenced
the deleted select_tools path. The executor now routes through
search_skills (the model-driven pull path per ADR-036), not the
old silent push method.

Addresses reviewer suggestion from PR #1363.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

Address-Review Summary

Addressed: 1 recommendation
Skipped: 1 recommendation (with justification)

✅ Fixed: Stale comment in local_agent_service.rs

Updated the comment at line 144 that still referenced select_tools. Now correctly references search_skills to match the ADR-036 pull model. Committed directly to main (trivial one-line doc change, no logic involved).

⏭️ Skipped: Trust boundary gap in find_skills for external skills

Rationale: This gap is explicitly scoped to a future implementation step in ADR-036 (implementation item 5: "Tools as nodes + typed-tool generation + schema validation/trust boundary"). No external skills can currently be registered, so there is no active security surface to close. The fix belongs with the external skill registration feature (#1353), not as a retrofit here. Tracked via the ADR-036 implementation notes.


Re-Review Decision: NO RE-REVIEW NEEDED — both changes are either trivially correct (one-line comment) or intentionally deferred with documented rationale.

malibio added a commit that referenced this pull request Jun 22, 2026
…loses #1352) (#1363)

Replace the silent select_tools push path with the ADR-036 pull model:
the model receives all tools and calls search_skills itself (Stage-1 gate),
then judges candidates and emits the typed action in the same turn or clarifies.

- Remove select_tools from AgentToolExecutor trait and GraphToolExecutor impl.
  The silent pre-inference skill search (SELECT_TOOLS_CONFIDENCE_THRESHOLD = 0.3)
  that scoped the tool list before the model saw anything is gone.
- Remove is_baseline() from Tool — it existed only to seed select_tools baselines.
- agent_loop.rs: pass the full tool list directly; no pre-filtering step.
  Degraded path: search_skills returns an error result when the embedding service
  is unavailable and the model falls through to general tools.
- Update search_skills description to describe the ADR-036 two-gate flow:
  model judges candidates and emits the action in the same turn, or clarifies
  with concrete candidates. Empty result = fall through to general tools.
- TOOL_STRATEGY_RULES: add CLARIFICATION CONTRACT (one clarification max, then
  fall through to semantic_search) and BLAST-RADIUS GATE (mutating skills require
  higher confidence than read-only skills).
- Update prompt_assembler.rs snapshot test to match new TOOL_STRATEGY_RULES body.

Happy path: 2 model turns. Clarification: 3 turns max. No silent injection.

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Jun 22, 2026
Updates a comment in local_agent_service.rs that still referenced
the deleted select_tools path. The executor now routes through
search_skills (the model-driven pull path per ADR-036), not the
old silent push method.

Addresses reviewer suggestion from PR #1363.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant