From 7919fe010b46f76d50a30f7cc418a57ecb5965b8 Mon Sep 17 00:00:00 2001 From: nzlov Date: Wed, 5 Mar 2025 19:24:57 +0800 Subject: [PATCH] docs: add custom tool (#1487) * docs: add custom tool * fix: add func params --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 0ef9958..64b6565 100644 --- a/README.md +++ b/README.md @@ -742,6 +742,54 @@ Tool list > rag_search, python, git_diff, git_commit, list_files, search_files, search_keyword, read_file_toplevel_symbols, > read_file, create_file, rename_file, delete_file, create_dir, rename_dir, delete_dir, bash, web_search, fetch +## Custom Tools + +Avante allows you to define custom tools that can be used by the AI during code generation and analysis. These tools can execute shell commands, run scripts, or perform any custom logic you need. + +### Example: Go Test Runner + +Here's an example of a custom tool that runs Go unit tests: + +```lua +{ + custom_tools = { + { + name = "run_go_tests", -- Unique name for the tool + description = "Run Go unit tests and return results", -- Description shown to AI + command = "go test -v ./...", -- Shell command to execute + param = { -- Input parameters (optional) + type = "table", + fields = { + { + name = "target", + description = "Package or directory to test (e.g. './pkg/...' or './internal/pkg')", + type = "string", + optional = true, + }, + }, + }, + returns = { -- Expected return values + { + name = "result", + description = "Result of the fetch", + type = "string", + }, + { + name = "error", + description = "Error message if the fetch was not successful", + type = "string", + optional = true, + }, + }, + func = function(params, on_log, on_complete) -- Custom function to execute + local target = params.target or "./..." + return vim.fn.system(string.format("go test -v %s", target)) + end, + }, + }, +} +``` + ## Custom prompts By default, `avante.nvim` provides three different modes to interact with: `planning`, `editing`, and `suggesting`, followed with three different prompts per mode.