Repository navigation
Fix local agent document reading (get_node markdown, search_semantic, prompt tuning) - #1081
Conversation
…include_markdown, prompt tuning
## Bug Fixes
- Fix get_node format=markdown returning empty string — was parsing MCP wire
format (content[0].text) but handler returns plain {markdown: "..."} object
- Wire include_markdown and collection params through exec_search_semantic —
both were silently dropped, include_markdown always None despite ops layer
defaulting to 1
## Improvements
- search_semantic tool definition: add include_markdown and collection params
so model knows they exist and can use them
- search_semantic executor: surface markdown field from results when present
- Tool Strategy Guide prompt: explain result ordering (relevance), result
structure (id/title/score/snippet/markdown), and that top result markdown
is the full document — stop calling get_node unnecessarily
- Research & Search skill: add guidance prompt with explicit workflow,
result structure, and decision rules for when to stop vs. fetch more
- MAX_TOOL_ITERATIONS: 2 → 5 (2 was too low for search+fetch+respond)
- Skill max_iterations: Research & Search 2→4, others 2→3
Fixes root cause of issue #1060 follow-up: tool schema drift between MCP
handlers and agent tool executor caused silent failures. Also relates to
#1080 (skill node property normalization bug).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
malibio
left a comment
There was a problem hiding this comment.
Code Review Summary
This PR correctly diagnoses and fixes a chain of three silent failures that caused the local agent to loop on empty search results and hit the iteration limit. The root cause fixes in tools.rs are technically sound and confirmed against the actual handler return shapes. The iteration limit increase from 2→5 is well-reasoned. The prompt tuning addresses real gaps in model guidance.
One mismatch between the tool schema description and the actual ops layer default is flagged as an improvement, and the absence of tests for the two critical bug fixes is a gap that should be tracked.
Findings
Suggested Improvements
[Improvement] tools.rs lines 201–203: Tool schema advertises include_markdown default as 0, but the ops layer defaults to 1 when None is passed
The def_search_semantic() tool parameter description says:
"Number of top results to include full markdown content for (0-5, default 0)."
But exec_search_semantic passes params.include_markdown directly (which is None when the model omits it), and search_ops::search_semantic applies input.include_markdown.unwrap_or(1) — so the actual default is 1, not 0.
This creates a contradiction with the tool definition visible to the model. The prompt_assembler.rs prompt correctly states "includes full markdown content for the top result by default," but a model reading the tool schema directly (which LLMs do) sees "default 0." These should agree. The tool description should read (0-5, default 1) to match the actual behavior.
[Improvement] skill_pipeline.rs / agent_loop.rs: SkillMatch.max_iterations is extracted but never enforced by the loop
find_skill() reads max_iterations from the skill node's properties and stores it in SkillMatch, but agent_loop.rs ignores it — the for iteration in 0..MAX_TOOL_ITERATIONS loop always uses the global constant. The skill-specific max_iterations values (Research & Search: 4, others: 3) are persisted to the skill node via seed_skill_nodes() but have no runtime effect. This means the iteration limit bump in this PR effectively relies entirely on MAX_TOOL_ITERATIONS = 5, and the per-skill values are decorative.
This is pre-existing behavior, not introduced here, but this PR increases these values and adds a new guidance prompt tied to the assumption that the skill constraint is operative — worth flagging so the intent is clear.
[Improvement] No tests cover the two critical bug fixes
The PR description honestly acknowledges this gap. These bugs were silent failures — no panic, no error, just an empty string — which makes them particularly prone to regressing invisibly:
exec_get_nodewithformat=markdown: a unit test calling the executor with a mock handler returning{"markdown": "..."}(and separately{"content": [...]}to confirm the old shape fails) would pin the correct key path.exec_search_semanticwithinclude_markdown: a unit test asserting that whenparams.include_markdownisNone, the ops call receivesNone(preserving the ops-layer default of 1) and when set to2, it propagates through.
The test module already exists in tools.rs (line 1235). These cases can be added there. Tracking issues are already called out in the PR description, which is good.
Nitpicks
Nit: skill_pipeline.rs line 225 — guidance prompt says markdown is "only present for top result"
The ops layer supports include_markdown up to 5, and the tool schema now exposes this. The guidance says "only present for top result," which is accurate for the default call (include_markdown=1), but slightly misleading if a caller passes include_markdown=3. A more precise phrasing would be: "only present for results within the include_markdown count (default: top result only)." Minor, but guidance prompts are model-facing contract.
Nit: tools.rs line 189 — tool description says "By default returns IDs and snippets only"
This is also contradicted by the ops-layer default of include_markdown=1. The description would be more accurate as: "By default returns IDs, snippets, and full markdown for the top result."
Summary Verdict
Net positive — recommended for merge. The three bug fixes are correct, verified against the actual handler return shapes, and the behavioral improvement is confirmed by the live log evidence cited in the PR. The tool schema/default mismatch is a latent confusion risk for model reasoning and should be corrected in a follow-up (or in this PR if it can be done quickly). The missing tests should be added — the test infrastructure is already in place at line 1235 of tools.rs.
- Fix include_markdown default in search_semantic tool description: both the top-level description and parameter description now correctly say "default 1" to match the ops-layer unwrap_or(1) behavior - Wire skill_match.max_iterations into the agent loop: effective_max_ iterations is now derived from the matched skill (or falls back to MAX_TOOL_ITERATIONS when no skill is matched), so per-skill iteration caps (3, 4, etc.) are actually enforced - Update skill_pipeline.rs guidance prompt to say markdown is present for "top N results based on include_markdown" instead of "only present for top result", matching the current 0-5 range behavior Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review Follow-up: All Recommendations AddressedFixed (commit 37d482b)🟡 Important #1:
🟡 Important #2:
🟢 Nit #1: Misleading guidance prompt in
Deferred🟢 Nit #2: No tests for
|
… prompt tuning) (#1081) * Fix local agent document reading: get_node markdown, search_semantic include_markdown, prompt tuning ## Bug Fixes - Fix get_node format=markdown returning empty string — was parsing MCP wire format (content[0].text) but handler returns plain {markdown: "..."} object - Wire include_markdown and collection params through exec_search_semantic — both were silently dropped, include_markdown always None despite ops layer defaulting to 1 ## Improvements - search_semantic tool definition: add include_markdown and collection params so model knows they exist and can use them - search_semantic executor: surface markdown field from results when present - Tool Strategy Guide prompt: explain result ordering (relevance), result structure (id/title/score/snippet/markdown), and that top result markdown is the full document — stop calling get_node unnecessarily - Research & Search skill: add guidance prompt with explicit workflow, result structure, and decision rules for when to stop vs. fetch more - MAX_TOOL_ITERATIONS: 2 → 5 (2 was too low for search+fetch+respond) - Skill max_iterations: Research & Search 2→4, others 2→3 Fixes root cause of issue #1060 follow-up: tool schema drift between MCP handlers and agent tool executor caused silent failures. Also relates to #1080 (skill node property normalization bug). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review recommendations for PR #1081 - Fix include_markdown default in search_semantic tool description: both the top-level description and parameter description now correctly say "default 1" to match the ops-layer unwrap_or(1) behavior - Wire skill_match.max_iterations into the agent loop: effective_max_ iterations is now derived from the matched skill (or falls back to MAX_TOOL_ITERATIONS when no skill is matched), so per-skill iteration caps (3, 4, etc.) are actually enforced - Update skill_pipeline.rs guidance prompt to say markdown is present for "top N results based on include_markdown" instead of "only present for top result", matching the current 0-5 range behavior Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
Fixes the local agent's inability to read document content when asked questions about stored knowledge. Root cause was a chain of three issues discovered through live terminal log analysis.
Bug Fixes
1.
get_nodeformat=markdown always returned emptyexec_get_nodewas parsing the response as MCP wire format (content[0].text) buthandle_get_markdown_from_node_idreturns a plain object ({markdown: "..."}). Theunwrap_or("")fallback silently swallowed every result.2.
search_semanticinclude_markdownwas hardcoded toNoneThe ops layer defaults
include_markdownto 1 (return full markdown for top result), but the agent executor always passedNone, overriding it. The parameter also wasn't in the tool schema so the model couldn't request it.3. Prompt didn't explain search result structure
The Tool Strategy Guide told the model to call
get_nodeafter searching, even whensearch_semanticalready returned the full document. The model had no way to know the result contained amarkdownfield or that results were ordered by relevance.Improvements
search_semantictool definition: exposeinclude_markdownandcollectionparamsmarkdownfield = full documentMAX_TOOL_ITERATIONS: 2 → 5 (2 was insufficient for search+fetch+respond)max_iterations: Research & Search 2→4, others 2→3Result
Before: agent looped on empty
search_nodescalls, hit iteration limit, apologized.After: search → markdown in result → immediate substantive response. One tool call.
Related
max_iterationsDB update blocked)Test Plan
search_semanticreturnsmarkdownfield, model uses it directly,tool_calls=0on iteration 1exec_get_nodewithformat=markdownasserting non-empty responseexec_search_semanticassertinginclude_markdownis wired through