import BaseTool from './baseTool.js'; /** * 找到答案工具 - 用于标记AI是否找到了足够的信息来回答用户 */ class FindAnswerTool extends BaseTool { constructor() { super( 'found_answer', '当你已经收集到足够信息可以回答用户问题时使用此工具', { type: 'object', properties: { answer_summary: { type: 'string', description: '简要总结你找到的关键信息,这将传递给下一阶段' }, confidence: { type: 'number', description: '回答的信心程度(0-1),1表示非常确信', minimum: 0, maximum: 1, default: 0.8 } }, required: ['answer_summary'] } ); } async execute(params, context) { const { answer_summary, confidence = 0.8 } = params; logger.info(`[crystelf-ai] AI找到答案 - 信心度: ${confidence}, 摘要: ${answer_summary}`); return { success: true, message: `已找到答案信息: ${answer_summary}`, foundAnswer: true, answerSummary: answer_summary, confidence }; } } /** * 信息不足工具 - 用于标记AI认为信息不足 */ class NotEnoughInfoTool extends BaseTool { constructor() { super( 'not_enough_info', '当你认为收集的信息不足以回答用户问题时使用此工具', { type: 'object', properties: { reason: { type: 'string', description: '说明为什么信息不足,缺少什么关键信息' }, tried_methods: { type: 'array', items: { type: 'string' }, description: '已经尝试过的搜索方法' } }, required: ['reason'] } ); } async execute(params, context) { const { reason, tried_methods = [] } = params; logger.info(`[crystelf-ai] AI认为信息不足 - 原因: ${reason}`); return { success: true, message: `信息不足: ${reason}`, foundAnswer: false, reason, triedMethods: tried_methods }; } } export { FindAnswerTool, NotEnoughInfoTool };