fix: disable compact history messages for dispatch agent (#1954)

This commit is contained in:
yetone
2025-05-01 05:19:54 +08:00
committed by GitHub
parent f2330a0701
commit 448efbb842
3 changed files with 28 additions and 20 deletions

View File

@@ -290,28 +290,34 @@ function M.generate_prompts(opts)
local final_history_messages = {}
if opts.history_messages then
if Config.history.max_tokens > 0 then remaining_tokens = math.min(Config.history.max_tokens, remaining_tokens) end
-- Traverse the history in reverse, keeping only the latest history until the remaining tokens are exhausted and the first message role is "user"
local history_messages = {}
for i = #opts.history_messages, 1, -1 do
local message = opts.history_messages[i]
local tokens = Utils.tokens.calculate_tokens(message.message.content)
remaining_tokens = remaining_tokens - tokens
if remaining_tokens > 0 then
table.insert(history_messages, 1, message)
else
break
if opts.disable_compact_history_messages then
final_history_messages = vim.list_extend(final_history_messages, opts.history_messages)
else
if Config.history.max_tokens > 0 then
remaining_tokens = math.min(Config.history.max_tokens, remaining_tokens)
end
-- Traverse the history in reverse, keeping only the latest history until the remaining tokens are exhausted and the first message role is "user"
local history_messages = {}
for i = #opts.history_messages, 1, -1 do
local message = opts.history_messages[i]
local tokens = Utils.tokens.calculate_tokens(message.message.content)
remaining_tokens = remaining_tokens - tokens
if remaining_tokens > 0 then
table.insert(history_messages, 1, message)
else
break
end
end
if #history_messages == 0 then
history_messages = vim.list_slice(opts.history_messages, #opts.history_messages - 1, #opts.history_messages)
end
dropped_history_messages = vim.list_slice(opts.history_messages, 1, #opts.history_messages - #history_messages)
-- prepend the history messages to the messages table
vim.iter(history_messages):each(function(msg) table.insert(final_history_messages, msg) end)
end
if #history_messages == 0 then
history_messages = vim.list_slice(opts.history_messages, #opts.history_messages - 1, #opts.history_messages)
end
dropped_history_messages = vim.list_slice(opts.history_messages, 1, #opts.history_messages - #history_messages)
-- prepend the history messages to the messages table
vim.iter(history_messages):each(function(msg) table.insert(final_history_messages, msg) end)
end
-- Utils.debug("opts.history_messages", opts.history_messages)

View File

@@ -94,6 +94,7 @@ When you're done, provide a clear and concise summary of what you found.]]):gsub
local stream_options = {
ask = true,
disable_compact_history_messages = true,
memory = memory_content,
code_lang = "unknown",
provider = Providers[Config.provider],

View File

@@ -349,6 +349,7 @@ vim.g.avante_login = vim.g.avante_login
---@field update_snippets? string[]
---@field prompt_opts? AvantePromptOptions
---@field session_ctx? table
---@field disable_compact_history_messages? boolean
---
---@class AvanteLLMToolHistory
---@field tool_result? AvanteLLMToolResult