内置工具
apply_patch 工具
使用结构化补丁格式应用文件更改。这非常适合多文件
或多区块编辑,因为使用单个 edit 调用会很脆弱。
该工具接受单个 input 字符串,其中封装一个或多个文件操作:
*** Begin Patch*** Add File: path/to/file.txt+第 1 行+第 2 行*** Update File: src/app.ts@@ 可选的更改上下文-旧行+新行*** Delete File: obsolete.txt*** End Patch参数
input(必需):完整的补丁内容,包括*** Begin Patch和*** End Patch。
注意事项
- 补丁路径支持相对路径(相对于工作区目录)和绝对路径。
tools.exec.applyPatch.workspaceOnly默认为true(限制在工作区内)。仅当你有意让apply_patch在工作区目录之外写入/删除时,才将其设置为false。- 在
*** Update File:区块内使用*** Move to:来重命名文件。 *** End of File在需要时标记仅在 EOF 处插入。- 默认对每个模型启用。设置
tools.exec.applyPatch.enabled: false可将其禁用,或使用tools.exec.applyPatch.allowModels将其限制为特定模型(接受gpt-5.4这样的原始 ID,或openai/gpt-5.4这样的完整 ID)。 - 配置位于
tools.exec.applyPatch.*下。
示例
{ "tool": "apply_patch", "input": "*** Begin Patch\n*** Update File: src/index.ts\n@@\n-const foo = 1\n+const foo = 2\n*** End Patch"}相关内容
Was this useful?