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": {
"path": {
"minLength": 1,
"type": "string",
"description": "Absolute path or a path relative to the current working directory."
},
"edits": {
"description": "Ordered edits applied in one call; each one replaces exact text once, or every match when it sets replace_all. Pass a single-element list for one change.",
"items": {
"additionalProperties": false,
"description": "One exact-text edit applied to a file.\n\nBy default ``old_text`` must appear exactly once in the current text, so\ninclude the surrounding characters that make it unique. Set ``replace_all``\nwhen every occurrence should change. ``new_text`` may be empty to delete the\nmatched text.",
"properties": {
"old_text": {
"description": "Exact text to find",
"minLength": 1,
"title": "Old Text",
"type": "string"
},
"new_text": {
"default": "",
"description": "Replacement text; an empty value deletes the match",
"title": "New Text",
"type": "string"
},
"replace_all": {
"default": false,
"description": "Whether every exact match should be replaced",
"title": "Replace All",
"type": "boolean"
}
},
"required": [
"old_text"
],
"title": "FileEdit",
"type": "object"
},
"minItems": 1,
"title": "Edits",
"type": "array"
}
},
"required": [
"path",
"edits"
],
"title": "ToolInput",
"type": "object"
}
Model-facing snippet#
edit(path="notes/plan.md", edits=[{"old_text": "Draft", "new_text": "Final"}])
edit(path="notes/plan.md", edits=[{"old_text": "First", "new_text": "1st"}, {"old_text": "Second", "new_text": "2nd", "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.
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 with read_file first and copy old_text exactly: same indentation, quotes, and line breaks.
Make old_text unique by including a neighbouring line or two; set replace_all only when every occurrence must change.
Send every change for the file in one call: edits apply in order, each one sees the previous result, and nothing is written if any edit fails.
When an edit fails, read the file again and retry with corrected old_text rather than switching to a shell command.
- zett_agent.tools.coding.edit#
A tool is a name, an input schema, and an async callable.
- 参数:
arguments (Mapping[str, Any])
- 返回类型:
Direct Python calls use await tool(arguments_mapping). The snippet
above describes model-facing invocation syntax, not the Python call signature.