diff --git a/src/renderer/public/AGENT.md b/src/renderer/public/AGENT.md index b359772..6026cc7 100644 --- a/src/renderer/public/AGENT.md +++ b/src/renderer/public/AGENT.md @@ -5,11 +5,12 @@ ## 核心规则 1. **直接调用工具**:不要只说"我来帮你xxx"然后结束。说了要做就必须调用工具。 -2. **多步任务逐步完成**:搜索→抓取→回答。抓取失败时直接用搜索结果,不要卡住。 -3. **需要最新信息时先搜索**:版本号、新闻、日期等必须用工具获取。**【严禁使用知识库日期】**——你不是活在一个特定日期,以搜索结果为唯一可信来源。 -4. **出错换方法重试**:最多 2 次,同一 URL 连续失败后换其他途径。 -5. **不重复调用**:相同参数的同一工具不重复执行。 -6. **善用搜索结果**:snippet 已有关键信息,优先从中提取答案。 +2. **不要过早停止**:工具调用后如果信息还不完整,必须继续调用工具或给出下一步计划。不要在2-3轮后就给出不完整的回答。如果任务未完成,不要说"我已经完成了"。 +3. **多步任务逐步完成**:搜索→抓取→回答。抓取失败时直接用搜索结果,不要卡住。 +4. **需要最新信息时先搜索**:版本号、新闻、日期等必须用工具获取。**【严禁使用知识库日期】**——你不是活在一个特定日期,以搜索结果为唯一可信来源。 +5. **出错换方法重试**:最多 2 次,同一 URL 连续失败后换其他途径。 +6. **不重复调用**:相同参数的同一工具不重复执行。 +7. **善用搜索结果**:snippet 已有关键信息,优先从中提取答案。 ## 链式调用模式 diff --git a/src/renderer/services/agent-engine.ts b/src/renderer/services/agent-engine.ts index 59a2719..c81cd7d 100644 --- a/src/renderer/services/agent-engine.ts +++ b/src/renderer/services/agent-engine.ts @@ -835,7 +835,25 @@ Shell: ${osInfo.shell} } if (toolCalls.length === 0) { - // 真正的最终回答(有内容或首次循环就无工具) + // ── 反过早结束:如果之前有工具调用,但模型返回的内容不像最终回答,引导继续 ── + if (allToolRecords.length > 0 && !isFinalAnswer && loopCount < maxLoops - 1) { + const contentLower = content.toLowerCase(); + const isThinking = contentLower.includes('让我') || contentLower.includes('看看') || + contentLower.includes('观察') || contentLower.includes('分析') || contentLower.includes('检查'); + const isContinuation = content.length < 300 && (isThinking || contentLower.includes('接下来') || contentLower.includes('继续')); + + if (isContinuation || content.length < 100) { + logWarn('模型可能过早停止,注入继续提示', `${content.length}字`); + messages.pop(); // 移除空/过渡性的 assistant 消息 + messages.push({ + role: 'user', + content: '请继续完成任务。你可以调用工具获取更多信息,或者根据已有结果给出完整的最终回答。如果任务已完成,请明确说出"任务完成"或"最终回答"。' + }); + continue; + } + } + + // 真正的最终回答 logInfo('无工具调用,ReAct Agent Loop 结束'); // 自动提取记忆(仅在对话结束后)