diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua
index d16f8c0..111749c 100644
--- a/lua/avante/sidebar.lua
+++ b/lua/avante/sidebar.lua
@@ -1638,7 +1638,11 @@ function Sidebar:create_input_container(opts)
then
break
end
- table.insert(history_messages, 1, { role = "assistant", content = entry.original_response })
+ table.insert(
+ history_messages,
+ 1,
+ { role = "assistant", content = Utils.trim_think_content(entry.original_response) }
+ )
local user_content = ""
if entry.selected_file ~= nil then
user_content = user_content .. "SELECTED FILE: " .. entry.selected_file.filepath .. "\n\n"
diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua
index ab252f0..23c1079 100644
--- a/lua/avante/utils/init.lua
+++ b/lua/avante/utils/init.lua
@@ -858,4 +858,6 @@ end
function M.is_same_file(filepath_a, filepath_b) return M.uniform_path(filepath_a) == M.uniform_path(filepath_b) end
+function M.trim_think_content(content) return content:gsub("^.-", "", 1) end
+
return M
diff --git a/tests/utils/init_spec.lua b/tests/utils/init_spec.lua
index ba7b85e..71caf4e 100644
--- a/tests/utils/init_spec.lua
+++ b/tests/utils/init_spec.lua
@@ -121,6 +121,38 @@ describe("Utils", function()
end)
end)
+ describe("trim_think_content", function()
+ it("should remove think content", function()
+ local input = "this should be removed Hello World"
+ assert.equals(" Hello World", Utils.trim_think_content(input))
+ end)
+
+ it("The think tag that is not in the prefix should not be deleted.", function()
+ local input = "Hello this should not be removed World"
+ assert.equals("Hello this should not be removed World", Utils.trim_think_content(input))
+ end)
+
+ it("should handle multiple think blocks", function()
+ local input = "firstmiddlesecond"
+ assert.equals("middlesecond", Utils.trim_think_content(input))
+ end)
+
+ it("should handle empty think blocks", function()
+ local input = "testtest"
+ assert.equals("testtest", Utils.trim_think_content(input))
+ end)
+
+ it("should handle empty think blocks", function()
+ local input = "testtest"
+ assert.equals("testtest", Utils.trim_think_content(input))
+ end)
+
+ it("should handle input without think blocks", function()
+ local input = "just normal text"
+ assert.equals("just normal text", Utils.trim_think_content(input))
+ end)
+ end)
+
describe("debounce", function()
it("should debounce function calls", function()
local count = 0