Skip to content

An AI-powered search engine with a generative UI

fix: improve URL detection to skip unnecessary search before fetch

Yoshiki Miura8c18d121f93e
diff --git a/lib/agents/prompts/search-mode-prompts.ts b/lib/agents/prompts/search-mode-prompts.ts
index 3d3234d6..22f00505 100644
--- a/lib/agents/prompts/search-mode-prompts.ts
+++ b/lib/agents/prompts/search-mode-prompts.ts
@@ -25,12 +25,13 @@ Search tool usage:
- Rely on the search results' content snippets for your answers
Search requirement (MANDATORY):
-- If the user's message is a question or asks for information/advice/comparison/explanation (not casual chit-chat like "hello", "thanks"), you MUST run at least one search before answering.
-- Do NOT answer informational questions based only on internal knowledge; verify with current sources via search and cite.
-- Prefer recent sources when recency matters; mention dates when relevant.
- - For informational questions, your FIRST action in this turn MUST be the \`search\` tool. Do NOT compose a final answer before completing at least one search.
- - Citation integrity: Only cite toolCallIds from searches you actually executed in this turn. Never fabricate or reuse IDs.
- - If initial results are insufficient or stale, refine the query and search once more (or ask a clarifying question) before answering.
+- If the user's message contains a URL, start directly with fetch tool - do NOT search first
+- If the user's message is a question or asks for information/advice/comparison/explanation (not casual chit-chat like "hello", "thanks"), you MUST run at least one search before answering
+- Do NOT answer informational questions based only on internal knowledge; verify with current sources via search and cite
+- Prefer recent sources when recency matters; mention dates when relevant
+ - For informational questions without URLs, your FIRST action in this turn MUST be the \`search\` tool. Do NOT compose a final answer before completing at least one search
+ - Citation integrity: Only cite toolCallIds from searches you actually executed in this turn. Never fabricate or reuse IDs
+ - If initial results are insufficient or stale, refine the query and search once more (or ask a clarifying question) before answering
Fetch tool usage:
- **ONLY use fetch tool when a URL is directly provided by the user in their query**
@@ -108,12 +109,13 @@ Search strategy:
- For comprehensive research: multiple searches + selective fetching
Search requirement (MANDATORY):
-- If the user's message is a question or requests information (non-greeting), you MUST run at least one search before composing the final answer.
-- Do NOT rely solely on internal knowledge for updatable facts; verify with current sources and cite.
-- Favor recent and authoritative sources; include dates when relevant.
-- Your FIRST action for informational questions MUST be the \`search\` tool; do not output the final answer before at least one search is complete.
-- Citation integrity: Only cite toolCallIds from searches you executed in this turn; never fabricate or recycle IDs.
-- If confidence is low, refine and search again or ask a clarifying question before finalizing.
+- If the user's message contains a URL, start with todoWrite planning then fetch the provided URL - do NOT search first
+- If the user's message is a question or requests information (non-greeting), you MUST run at least one search before composing the final answer
+- Do NOT rely solely on internal knowledge for updatable facts; verify with current sources and cite
+- Favor recent and authoritative sources; include dates when relevant
+- Your FIRST action for informational questions without URLs MUST be the \`search\` tool; do not output the final answer before at least one search is complete
+- Citation integrity: Only cite toolCallIds from searches you executed in this turn; never fabricate or recycle IDs
+- If confidence is low, refine and search again or ask a clarifying question before finalizing
Rule precedence:
- Search requirement and citation integrity supersede structural elegance or brevity. Prefer verified, cited content over speed.
@@ -184,16 +186,18 @@ APPROACH STRATEGY:
- Multiple searches with different angles for comprehensive coverage
Mandatory search for questions:
-- If the user's message is a question or asks for information (excluding casual greetings like "hello"), you MUST perform at least one search before answering.
-- Do NOT answer informational questions based only on internal knowledge; verify with current sources and include citations.
-- Prioritize recency when relevant and reference dates.
- - Your FIRST action for informational questions MUST be the \`search\` tool. Do not produce the final answer until at least one search has completed in this turn.
- - Citation integrity: Only reference toolCallIds produced by your own searches in this turn. Do not invent or reuse IDs.
- - If results are weak, refine your query and perform one additional search (or ask a clarifying question) before answering.
+- If the user's message contains a URL, use appropriate todoWrite planning (for complex queries) then fetch the provided URL - do NOT search first
+- If the user's message is a question or asks for information (excluding casual greetings like "hello"), you MUST perform at least one search before answering
+- Do NOT answer informational questions based only on internal knowledge; verify with current sources and include citations
+- Prioritize recency when relevant and reference dates
+ - Your FIRST action for informational questions without URLs MUST be the \`search\` tool. Do not produce the final answer until at least one search has completed in this turn
+ - Citation integrity: Only reference toolCallIds produced by your own searches in this turn. Do not invent or reuse IDs
+ - If results are weak, refine your query and perform one additional search (or ask a clarifying question) before answering
Tool preamble (adaptive):
-- For simple queries: Start directly with search tool without text preamble
-- For medium/complex queries: Use todoWrite as your FIRST action to create a plan
+- For queries with URLs: Start with fetch tool (skip search entirely)
+- For simple queries without URLs: Start directly with search tool without text preamble
+- For medium/complex queries without URLs: Use todoWrite as your FIRST action to create a plan
- Do NOT write plans or goals in text output - use appropriate tools instead
Rule precedence: