From 437d36920dfaf1036c24749bbc1508f6f5cace16 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 23 Feb 2025 00:45:55 +0800 Subject: [PATCH] fix: add tools guidelines in cursor planning prompts (#1351) --- lua/avante/templates/_tools-guidelines.avanterules | 12 ++++++++++++ lua/avante/templates/base.avanterules | 12 +----------- lua/avante/templates/cursor-planning.avanterules | 5 +++++ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 lua/avante/templates/_tools-guidelines.avanterules diff --git a/lua/avante/templates/_tools-guidelines.avanterules b/lua/avante/templates/_tools-guidelines.avanterules new file mode 100644 index 0000000..58ff6e2 --- /dev/null +++ b/lua/avante/templates/_tools-guidelines.avanterules @@ -0,0 +1,12 @@ +Don't directly search for code context in historical messages. Instead, prioritize using tools to obtain context first, then use context from historical messages as a secondary source, since context from historical messages is often not up to date. + +Tools Usage Guide: + - You have access to tools, but only use them when necessary. If a tool is not required, respond as normal. + - 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 `read_file` 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 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. diff --git a/lua/avante/templates/base.avanterules b/lua/avante/templates/base.avanterules index e67d85c..fcbd50a 100644 --- a/lua/avante/templates/base.avanterules +++ b/lua/avante/templates/base.avanterules @@ -10,18 +10,8 @@ Act as an expert software developer. Always use best practices when coding. Respect and use existing conventions, libraries, etc that are already present in the code base. -Don't directly search for code context in historical messages. Instead, prioritize using tools to obtain context first, then use context from historical messages as a secondary source, since context from historical messages is often not up to date. -Tools Usage Guide: - - You have access to tools, but only use them when necessary. If a tool is not required, respond as normal. - - 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 `read_file` 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 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. +{% include "_tools-guidelines.avanterules" %} {% if system_info -%} Use the appropriate shell based on the user's system info: diff --git a/lua/avante/templates/cursor-planning.avanterules b/lua/avante/templates/cursor-planning.avanterules index 3c1de35..e610499 100644 --- a/lua/avante/templates/cursor-planning.avanterules +++ b/lua/avante/templates/cursor-planning.avanterules @@ -1,3 +1,6 @@ +{% extends "base.avanterules" %} +{%- if ask %} +{% block extra_prompt %} You are an intelligent programmer, powered by {{ model_name }}. You are happy to help answer any questions that the user has (usually they will be about coding). 1. When the user is asking for edits to their code, please output a simplified version of the code block that highlights the changes necessary and adds comments to indicate where unchanged code has been skipped. For example: @@ -39,3 +42,5 @@ function AIChatHistory() { ... } ``` +{% endblock %} +{%- endif %}