An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: strengthen todoWrite guidance for complex queries
Yoshiki Miura3890dda63d32
diff --git a/lib/agents/prompts/search-mode-prompts.ts b/lib/agents/prompts/search-mode-prompts.tsindex 5f612fd9..21c5ff7c 100644--- a/lib/agents/prompts/search-mode-prompts.ts+++ b/lib/agents/prompts/search-mode-prompts.ts@@ -62,27 +62,37 @@ Structure your responses with:- Summary or conclusion when appropriate`-export const AUTO_MODE_PROMPT = `+export const ADAPTIVE_MODE_PROMPT = `Instructions:You are a helpful AI assistant with access to real-time web search, content retrieval, task management, and the ability to ask clarifying questions.APPROACH STRATEGY:-1. **Assess query complexity first:**- - Simple queries (1-2 aspects): Direct search and respond- - Medium queries (3-4 aspects): Consider using todoWrite for organization- - Complex queries (5+ aspects or requiring deep research): ALWAYS use todoWrite+1. **FIRST STEP - Assess query complexity:**+ - Simple queries (1-2 specific questions): Direct search and respond+ - Medium queries (3-4 related aspects): SHOULD use todoWrite for organization+ - Complex queries (ANY of the following): MUST use todoWrite+ * 5+ aspects to research+ * Requires comparing multiple viewpoints+ * Needs systematic investigation+ * Involves both research AND analysis/synthesis+ * User asks for "comprehensive" or "detailed" analysis-2. **For queries with multiple aspects or requiring systematic research:**- - Use todoWrite to break down the query into clear tasks- - Update task status as you progress through your research- - This helps users track your progress and ensures thoroughness+2. **When using todoWrite (for medium/complex queries):**+ - Create it as your FIRST action to show your plan+ - Break down into specific, measurable tasks like:+ * "Search for [specific aspect]"+ * "Fetch detailed content from top 3 sources"+ * "Compare perspectives from different sources"+ * "Synthesize findings into comprehensive answer"+ - Update task status as you progress (provides transparency)+ - This ensures thoroughness and helps users track progress3. **Search and fetch strategy:**- - Start with type="general" search to get an overview and identify key sources- - ALWAYS follow up promising search results with fetch tool for deeper analysis- - Use multiple searches with different keywords for comprehensive coverage- - Pattern: Search → Identify top sources → Fetch detailed content → Synthesize+ - Use type="optimized" for research queries (immediate content)+ - Use type="general" for current events/news (then fetch for content)+ - Pattern: Search → Identify top sources → Fetch if needed → Synthesize+ - Multiple searches with different angles for comprehensive coverage4. **If the query is ambiguous, use ask_question tool for clarification**diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex 784ecfdd..f7cd9c02 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -16,7 +16,7 @@ import { getModel } from '../utils/registry'import { isTracingEnabled } from '../utils/telemetry'import {- AUTO_MODE_PROMPT,+ ADAPTIVE_MODE_PROMPT,PLANNING_MODE_PROMPT,QUICK_MODE_PROMPT} from './prompts/search-mode-prompts'@@ -109,7 +109,7 @@ export function researcher({case 'adaptive':default:// Adaptive Mode: Balanced approach, current behavior- systemPrompt = AUTO_MODE_PROMPT+ systemPrompt = ADAPTIVE_MODE_PROMPTactiveToolsList = ['search', 'fetch']if (writer && 'todoWrite' in todoTools) {activeToolsList.push('todoWrite', 'todoRead')diff --git a/lib/config/model-types.ts b/lib/config/model-types.tsindex a6ca0beb..b6430b91 100644--- a/lib/config/model-types.ts+++ b/lib/config/model-types.ts@@ -10,7 +10,8 @@ export const MODEL_TYPE_CONFIGS: Record<ModelType, Model> = {providerId: 'gateway',providerOptions: {gateway: {- order: ['groq', 'deepinfra']+ order: ['groq', 'deepinfra'],+ only: ['groq']}}},