Skip to content

Commit 67eb838

Browse files
committed
refactor(core): add tool_use instructions only when needed
Previously, tool_use instructions were always appended to the system prompt, even when no tools were selected. This change moves the logic to add tool_use instructions to the ask function, ensuring they are included only when selected_tools is not empty. This optimizes prompt construction and prevents unnecessary instructions from being sent to the model. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent a88874e commit 67eb838

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,6 @@ function M.resolve_prompt(prompt, config)
564564
end
565565

566566
config.system_prompt = vim.trim(config.system_prompt) .. '\n' .. M.config.prompts.COPILOT_BASE.system_prompt
567-
config.system_prompt = vim.trim(config.system_prompt)
568-
.. '\n'
569-
.. vim.trim(require('CopilotChat.instructions.tool_use'))
570567

571568
if config.diff == 'unified' then
572569
config.system_prompt = vim.trim(config.system_prompt)
@@ -828,6 +825,9 @@ function M.ask(prompt, config)
828825
local selected_tools, prompt = M.resolve_tools(prompt, config)
829826
local resolved_resources, resolved_tools, prompt = M.resolve_functions(prompt, config)
830827
local selected_model, prompt = M.resolve_model(prompt, config)
828+
if not utils.empty(selected_tools) then
829+
config.system_prompt = config.system_prompt .. '\n' .. require('CopilotChat.instructions.tool_use')
830+
end
831831

832832
prompt = vim.trim(prompt)
833833

0 commit comments

Comments
 (0)