内置工具

apply_patch 工具

使用结构化补丁格式应用文件更改。这非常适合多文件 或多区块编辑,因为使用单个 edit 调用会很脆弱。

该工具接受单个 input 字符串,其中封装一个或多个文件操作:

text
*** 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.* 下。

示例

json
{  "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?
On this page

On this page