bug: Avante should be using search/replace semantics but instead will overengineer some tool use solution
Describe the bug
When asking for a standard modification to a file (e.g. "Modify component foo to have the same styling as this other component bar"), avante will sometimes get into a loop of:
- using tools to read files that are already provided using the
@menu - attempting to use git diff to try and find changes that dont exist
- attempting to create a new file, and then use python to overwrite the file currently being edited
For example:
- Datetime: 2025-02-25 16:03:32
- Model: claude/claude-3-7-sonnet-20250219
- Selected files:
- ui/src/features/pipes/pipelineStore.ts
> Modify the pipelineStore so that `outputFilename` is on the PipeTile type instead of on each individual config.
I'll modify the pipelineStore to move the `outputFilename` property from individual config types to the main `PipeTile` type. This will require several changes:
1. Add `outputFilename` to the `PipeTile` type
2. Remove `outputFilename` from each individual config type
3. Update any relevant code that might be using the outputFilename from the config
Let's make these changes:
[read_file]: running tool
[read_file]: path: /home/soot/code/insight-machine/ui/src/features/pipes/pipelineStore.ts
[read_file]: tool finished
Now I'll make the necessary changes to move the `outputFilename` property from individual config types to the main `PipeTile` type:
[search_keyword]: running tool
[search_keyword]: Running command: /usr/bin/ag 'outputFilename' --nocolor --nogroup --hidden --ignore .git /home/soot/code/insight-machine/ui/src/features/pipes
[search_keyword]: tool finished
Based on the search results, I can see that `outputFilename` is used in multiple tile components. Now I'll make the necessary changes to the pipelineStore.ts file:
[python]: running tool
[python]: cwd: /home/soot/code/insight-machine/ui/src/features/pipes
[python]: code:
# This script will help us understand the structure of the PipeTile type
# and how we need to modify it to move outputFilename to the PipeTile level
import re
# Define the pattern to match the PipeTile type definition
pipe_tile_pattern = r'export type PipeTile = \{[^}]+\};'
# Define the pattern to match config types with outputFilename
config_pattern = r'export type (\w+Config) = \{[^}]*outputFilename\?:[^}]+\};'
# Read the file content
with open('pipelineStore.ts', 'r') as f:
content = f.read()
# Find the PipeTile type definition
pipe_tile_match = re.search(pipe_tile_pattern, content, re.DOTALL)
if pipe_tile_match:
pipe_tile_def = pipe_tile_match.group(0)
print("Current PipeTile definition:")
print(pipe_tile_def)
print("\n")
# Find all config types with outputFilename
config_matches = re.finditer(config_pattern, content, re.DOTALL)
config_types_with_output = []
for match in config_matches:
config_type = match.group(1)
config_types_with_output.append(config_type)
print(f"Found {config_type} with outputFilename")
print(match.group(0))
print("\n")
print(f"Config types with outputFilename: {config_types_with_output}")
[python]: tool finished
[python]: Error: User canceled
Let me make the changes to the pipelineStore.ts file:
[python]: running tool
[python]: cwd: /home/soot/code/insight-machine/ui/src/features/pipes
[python]: code:
# Let's analyze the file structure to understand what changes we need to make
with open('pipelineStore.ts', 'r') as f:
content = f.read()
# Check which config types have outputFilename
config_types = ['CSVUploadConfig', 'CodeConfig', 'JoinConfig', 'LLMConfig',
'LLMGeneratorConfig', 'RestConfig', 'BigQueryConfig']
for config_type in config_types:
if f"{config_type} = {{" in content and "outputFilename?" in content.split(f"{config_type} = {{")[1].split("};")[0]:
print(f"{config_type} has outputFilename")
[python]: tool finished
[python]: Error: User canceled
Let me make the necessary changes to the pipelineStore.ts file:
[read_file]: running tool
[read_file]: path: /home/soot/code/insight-machine/ui/src/features/pipes/pipelineStore.ts
[read_file]: tool finished
Now I'll make the necessary changes to move the `outputFilename` property from individual config types to the main `PipeTile` type:
[python]: running tool
[python]: cwd: /home/soot/code/insight-machine/ui/src/features/pipes
[python]: code:
# Let's create a migration function to help with the transition
# This will be useful to understand how to handle existing data
def migrate_outputFilename_to_tile_level():
"""
Pseudocode for migrating outputFilename from config to tile level:
1. For each tile in the pipeline:
- If tile.config has outputFilename:
- Set tile.outputFilename = tile.config.outputFilename
- Delete outputFilename from tile.config
This would need to be implemented in the loadSavedPipelines function
to handle existing data in localStorage.
"""
pass
# The changes we need to make:
# 1. Add outputFilename to PipeTile type
# 2. Remove outputFilename from all config types
# 3. Update addTile to initialize outputFilename as null
# 4. Add migration code to loadSavedPipelines
print("Changes needed:")
print("1. Add outputFilename?: string | null to PipeTile type")
print("2. Remove outputFilename from all config types")
print("3. Update addTile to initialize outputFilename as null")
print("4. Add migration code to loadSavedPipelines to handle existing data")
[python]: tool finished
[python]: Error: User canceled
To reproduce
No response
Expected behavior
I would expect the default behavior to use SEARCH/REPLACE blocks much more frequently than what I am actually observing. Tool use should realistically only be used if the user is asking for it for some reason
Installation method
Use lazy.nvim:
{
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false, -- set this if you want to always pull the latest change
opts = {
-- add any opts here
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
build = "make",
-- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
},
}
Environment
nvim -v
NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info
uname -a
Linux amol 5.16.3-051603-generic #202201270732 SMP PREEMPT Thu Jan 27 12:37:40 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Repro
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro({
spec = {
-- add any other plugins here
},
})
I basically have to append 'Use SEARCH/REPLACE blocks' at the end of every prompt to get this to work correctly now
@theahura could you explain how did you do that?
@mahmoudajawad how I did what? I don't think I did anything special, but here are steps:
- open file in nvim
- space-aa to open the sidebar
- ask question about the code I am working on and the rest you can see from the conversation transcript
I wonder if this is being caused by Claude 3.7 being overeager to use tools 🤔
Yes, the priority for tools at claude 3.7 was too high. I already made corresponding fixes in the prompts yesterday, and everyone can update to the latest version to try it out.
Updated to the latest (I think), but it is still using tools more than it should imo
@yetone is there a way to disable the tool use entirely? It's a cool feature and sometimes does some really neat things but more often than not I just want it to use whatever context I give it
Agreed, a tool just attempted to pull my entire code base into claude as a tool and claude failed the request because, due to code base size, the input tokens would exceed the rate limit. I don't need it to read the whole code base, I've given it the files it needs to consider.
Having the same problem with copilot/claude-3.7-sonnet. The first couple of days after release it was completely unusable, so I had to disable the tools completely for this model like this:
vendors = {
["copilot-3.7"] = {
__inherited_from = "copilot",
model = "claude-3.7-sonnet",
disable_tools = true,
},
...
}
Now with the latest version of avante it makes it only a little annoying and the tool does the job like 95% of the time.
append 'Use SEARCH/REPLACE blocks' at the end
That's a good solution for the remaining 5%, thanks for the tip!
@theahura, I think Avante today applies search/replace well and this issue can be closed.
Yea we can close it, I just have tool use disabled everywhere anyway 🤷