diff --git a/lua/avante/highlights.lua b/lua/avante/highlights.lua index 0dab5e9..e862733 100644 --- a/lua/avante/highlights.lua +++ b/lua/avante/highlights.lua @@ -48,7 +48,7 @@ local Highlights = { AVANTE_STATE_SPINNER_THINKING = { name = "AvanteStateSpinnerThinking", fg = "#1e222a", bg = "#c678dd" }, AVANTE_STATE_SPINNER_COMPACTING = { name = "AvanteStateSpinnerCompacting", fg = "#1e222a", bg = "#c678dd" }, AVANTE_TASK_COMPLETED = { name = "AvanteTaskCompleted", fg = "#98c379", bg_link = "Normal" }, - AVANTE_THINKING = { name = "AvanteThinking", fg = "#1e222a", bg = "#c678dd" }, + AVANTE_THINKING = { name = "AvanteThinking", fg = "#c678dd", bg_link = "Normal" }, } Highlights.conflict = { diff --git a/lua/avante/llm_tools/init.lua b/lua/avante/llm_tools/init.lua index 1ec6679..8ff6017 100644 --- a/lua/avante/llm_tools/init.lua +++ b/lua/avante/llm_tools/init.lua @@ -1052,7 +1052,7 @@ You can delete the first file by providing a path of "directory1/a/something.txt }, }, }, - require("avante.llm_tools.thinking"), + require("avante.llm_tools.think"), require("avante.llm_tools.get_diagnostics"), require("avante.llm_tools.bash"), require("avante.llm_tools.attempt_completion"), diff --git a/lua/avante/llm_tools/thinking.lua b/lua/avante/llm_tools/think.lua similarity index 64% rename from lua/avante/llm_tools/thinking.lua rename to lua/avante/llm_tools/think.lua index 0b45b86..8103335 100644 --- a/lua/avante/llm_tools/thinking.lua +++ b/lua/avante/llm_tools/think.lua @@ -6,10 +6,14 @@ local Utils = require("avante.utils") ---@class AvanteLLMTool local M = setmetatable({}, Base) -M.name = "thinking" +M.name = "think" M.description = - "A tool for thinking through problems, brainstorming ideas, or planning without executing any actions. Use this tool when you need to work through complex problems, develop strategies, or outline approaches before taking action." + [[Use the tool to think about something. It will not obtain new information or make any changes to the repository, but just log the thought. Use it when complex reasoning or brainstorming is needed. For example, if you explore the repo and discover the source of a bug, call this tool to brainstorm several unique ways of fixing the bug, and assess which change(s) are likely to be simplest and most effective. Alternatively, if you receive some test results, call this tool to brainstorm ways to fix the failing tests. + +RULES: +- Remember to frequently use the `think` tool to resolve tasks, especially before each tool call. +]] M.support_streaming = true @@ -18,8 +22,8 @@ M.param = { type = "table", fields = { { - name = "content", - description = "Content to think about. This should be a description of what to think about or a problem to solve.", + name = "thought", + description = "Your thoughts.", type = "string", }, }, @@ -40,7 +44,7 @@ M.returns = { } ---@class ThinkingInput ----@field content string +---@field thought string ---@type avante.LLMToolOnRender function M.on_render(opts, _, state) @@ -48,7 +52,7 @@ function M.on_render(opts, _, state) local text = state == "generating" and "Thinking" or "Thoughts" table.insert(lines, Line:new({ { Utils.icon("🤔 ") .. text, Highlights.AVANTE_THINKING } })) table.insert(lines, Line:new({ { "" } })) - local content = opts.content or "" + local content = opts.thought or "" local text_lines = vim.split(content, "\n") for _, text_line in ipairs(text_lines) do table.insert(lines, Line:new({ { "> " .. text_line } })) diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua index 002bc64..61145be 100644 --- a/lua/avante/providers/openai.lua +++ b/lua/avante/providers/openai.lua @@ -379,6 +379,16 @@ function M:add_tool_use_message(tool_use, state, opts) end function M:parse_response(ctx, data_stream, _, opts) + local orig_on_stop = opts.on_stop + local stopped = false + ---@param stop_opts AvanteLLMStopCallbackOptions + opts.on_stop = function(stop_opts) + if stop_opts and not stop_opts.streaming_tool_use then + if stopped then return end + stopped = true + end + return orig_on_stop(stop_opts) + end if data_stream:match('"%[DONE%]":') then self:finish_pending_messages(ctx, opts) if ctx.tool_use_list and #ctx.tool_use_list > 0 then @@ -388,7 +398,10 @@ function M:parse_response(ctx, data_stream, _, opts) end return end - if data_stream == "[DONE]" then return end + if data_stream == "[DONE]" then + opts.on_stop({ reason = "complete" }) + return + end local jsn = vim.json.decode(data_stream) ---@cast jsn AvanteOpenAIChatResponse if not jsn.choices then return end diff --git a/lua/avante/templates/_tools-guidelines.avanterules b/lua/avante/templates/_tools-guidelines.avanterules index 24f6b3d..2ca8d04 100644 --- a/lua/avante/templates/_tools-guidelines.avanterules +++ b/lua/avante/templates/_tools-guidelines.avanterules @@ -11,17 +11,16 @@ TOOLS USAGE GUIDE - Before using the `view` tool each time, always repeatedly check whether the file is already in the tag. If it is already there, do not use the `view` tool, just read the file content directly from the tag. - If you use the `view` tool when file content is already provided in the tag, you will be fired! - If the `rag_search` tool exists, prioritize using it to do the search! -- If the `rag_search` tool exists, only use tools like `search_keyword` `search_files` `view` `list_files` etc when absolutely necessary! +- If the `rag_search` tool exists, only use tools like `glob` `view` `ls` etc when absolutely necessary! - Keep the `query` parameter of `rag_search` tool as concise as possible! Try to keep it within five English words! - If you encounter a URL, prioritize using the `fetch` tool to obtain its content. - If you have information that you don't know, please proactively use the tools provided by users! Especially the `web_search` tool. - When available tools cannot meet the requirements, please try to use the `run_command` tool to solve the problem whenever possible. -- When attempting to modify a file that is not in the context, please first use the `list_files` tool and `search_files` tool to check if the file you want to modify exists, then use the `view` tool to read the file content. Don't modify blindly! -- When generating files, first use `list_files` tool to read the directory structure, don't generate blindly! +- When attempting to modify a file that is not in the context, please first use the `ls` tool and `glob` tool to check if the file you want to modify exists, then use the `view` tool to read the file content. Don't modify blindly! +- When generating files, first use `ls` tool to read the directory structure, don't generate blindly! - When creating files, first check if the directory exists. If it doesn't exist, create the directory before creating the file. - After `web_search` tool returns, if you don't get detailed enough information, do not continue use `web_search` tool, just continue using the `fetch` tool to get more information you need from the links in the search results. -- For any mathematical calculation problems, please prioritize using the `python` tool to solve them. Please try to avoid mathematical symbols in the return value of the `python` tool for mathematical problems and directly output human-readable results, because large models don't understand mathematical symbols, they only understand human natural language. -- Do not use the `run_python` tool to read or modify files! If you use the `python` tool to read or modify files, you will be fired!!!!! +- For any mathematical calculation problems, please prioritize using the `the_python` tool to solve them. Please try to avoid mathematical symbols in the return value of the `the_python` tool for mathematical problems and directly output human-readable results, because large models don't understand mathematical symbols, they only understand human natural language. +- Do not use the `run_python` tool to read or modify files! If you use the `the_python` tool to read or modify files, you will be fired!!!!! - Do not use the `bash` tool to read or modify files! If you use the `bash` tool to read or modify files, you will be fired!!!!! - If you are provided with the `write_file` tool, there's no need to output your change suggestions, just directly use the `write_file` tool to complete the changes. -- Before each tool call, explain the reason why you're using the tool