智能体工具

编辑编辑编辑编辑

edit({ path, old_string, new_string, replace_all? })

替换文件中的精确字符串。 它必须完全匹配, 包括空白, 并且要独一无二, 除非您另有表示 。

category: writeexact matchkeeps the old version
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

pathstring必填

档案

old_stringstring必填

替换什么。 包括空格的精密空白 。

new_stringstring必填

装什么

replace_allbooleanfalse

替换每次发生的情况,而不是要求发生的情况。

先读文件

缩进是匹配的一部分

从内存而非文件复制的字符串通常因空格或制表符而不同,编辑失败。编辑前的读指令为此原因在系统中提示,失败的编辑成本则转弯。

除非 replace_all

拒绝出现两次的字符串 : 替换两个相同段落中的一条是模糊的, 并且猜出哪个比失败更糟。 添加更多周围的上下文使其独一, 或设置 replace_all.

在一个文件中进行多个编辑

使用使用 multi_edit:一个电话,按顺序应用,要么全部,要么全部,要么全部。 edit 每人一个文件成本 转一个转。