You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: structured delegate response with searches tracking and relevance filtering
- Search delegate now returns structured JSON with confidence, groups, and
a new `searches` field listing all queries made (with path and outcome).
This lets the parent AI see what was attempted and retry different terms.
- Delegate prompt emphasizes relevance filtering: only include files
verified by extract, not keyword matches. Fewer verified files > many
unverified matches.
- Code-searcher subagent iteration limit handling: when hitting maxIterations,
the last-iteration prompt tells the subagent to output structured JSON with
partial results (not a text error). Post-loop fallback also produces
structured JSON with search history for code-searcher agents.
- Separate searchDelegateSchema (query + path only) for delegate mode,
preventing the parent from passing keyword-specific params like exact/language.
- Delegate-level dedup prevents re-spawning expensive subagents for the same
normalized concept.
- System prompts updated: search delegate returns file locations (not extracted
code blocks), parent must use extract() to read code.
- Delegate span enrichment: logs truncated response on success spans.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: restructure search delegate prompt with XML tags
Reorganize the delegate subagent prompt into clear XML sections:
<role>, <task>, <tools>, <search-engine-behavior>, <strategy>,
<relevance-filtering>, <stop-conditions>, <on-iteration-limit>,
<output-format>, and <output-guidelines> with <field> elements.
Makes the prompt easier to parse for both humans and LLMs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: LLM-based semantic dedup, shared provider utility, delegate improvements
- Add LLM-based semantic dedup for delegate queries (checkDelegateDedup)
using generateText to detect redundant searches across all paths
- Create shared utils/provider.js with createProviderInstance(),
resolveApiKey(), createLanguageModel(), and DEFAULT_MODELS
- Refactor FallbackManager and ProbeAgent to use shared provider utility,
eliminating duplicated SDK imports and provider creation logic
- Add 'reason' field to structured delegate response schema
- Remove redundant <output-format> and <output-guidelines> from delegate
prompt, replace with concise <output-rules>
- Add OTEL tracing for dedup decisions (search.delegate.dedup spans)
- Fix dedup model creation: fall back to FORCE_PROVIDER env var and
DEFAULT_MODELS when options.provider/model unavailable at init time
- Return NOT FOUND verdict when delegate reports low confidence with
empty groups instead of falling back to raw search
- Add parent prompt guidance to prevent re-searching same concepts
- Add 'reason' to iteration-limit fallback response
- Add tests for filler prefix stripping in normalizeQueryConcept
- Add tests for reason field in structured delegate response
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
// Add high-level instructions about when to use tools
3014
2979
constsearchToolDesc1=this.searchDelegate
3015
-
? '- search: Ask natural language questions to find code (e.g., "How does authentication work?"). A subagent handles keyword searches and returns extracted code blocks. Do NOT formulate keyword queries — just ask questions.'
2980
+
? '- search: Ask natural language questions to find code locations (e.g., "How does authentication work?"). Returns structured JSON with file locations grouped by relevance. Use extract() on the returned files to read the actual code. Do NOT formulate keyword queries — just ask questions.'
3016
2981
: '- search: Find code patterns using keyword queries with Elasticsearch syntax. Handles stemming and case variations automatically — do NOT try manual keyword variations.';
3017
2982
systemPrompt+=`You have access to powerful code search and analysis tools through MCP:
3018
2983
${searchToolDesc1}
@@ -3025,10 +2990,10 @@ ${searchToolDesc1}
3025
2990
}
3026
2991
3027
2992
constsearchGuidance1=this.searchDelegate
3028
-
? '1. Start with search — ask a question about what you want to understand. It returns extracted code blocks directly.'
2993
+
? '1. Start with search — ask a question about what you want to understand. It returns file locations grouped by relevance (JSON with confidence and groups).'
3029
2994
: '1. Start with search to find relevant code patterns. One search per concept is usually enough — probe handles stemming and case variations.';
3030
2995
constextractGuidance1=this.searchDelegate
3031
-
? '2. Use extract only if you need more context or a full file'
2996
+
? '2. Use extract on the file locations returned by search to read the actual code. Each group has a "reason" explaining why those files matter.'
3032
2997
: '2. Use extract to get detailed context when needed';
3033
2998
3034
2999
systemPrompt+=`\n
@@ -3078,7 +3043,7 @@ ${extractGuidance1}
3078
3043
3079
3044
// Add high-level instructions about when to use tools
3080
3045
constsearchToolDesc2=this.searchDelegate
3081
-
? '- search: Ask natural language questions to find code (e.g., "How does authentication work?"). A subagent handles keyword searches and returns extracted code blocks. Do NOT formulate keyword queries — just ask questions.'
3046
+
? '- search: Ask natural language questions to find code locations (e.g., "How does authentication work?"). Returns structured JSON with file locations grouped by relevance. Use extract() on the returned files to read the actual code. Do NOT formulate keyword queries — just ask questions.'
3082
3047
: '- search: Find code patterns using keyword queries with Elasticsearch syntax. Handles stemming and case variations automatically — do NOT try manual keyword variations.';
3083
3048
systemPrompt+=`You have access to powerful code search and analysis tools through MCP:
3084
3049
${searchToolDesc2}
@@ -3091,10 +3056,10 @@ ${searchToolDesc2}
3091
3056
}
3092
3057
3093
3058
constsearchGuidance2=this.searchDelegate
3094
-
? '1. Start with search — ask a question about what you want to understand. It returns extracted code blocks directly.'
3059
+
? '1. Start with search — ask a question about what you want to understand. It returns file locations grouped by relevance (JSON with confidence and groups).'
3095
3060
: '1. Start with search to find relevant code patterns. One search per concept is usually enough — probe handles stemming and case variations.';
3096
3061
constextractGuidance2=this.searchDelegate
3097
-
? '2. Use extract only if you need more context or a full file'
3062
+
? '2. Use extract on the file locations returned by search to read the actual code. Each group has a "reason" explaining why those files matter.'
3098
3063
: '2. Use extract to get detailed context when needed';
3099
3064
3100
3065
systemPrompt+=`\n
@@ -3160,10 +3125,10 @@ ${extractGuidance2}
3160
3125
Follow these instructions carefully:
3161
3126
1. Analyze the user's request.
3162
3127
2. Use the available tools step-by-step to fulfill the request.
3163
-
3. You MUST use the search tool before answering ANY code-related question. NEVER answer from memory or general knowledge — your answers must be grounded in actual code found via search/extract.${this.searchDelegate ? ' Ask natural language questions — the search subagent handles keyword formulation and returns extracted code blocks. Use extract only to expand context or read full files.' : ' Search handles stemming and case variations automatically — do NOT try keyword variations manually. Read full files only if really necessary.'}
3128
+
3. You MUST use the search tool before answering ANY code-related question. NEVER answer from memory or general knowledge — your answers must be grounded in actual code found via search/extract.${this.searchDelegate ? ' Ask natural language questions — the search subagent handles keyword formulation and returns file locations grouped by relevance. Then use extract() on those locations to read the actual code.' : ' Search handles stemming and case variations automatically — do NOT try keyword variations manually. Read full files only if really necessary.'}
3164
3129
4. Ensure to get really deep and understand the full picture before answering. Follow call chains — if function A calls B, search for B too. Look for related subsystems (e.g., if asked about rate limiting, also check for quota, throttling, smoothing).
3165
3130
5. Once the task is fully completed, provide your final answer directly as text. Always cite specific files and line numbers as evidence. Do NOT output planning or thinking text — go straight to the answer.
3166
-
6. ${this.searchDelegate ? 'Ask clear, specific questions when searching. Each search should target a distinct concept or question.' : 'Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.'}
3131
+
6. ${this.searchDelegate ? 'Ask clear, specific questions when searching. Each search should target a distinct concept or question. NEVER re-search the same concept with different phrasing — if you already searched for "wrapToolWithEmitter", do NOT search again for "definition of wrapToolWithEmitter" or "how wrapToolWithEmitter works". Use extract() on the files already found instead. Limit yourself to one search per distinct concept. When formulating queries, describe WHAT you are looking for, not WHERE — the search agent will search the full codebase. Do NOT include file names or class names in the query unless that IS the concept (e.g., say "search dedup logic" not "search dedup ProbeAgent").' : 'Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.'}
3167
3132
7. NEVER use bash for code exploration (no grep, cat, find, head, tail, awk, sed) — always use search and extract tools instead. Bash is only for system operations like building, running tests, or git commands.${this.allowEdit ? `
3168
3133
7. When modifying files, choose the appropriate tool:
? `⚠️ LAST ITERATION — you are out of tool calls. Output your JSON response NOW with whatever files you have verified so far. Set confidence to "low" if your search was incomplete. Include the "searches" array listing all search queries you made with their paths and outcomes.${searchSummary}`
4061
+
: `⚠️ LAST ITERATION — you are out of tool calls. Provide your BEST answer NOW with the information gathered so far. If you could not find what was requested, explain exactly what you searched for and why it did not work, so the caller can try a different approach.${searchSummary}`;
4062
+
4091
4063
return{
4092
4064
toolChoice: 'none',
4093
-
userMessage: `⚠️ LAST ITERATION — you are out of tool calls. Provide your BEST answer NOW with the information gathered so far. If you could not find what was requested, explain exactly what you searched for and why it did not work, so the caller can try a different approach.${searchSummary}`
4065
+
userMessage: lastIterMessage
4094
4066
};
4095
4067
}
4096
4068
@@ -4766,27 +4738,41 @@ Double-check your response based on the criteria above. If everything looks good
summary+=`\nThe search approach may be fundamentally wrong for this query. Consider: using exact=true for literal string matching, using bash/grep for pattern-based file searches, or trying a completely different strategy instead of repeating similar searches.`;
4774
+
finalResult=summary;
4787
4775
}
4788
-
summary+=`\nThe search approach may be fundamentally wrong for this query. Consider: using exact=true for literal string matching, using bash/grep for pattern-based file searches, or trying a completely different strategy instead of repeating similar searches.`;
0 commit comments