edit#
Build typed tools from annotations and docstrings. See the guide.
Edit an existing UTF-8 file by replacing exact text; always use this tool to modify a file.
Parameters#
{
"additionalProperties": false,
"properties": {
"file_path": {
"minLength": 1,
"type": "string",
"description": "Absolute path or a path relative to the current working directory."
},
"old_string": {
"minLength": 1,
"type": "string",
"description": "The exact text to replace, copied from the file as it is now."
},
"new_string": {
"type": "string",
"description": "The text to put in its place; an empty string deletes the match."
},
"replace_all": {
"default": false,
"type": "boolean",
"description": "Replace every occurrence of old_string instead of insisting it appears once."
}
},
"required": [
"file_path",
"old_string",
"new_string"
],
"type": "object"
}
Model-facing snippet#
edit(file_path="notes/plan.md", old_string="Draft", new_string="Final")
edit(file_path="notes/plan.md", old_string="Total", new_string="Sum", replace_all=True)
Guidelines#
Always use this tool when you need to modify an existing file, instead of sed, awk, perl -i, python -c, tee, or shell redirection. Reserve those for bulk or mechanical rewrites this tool cannot express, such as renaming a symbol across many files.
One change a call: call edit again for the next change, and nothing is written when the old text does not match.
Avoid sed, cat, and similar shell commands for reading or changing files unless it is necessary; inspect files with read_file, grep, and glob, and change them with this tool.
Read the target lines first and copy old_string exactly: same indentation, quotes, and line breaks; a read’s line number and tab are not part of the file.
Make old_string unique by including a neighbouring line or two; set replace_all only when every occurrence must change.
An edit writes the file with LF line breaks, so a CRLF file becomes LF and a CRLF checkout shows the edit as a whole-file diff.
When an edit fails, read the file again and retry with corrected old_string rather than switching to a shell command.
- zett_agent.tools.files.edit#
A tool is a name, an input schema, and an async callable.
- Parameters:
arguments (Mapping[str, Any])
- Return type:
Direct Python calls use await tool(arguments_mapping). The snippet
above describes model-facing invocation syntax, not the Python call signature.