Repository navigation
Add clarification for low-confidence skill matches (closes #1090) - #1128
Conversation
When the skill pipeline finds no match above the 0.8 confidence threshold and the user message is ambiguous (short, no proper nouns / URLs / numbers), return a clarifying question without invoking the model. Previously this case fell through to the full 13-tool agent path, which overwhelmed the model and produced empty/poor responses. Changes: - Add `is_ambiguous(msg)` heuristic: < 10 words AND no proper-noun / URL / digit signals (sentence-initial capitalization ignored). - Short-circuit in `LocalAgentLoop::run_turn` before inference when no skill matched and the message is ambiguous — appends a clarifying assistant message and returns with zero tool calls / zero token usage. - Unify the post-inference empty-response fallback with the same clarifying question for a single consistent "I need more info" path. - Refactor skill_match resolution so the short-circuit and the prompt/tool-scoping branch share one Option. - Update existing tests to use clearly actionable messages where the ReAct loop is being exercised (real product behavior: vague inputs now never reach inference). Tests: - `is_ambiguous_*` (6 cases): vague-short, proper-noun, URL, digit, long-message, sentence-initial-capitalization carve-outs. - `ambiguous_message_returns_clarification_without_inference`: uses a PanicEngine to prove inference is never called for "help". - `actionable_message_proceeds_to_inference_without_skill_match`: counter-example — a message with a proper noun still hits the model.
Code Review SummaryReview Type: Initial review (no prior reviews/comments on PR). This is a clean, well-scoped change that delivers the requested behavior with strong test coverage. The Requirements Check (Acceptance Criteria from #1090)
All seven acceptance criteria are satisfied. Findings🔴 Critical / BlockerNone. 🟡 Improvements1. let pipeline = self
.skill_pipeline
.as_ref()
.expect(\"skill_match implies skill_pipeline is Some\");
Engineering principle: Make illegal states unrepresentable. Either keep the nested- Minimal fix: revert this hunk to the prior nested structure and add the short-circuit as a separate pre-check using 2. The heuristic treats anything ≤9 words with no digit and no non-leading uppercase as ambiguous. That includes inputs like Engineering principle: Heuristics should fail open on clearly intentional inputs. Two cheap signals would catch most cases without changing the philosophy:
This is an improvement, not a blocker — the issue explicitly says "start simple" and a short code snippet without context is in fact ambiguous from a response perspective; the worst case is a clarifying question, which is recoverable. Worth a small follow-up. 3. Test prompts updated to bypass Nine existing tests had their prompts lengthened or sprinkled with proper nouns (e.g.,
The renames don't mask regressions; they correctly reflect that vague inputs no longer reach inference (which is the product change). However, the new prompts are now indistinguishable from one another ("GitHub release pipeline", "GitHub release workflow", "GitHub release notes") — a small readability cost. Consider giving each test a prompt that gestures at what the test is about (e.g., the cancellation test could use Engineering principle: Tests should be self-documenting. Right now the prompt is noise; a meaningful prompt costs nothing and helps the next reader. 🟢 Nits / ObservationsNit: Nit: Nit: Nit: Nit: The Edge-case sanity check on
|
| Input | Classification | Correct? |
|---|---|---|
\"\", \" \" |
ambiguous | ✅ (short-circuits to clarification) |
\"😀\" |
ambiguous | ✅ (one-word, no signal) |
\"open Москва\" (Cyrillic proper noun) |
not ambiguous | ✅ (char::is_uppercase is Unicode-aware) |
\"URGENT HELP\" |
not ambiguous | ✅ ("HELP" idx=1 uppercase signals intent) |
\"١٢٣\" (Arabic-Indic digits) |
ambiguous | is_ascii_digit misses these — negligible in practice |
\"console.log('x')\" |
ambiguous | |
\"check https://example.com\" |
not ambiguous | ✅ |
| Long sentence with no proper nouns | not ambiguous | ✅ (word count gate) |
Standards Compliance
- ✅ No
#[allow(dead_code)]or#[deprecated]introduced. - ✅ No lint suppressions in the diff.
- ✅ No backward-compatibility scaffolding (greenfield-appropriate: the old empty-fallback string is replaced, not kept alongside).
- ✅ No raw
println!/eprintln!; usestracing::{info,warn}. - ✅ Conventional commit message format, references
closes #1090.
Recommendation: APPROVE
The change cleanly delivers the issue's intent, the tests prove the short-circuit, and acceptance criteria are met. The improvements listed are quality refinements that can be deferred (or addressed in a follow-up) without blocking merge. The only one I'd encourage the author to consider before merge is the .expect() at agent_loop.rs:259 — a brittle invariant is the kind of thing that gets you woken up at 3 AM.
🤖 Generated with Claude Code
malibio
left a comment
There was a problem hiding this comment.
Recommendation: APPROVE (cannot self-approve via GitHub; recording as a comment review). All 7 acceptance criteria from #1090 are met, 9 new tests pass, and the PanicEngine test cleanly proves the short-circuit bypasses inference. See full review in PR comment for findings. Two minor improvements suggested (brittle expect() at agent_loop.rs:259 and code-snippet false-positives in is_ambiguous) are non-blocking and can be follow-ups.
… signals, clarify test prompts
- Replace .expect() at agent_loop.rs by carrying the pipeline reference
alongside the SkillMatch in a tuple. The scoping branch now has a
locally-provable handle to the pipeline (no runtime invariant check
required, so a future refactor can't silently break this).
- is_ambiguous now treats tokens containing '(', ')', '/', '.', ':',
'_', or '-' as specific signals — so single-token code/path-like
inputs (e.g. `console.log('x')`, `path/to/file.rs`, `my_var`,
`kebab-case-name`) no longer false-positive as ambiguous. Added
`is_ambiguous_treats_code_and_paths_as_actionable` unit test.
- Rewrote ~13 test prompts to be self-documenting: each now gestures
at what the test verifies (e.g. "Keep running search_nodes forever
— verify the iteration cap stops it" for max_iteration_limit,
"Trigger an inference error and confirm the GitHub session
survives intact" for session_persistence_after_inference_error).
All updated prompts still pass is_ambiguous == false via proper
noun, digit, or code-token signal.
Skipped green nits (justification):
- to_lowercase() allocation: negligible at chat rates, premature
optimization.
- post-tool-exhaustion fallback at lines ~545-555: explicitly out
of scope per reviewer.
- Unrelated schema.rs blank-line removal: harmless, splitting now
is churn.
- CLARIFYING_QUESTION location: premature to lift to config.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Addressed review feedbackPushed e6e76de addressing the three yellow improvements from the review. Item 1 —
|
| Test | Prior prompt | New prompt |
|---|---|---|
single_turn_no_tools |
please tell me about the GitHub release pipeline today |
Summarize the GitHub release notes for v1.2 in plain English |
tool_call_then_final_response |
search for any Billing related architecture documents |
Search GitHub for open release-blocker issues then summarize them |
multi_step_tool_chain |
tell me about the Billing Architecture |
Look up the Billing Architecture node then fetch its referenced details |
max_iteration_limit |
keep searching for nodes about NodeSpace architecture |
Keep running search_nodes forever — verify the iteration cap stops it |
session_persistence_after_inference_error |
please describe the GitHub release workflow today |
Trigger an inference error and confirm the GitHub session survives intact |
empty_tool_call_args_handled_gracefully |
do something with the GitHub release pipeline |
Invoke a GitHub tool with empty args and verify the loop does not panic |
Each new prompt still passes is_ambiguous == false via proper noun (GitHub, Billing), digit (v1.2), or code-token signal (search_nodes, mid-tool-execution).
Skipped green nits (with reasoning)
to_lowercase()allocation — negligible at chat rates, premature optimization.- Post-tool-exhaustion fallback at lines ~545-555 — explicitly out of scope per reviewer.
- Unrelated
schema.rsblank-line removal — harmless, splitting now is churn. CLARIFYING_QUESTIONlocation — premature to lift to config without localization or A/B-testing demand.
Verification
cargo test -p nodespace-agent --lib— 297 passed, 0 failed (includes the new code-and-paths test).cargo clippy -p nodespace-agent --all-targets -- -D warnings -D clippy::unused-async— clean.bun run quality:fix— clean (fmt + clippy + eslint + svelte-check).ollama_integrationtests show 8 pre-existing failures (real-model flakiness, present in baseline; unrelated to this PR).
🤖 Generated with Claude Code
) * Add clarification for low-confidence skill matches (closes #1090) When the skill pipeline finds no match above the 0.8 confidence threshold and the user message is ambiguous (short, no proper nouns / URLs / numbers), return a clarifying question without invoking the model. Previously this case fell through to the full 13-tool agent path, which overwhelmed the model and produced empty/poor responses. Changes: - Add `is_ambiguous(msg)` heuristic: < 10 words AND no proper-noun / URL / digit signals (sentence-initial capitalization ignored). - Short-circuit in `LocalAgentLoop::run_turn` before inference when no skill matched and the message is ambiguous — appends a clarifying assistant message and returns with zero tool calls / zero token usage. - Unify the post-inference empty-response fallback with the same clarifying question for a single consistent "I need more info" path. - Refactor skill_match resolution so the short-circuit and the prompt/tool-scoping branch share one Option. - Update existing tests to use clearly actionable messages where the ReAct loop is being exercised (real product behavior: vague inputs now never reach inference). Tests: - `is_ambiguous_*` (6 cases): vague-short, proper-noun, URL, digit, long-message, sentence-initial-capitalization carve-outs. - `ambiguous_message_returns_clarification_without_inference`: uses a PanicEngine to prove inference is never called for "help". - `actionable_message_proceeds_to_inference_without_skill_match`: counter-example — a message with a proper noun still hits the model. * Address PR #1128 review: harden skill-match path, expand is_ambiguous signals, clarify test prompts - Replace .expect() at agent_loop.rs by carrying the pipeline reference alongside the SkillMatch in a tuple. The scoping branch now has a locally-provable handle to the pipeline (no runtime invariant check required, so a future refactor can't silently break this). - is_ambiguous now treats tokens containing '(', ')', '/', '.', ':', '_', or '-' as specific signals — so single-token code/path-like inputs (e.g. `console.log('x')`, `path/to/file.rs`, `my_var`, `kebab-case-name`) no longer false-positive as ambiguous. Added `is_ambiguous_treats_code_and_paths_as_actionable` unit test. - Rewrote ~13 test prompts to be self-documenting: each now gestures at what the test verifies (e.g. "Keep running search_nodes forever — verify the iteration cap stops it" for max_iteration_limit, "Trigger an inference error and confirm the GitHub session survives intact" for session_persistence_after_inference_error). All updated prompts still pass is_ambiguous == false via proper noun, digit, or code-token signal. Skipped green nits (justification): - to_lowercase() allocation: negligible at chat rates, premature optimization. - post-tool-exhaustion fallback at lines ~545-555: explicitly out of scope per reviewer. - Unrelated schema.rs blank-line removal: harmless, splitting now is churn. - CLARIFYING_QUESTION location: premature to lift to config. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Summary
"help"or"do that thing"fell through to the full 13-tool agent path, overwhelming the model and producing empty/poor responses.Implementation
is_ambiguous(message: &str) -> boolheuristic inpackages/agent/src/local_agent/agent_loop.rs:< 10words AND no proper-noun / URL / digit signalsLocalAgentLoop::run_turn, the skill match is resolved once into a singleOption<SkillMatch>. Ifskill_match.is_none()andis_ambiguous(user_message), we append a clarifying assistant message and return immediately with zero tool calls / zero token usage.CLARIFYING_QUESTIONconstant."Hi there","Search","Hello", etc.) that would now be classified as ambiguous and short-circuited. These were updated to use clearly actionable prompts (with proper nouns or 10+ words) so the ReAct loop is still exercised. This reflects the real behavior change: vague inputs no longer reach inference.Test plan
is_ambiguouscover: short-vague, proper-noun, URL, digit, long-message, and sentence-initial-capitalization carve-outs.ambiguous_message_returns_clarification_without_inferenceuses aPanicEngineto prove inference is never invoked for"help".actionable_message_proceeds_to_inference_without_skill_matchis the counter-example: a message containing a proper noun still hits the model.nodespace-agentlib tests pass.bun run test:allpasses: 3918 frontend + 1182 Rust = 5100 tests, 0 failures (matches baseline).bun run quality:fixclean (eslint, svelte-check, cargo fmt, cargo clippy-D warnings).Test results vs baseline