feat: 增强联网搜索与网页抓取的联动

1. TOOL_USAGE_GUIDE 新增第 6 条:联网搜索联动规则
   - 要求 AI 在 web_search 后必须选择相关 URL 调用 web_fetch 抓取详情
   - 明确告知搜索摘要往往不完整,必须抓取原文才能给出准确答案
2. web_search 默认结果数从 5 提升到 8,给 AI 更多线索定位目标页面
This commit is contained in:
Metona
2026-04-17 09:00:08 +08:00
parent a2cff73fd7
commit fdb0e96561
3 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -495,7 +495,7 @@ export async function handleWebSearch(params: { query: string; max_results?: num
return { success: false, error: '搜索关键词不能为空' }; return { success: false, error: '搜索关键词不能为空' };
} }
const maxResults = Math.min(params.max_results || 5, 10); const maxResults = Math.min(params.max_results || 8, 10);
sendLog('info', `🔍 web_search`, `"${query}" (${maxResults} 条)`); sendLog('info', `🔍 web_search`, `"${query}" (${maxResults} 条)`);
+2 -1
View File
@@ -32,7 +32,8 @@ const TOOL_USAGE_GUIDE = `【工具使用规则】
2. 工具调用结果中的 path 字段是权威的文件路径,优先使用它。 2. 工具调用结果中的 path 字段是权威的文件路径,优先使用它。
3. 如果对话中从未出现过相关路径,应先用 search_files 或 list_directory 定位,不要凭空猜测路径。 3. 如果对话中从未出现过相关路径,应先用 search_files 或 list_directory 定位,不要凭空猜测路径。
4. 对同一文件的连续操作(读取→修改、读取→删除),路径必须一致。 4. 对同一文件的连续操作(读取→修改、读取→删除),路径必须一致。
5. 当用户要求执行命令时,使用 run_command 工具执行。命令通过工作空间终端实时执行并显示,执行完成后将 stdout/stderr 结果告知用户。`; 5. 当用户要求执行命令时,使用 run_command 工具执行。命令通过工作空间终端实时执行并显示,执行完成后将 stdout/stderr 结果告知用户。
6. 联网搜索联动:当用户询问需要最新信息的问题时(如版本号、新闻、价格等),先用 web_search 搜索,然后必须从搜索结果中选择最相关的 1-3 个 URL,用 web_fetch 抓取页面详细内容获取准确数据。不要仅凭搜索摘要回答——摘要往往不完整,必须抓取原文才能给出准确答案。`;
export interface AgentCallbacks { export interface AgentCallbacks {
onThinking: (text: string) => void; onThinking: (text: string) => void;
+1 -1
View File
@@ -346,7 +346,7 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [
required: ['query'], required: ['query'],
properties: { properties: {
query: { type: 'string', description: 'The search query. Be specific and concise for best results.' }, query: { type: 'string', description: 'The search query. Be specific and concise for best results.' },
max_results: { type: 'integer', description: 'Maximum number of results to return. Default: 5, max: 10.' } max_results: { type: 'integer', description: 'Maximum number of results to return. Default: 8, max: 10.' }
} }
} }
} }