Skip to content

Commit

Permalink
feat: add custom tools config (#1461)
Browse files Browse the repository at this point in the history
* chore: add string literal types for tool params, and returns

* feat: add custom tools config
  • Loading branch information
PeterCardenas authored Mar 3, 2025
1 parent 6bbf9b3 commit de1e6a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lua/avante/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local Utils = require("avante.utils")
---@class avante.CoreConfig: avante.Config
local M = {}
---@class avante.Config
---@field custom_tools AvanteLLMToolPublic[]
M._defaults = {
debug = false,
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "vertex" | "cohere" | "copilot" | string
Expand Down Expand Up @@ -409,6 +410,8 @@ M._defaults = {
throttle = 600,
},
disabled_tools = {}, ---@type string[]
---@type AvanteLLMToolPublic[]
custom_tools = {},
}

---@type avante.Config
Expand Down
4 changes: 3 additions & 1 deletion lua/avante/llm_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,10 @@ end

---@return AvanteLLMTool[]
function M.get_tools()
---@type AvanteLLMTool[]
local unfiltered_tools = vim.list_extend(vim.list_extend({}, M._tools), Config.custom_tools)
return vim
.iter(M._tools)
.iter(unfiltered_tools)
:filter(function(tool) ---@param tool AvanteLLMTool
-- Always disable tools that are explicitly disabled
if vim.tbl_contains(Config.disabled_tools, tool.name) then return false end
Expand Down
9 changes: 6 additions & 3 deletions lua/avante/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,21 @@ vim.g.avante_login = vim.g.avante_login
---@field returns AvanteLLMToolReturn[]
---@field enabled? fun(): boolean

---@class AvanteLLMToolPublic : AvanteLLMTool
---@field func AvanteLLMToolFunc

---@class AvanteLLMToolParam
---@field type string
---@field type 'table'
---@field fields AvanteLLMToolParamField[]

---@class AvanteLLMToolParamField
---@field name string
---@field description string
---@field type string
---@field type 'string' | 'integer'
---@field optional? boolean

---@class AvanteLLMToolReturn
---@field name string
---@field description string
---@field type string
---@field type 'string' | 'string[]' | 'boolean'
---@field optional? boolean

0 comments on commit de1e6a4

Please sign in to comment.