From fa05e53307ab55a2f63d6deaff4e9ad6222658fd Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Fri, 7 Feb 2025 12:35:27 +0800 Subject: [PATCH] feat: improve search action --- src/agent.ts | 14 ++++++++++++-- src/tools/query-rewriter.ts | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/agent.ts b/src/agent.ts index 854356f..09e45b5 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -75,6 +75,7 @@ function getPrompt( question: string, context?: string[], allQuestions?: string[], + allKeywords?: string[], allowReflect: boolean = true, allowAnswer: boolean = true, allowRead: boolean = true, @@ -190,11 +191,18 @@ ${urlList} } if (allowSearch) { + actionSections.push(` -- Query external sources using a public search engine +- Search external, realtime world-knoweledge using a search engine - Focus on solving one specific aspect of the question -- Only give keywords search query, not full sentences +- Only use keywords in th search query, not full sentences +${allKeywords?.length ? ` +- The following searched queries do not give useful information, you need to think out of the box or cut from a completely different angle: + +${allKeywords.join('\n')} + +` : ''} `); } @@ -314,6 +322,7 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_ currentQuestion, diaryContext, allQuestions, + allKeywords, allowReflect, allowAnswer, allowRead, @@ -640,6 +649,7 @@ You decided to think out of the box or cut from a completely different angle.`); question, diaryContext, allQuestions, + allKeywords, false, false, false, diff --git a/src/tools/query-rewriter.ts b/src/tools/query-rewriter.ts index ba244ea..70a7ed0 100644 --- a/src/tools/query-rewriter.ts +++ b/src/tools/query-rewriter.ts @@ -18,7 +18,7 @@ const responseSchema = z.object({ function getPrompt(action: SearchAction): string { - return `You are an expert Information Retrieval Assistant. Transform user queries into precise keyword combinations with strategic reasoning and appropriate search operators. + return `You are an expert Information Retrieval query optimizer. Optimize user queries into precise keyword combinations with strategic reasoning and appropriate search operators. 1. Generate search queries that directly include appropriate operators @@ -61,7 +61,7 @@ Input Query: How to fix a leaking kitchen faucet? This is a how-to query seeking practical solutions. User likely wants step-by-step guidance and visual demonstrations for DIY repair. We'll target both video tutorials and written guides. -Queries: [ +Output Queries: [ "kitchen faucet leak repair", "faucet drip fix site:youtube.com", "how to repair faucet " @@ -71,7 +71,7 @@ Input Query: What are healthy breakfast options for type 2 diabetes? This is a health-specific informational query. User needs authoritative medical advice combined with practical meal suggestions. Splitting into medical guidelines and recipes will provide comprehensive coverage. -Queries: [ +Output Queries: [ "what to eat for type 2 diabetes", "type 2 diabetes breakfast guidelines", "diabetic breakfast recipes" @@ -81,7 +81,7 @@ Input Query: Latest AWS Lambda features for serverless applications This is a product research query focused on recent updates. User wants current information about specific technology features, likely for implementation purposes. We'll target official docs and community insights. -Queries: [ +Output Queries: [ "aws lambda features site:aws.amazon.com intitle:2025", "new features lambda serverless" ]