Repository navigation
Description
Overview
Today the agent uses a pre-LLM router: the skill pipeline runs semantic search before any model call, picks a single skill, and the LLM is invoked with only that skill's scoped tools/prompt. The model never sees the menu of skills — it's handed one. When no skill scores above the confidence threshold, the agent falls through to the full 13-tool path (or, after #1090, returns a hardcoded clarifying question based on a word-count heuristic).
This proposal flips the control: expose a search_skills(query) tool to the LLM and let the model decide when to search, judge the results, and either invoke a skill or ask for clarification using real context about what it searched and found.
Problem Statement
The pre-LLM router has fundamental limitations that heuristics can only paper over:
-
User-corpus-agnostic routing is impossible. A query like "what's the capital of France?" might score 0.9 against one user's history-of-countries notes and 0.05 against another user's task list. The same query is in-scope or out-of-scope depending on what's stored. Hardcoded confidence floors can't capture this.
-
Ambiguity heuristics are brittle. Ask for clarification when skill confidence is below threshold instead of falling through to full tool set #1090 added an
is_ambiguousfunction (word count + proper-noun / URL / digit / code-token detection) to decide when to short-circuit. This is a patch on a fundamentally limited design — the router has no judgment, so we keep bolting on rules to approximate one. -
Multi-skill turns are impossible. Pre-routing picks one skill per turn. A request like "find my Q2 budget notes and create a task to review them" requires two skills and can't be expressed.
-
Hidden routing produces opaque failures. When the router picks the wrong skill or finds nothing, the user gets either a wrong answer or a generic clarification with no context about what was searched. The model could ask a much better question if it knew what it didn't find.
-
The schema list is decorative. The LLM already receives the schema list as context but doesn't use it for routing decisions — that work happens before the model is invoked.
Proposed Solution
Expose the existing skill pipeline as a tool the LLM calls itself.
New flow
- LLM receives the system prompt + schema list + a
search_skills(query)tool - User sends a message
- LLM decides whether a skill is needed
- If yes, LLM calls
search_skillswith its own query (which may differ from the raw user message) - Pipeline returns top matches with scores and metadata
- LLM judges the results and either:
- Invokes the matched skill with appropriate arguments
- Asks the user for clarification, citing what it searched and didn't find
- Responds directly (for conversational/social turns)
- For multi-skill turns, the model can call
search_skillsrepeatedly and chain skill invocations
What gets deleted
is_ambiguousheuristic and its tests inpackages/agent/src/local_agent/agent_loop.rs- Pre-LLM dispatch path in
agent_loop.rs(run_turnshort-circuit + pipeline-scoped prompt branch) - The
CLARIFYING_QUESTIONconstant and the hardcoded fallback paths that reference it (model will produce its own clarifications) - Test infrastructure that mocked the skill router separately from the LLM
What gets kept
SkillPipelineitself (semantic search + scoring) — becomes the implementation ofsearch_skillsSkillMatchstruct and scoring logic- Skill definitions, schemas, and registration
Acceptance Criteria
-
search_skills(query: String)tool registered and exposed to the LLM in every turn - Tool returns a structured response (top-N matches with skill name, confidence, description, and any metadata the model needs to decide)
- LLM can invoke a matched skill via normal tool calling after a
search_skillsresult - LLM can ask for clarification with context when search returns nothing useful (no hardcoded
CLARIFYING_QUESTIONstring) - Multi-skill turns work end-to-end (model calls
search_skillsmore than once in a turn, chains skill invocations) - Pre-LLM routing path removed from
run_turn(no moreis_ambiguous, no skill-scoped prompt branch) - Test suite covers: confident match → skill invoked; no relevant skill → model asks for clarification; off-corpus query → model judges and responds appropriately; multi-skill turn → both skills invoked
- Latency measured on a local 7B-class model and documented in PR (rough floor: how many extra ms per turn vs the current router)
- Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Reference Files
- Agent loop:
packages/agent/src/local_agent/agent_loop.rs—run_turnis where the pre-LLM dispatch lives today; thesearch_skillstool gets registered here and the short-circuit / scoped-prompt branches get removed - Skill pipeline:
packages/agent/src/skill_pipeline.rs—SkillPipeline::search(or equivalent) becomes the implementation backing the new tool;SkillMatchis the natural return shape - Tool registration: wherever the 13 core tools are assembled for the LLM (in
agent_loop.rsor an adjacent module) —search_skillsis added to that set
Implementation Details
Tool signature (proposed):
// Tool exposed to the LLM
fn search_skills(query: String, limit: Option<usize>) -> SearchSkillsResponse;
struct SearchSkillsResponse {
matches: Vec<SkillMatchSummary>, // top-N, sorted by confidence
}
struct SkillMatchSummary {
name: String,
confidence: f32,
description: String,
// any other fields the model needs to judge relevance
}The tool should always return — even an empty matches array is a useful signal. Let the model judge "low confidence" instead of filtering server-side.
Removing the pre-LLM path:
The current run_turn resolves Option<(&Arc<SkillPipeline>, SkillMatch)> before inference and branches on it. Replace with a single inference path that always exposes the full tool set including search_skills. The skill-scoped prompt variant goes away — there's only one prompt path now.
Conversation flow for clarification:
When the model decides nothing relevant exists, it produces a natural-language response that references what it searched. No CLARIFYING_QUESTION constant, no fallback string. If the model returns empty text, that's an inference bug, not a routing decision — handle it as an error, not a UX surface.
Open Questions
These should be resolved in implementation, documented in the PR:
- Latency cost on local models. Every turn now pays one inference to decide whether to search. On a local 7B-class model this is probably 1–3 seconds added per interaction. Worth measuring before committing; if it's prohibitive, consider a fast-path for messages that obviously don't need a skill (greetings, etc.) — but only if measurement justifies it.
search_skillsresult shape. How much metadata does the model need per match? Description, schema hints, example invocations? Start minimal and expand based on actual model behavior.- Confidence in the response. Today's threshold is 0.8. The new design shows confidence to the model; should the model see raw scores, qualitative buckets (high/medium/low), or both? Start with raw scores and observe.
- Skill argument inference. Today the router hands a matched skill to the model with a pre-built prompt. In the new design the model invokes the skill itself — does it need argument schemas surfaced via the schema list, or via the
search_skillsresponse?
Non-Goals
- Replacing the skill pipeline's semantic search implementation (only its position in the control flow changes)
- Changing skill definitions or schemas
- Adding multi-turn clarification state tracking
- Tuning model prompts beyond what's needed to make
search_skillsdiscoverable
Related Issues
- Ask for clarification when skill confidence is below threshold instead of falling through to full tool set #1090 (predecessor — added `is_ambiguous` heuristic that this issue makes obsolete)
- Unify agent guidance rules into a single source for local agent and gRPC tool layer #1089 (related agent-prompt unification work)
Activity
malibio commentedon May 18, 2026
Baseline: 3918 tests passed (128 files). Working in worktree on branch worktree-issue-1130-llm-skill-search.
Replace pre-LLM skill routing with LLM-orchestrated search_skills tool (
Replace pre-LLM skill routing with LLM-orchestrated search_skills (cl…
Replace pre-LLM skill routing with LLM-orchestrated search_skills (cl…