From aee18837e446c7a5a773ee8306d4419d92f78dd0 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Thu, 20 Nov 2025 17:25:30 +0800 Subject: [PATCH] feat: enhance smart thinking scheduling --- config/limits.py | 2 + prompts/thinking_mode_guidelines.txt | 10 +- static/app.js | 17 +++- static/index.html | 8 +- utils/api_client.py | 35 +++++-- web_server.py | 141 ++++++++++++++++++++++++++- 6 files changed, 188 insertions(+), 25 deletions(-) diff --git a/config/limits.py b/config/limits.py index ff9dd44..c3687c6 100644 --- a/config/limits.py +++ b/config/limits.py @@ -18,6 +18,7 @@ MAX_ITERATIONS_PER_TASK = 100 MAX_CONSECUTIVE_SAME_TOOL = 50 MAX_TOTAL_TOOL_CALLS = 100 TOOL_CALL_COOLDOWN = 0.5 +THINKING_FAST_INTERVAL = 10 # 工具字符/体积限制 MAX_READ_FILE_CHARS = 30000 @@ -49,6 +50,7 @@ __all__ = [ "MAX_CONSECUTIVE_SAME_TOOL", "MAX_TOTAL_TOOL_CALLS", "TOOL_CALL_COOLDOWN", + "THINKING_FAST_INTERVAL", "MAX_READ_FILE_CHARS", "MAX_FOCUS_FILE_CHARS", "MAX_RUN_COMMAND_CHARS", diff --git a/prompts/thinking_mode_guidelines.txt b/prompts/thinking_mode_guidelines.txt index ef21918..94c5964 100644 --- a/prompts/thinking_mode_guidelines.txt +++ b/prompts/thinking_mode_guidelines.txt @@ -1,5 +1,6 @@ -你现在处于「思考模式」。 -思考模式时,第一次请求的模型不是kimi-k2,而是kimi-k2-thinking 一个更善于分析复杂问题,规划复杂流程的模型,在后续请求时,模型会换回kimi-k2 +你现在处于「思考模式」 +思考模式时,第一次请求的模型不是kimi-k2,而是kimi-k2-thinking 一个更善于分析复杂问题,规划复杂流程的模型,在后续请求时,模型会换回kimi-k2。 +并且,在系统监控到工具或写入失败时,会自动再次切换到思考模型,思考模型会更加深入地分析错误的原因,保证任务顺利进行。 请百分百遵循一下原则: @@ -24,4 +25,7 @@ - 若判断无需任何工具或修改,也要明确说明理由。 - 保持语气专业但亲切,让用户清楚你即将采取的行动。 -# 你的思考过程在后文会不可见,所以你需要在用户给出要求时的第一次回答中尽可能在正式输出中详细描述你的规划,来作为后面kimi-k2模型行动时提供参考依据 \ No newline at end of file +# 你的思考过程在后文会不可见,所以你需要在用户给出要求时的第一次回答中尽可能在正式输出中详细描述你的规划,来作为后面kimi-k2模型行动时提供参考依据 + +**⚠️重要提示⚠️** +思考模式下,token会被大量消耗,所以请保持思路连贯,在思考内容中禁止回顾全部的上下文历史,只需紧扣上一步的状态并规划下一步行动。 \ No newline at end of file diff --git a/static/app.js b/static/app.js index e5cfd51..7361314 100644 --- a/static/app.js +++ b/static/app.js @@ -737,7 +737,7 @@ async function bootstrapApp() { }; msg.actions.push(action); - const blockId = `${this.currentMessageIndex}-thinking-${msg.actions.length - 1}`; + const blockId = action.blockId || `thinking-${Date.now()}-${Math.random().toString(36).slice(2)}`; action.blockId = blockId; this.expandedBlocks.add(blockId); // 开始思考时自动锁定滚动到底部 @@ -777,12 +777,17 @@ async function bootstrapApp() { if (lastAction && lastAction.type === 'thinking') { lastAction.streaming = false; lastAction.content = data.full_content; - if (lastAction.blockId) { + const blockId = lastAction.blockId || `thinking-${Date.now()}-${Math.random().toString(36).slice(2)}`; + if (!lastAction.blockId) { + lastAction.blockId = blockId; + } + if (blockId) { setTimeout(() => { - this.expandedBlocks.delete(lastAction.blockId); + this.expandedBlocks.delete(blockId); + this.thinkingScrollLocks.delete(blockId); this.$forceUpdate(); }, 1000); - this.$nextTick(() => this.scrollThinkingToBottom(lastAction.blockId)); + this.$nextTick(() => this.scrollThinkingToBottom(blockId)); } } msg.streamingThinking = ''; @@ -1694,12 +1699,14 @@ async function bootstrapApp() { } if (reasoningText) { + const blockId = `history-thinking-${Date.now()}-${Math.random().toString(36).slice(2)}`; currentAssistantMessage.actions.push({ id: `history-think-${Date.now()}-${Math.random()}`, type: 'thinking', content: reasoningText, streaming: false, - timestamp: Date.now() + timestamp: Date.now(), + blockId }); console.log('添加思考内容:', reasoningText.substring(0, 50) + '...'); } diff --git a/static/index.html b/static/index.html index bf33efa..d4e081a 100644 --- a/static/index.html +++ b/static/index.html @@ -269,8 +269,8 @@