Skip to content

[tools] Add apply_patch tool - #2303

Merged
dylan-hurd-oai merged 6 commits into
mainfrom
dh--apply-patch-tool
Aug 15, 2025
Merged

dylan-hurd-oai merged 6 commits into
mainfrom
dh--apply-patch-tool

Conversation

@dylan-hurd-oai

@dylan-hurd-oai dylan-hurd-oai commented Aug 14, 2025 •

Copy link
Copy Markdown
Contributor

Summary

We've been seeing a number of issues and reports with our synthetic apply_patch tool, e.g. #802. Let's make this a real tool - in my anecdotal testing, it's critical for GPT-OSS models, but I'd like to make it the standard across GPT-5 and codex models as well.

Testing

  • Tested locally
  • Follow-up: Add an integration test

@github-actions

Copy link
Copy Markdown
Contributor

Summary
This PR adds an “apply_patch” tool as a first-class OpenAI tool, wires it through config/overrides and MCP server parameters, and enables it for the gpt-oss model family. It also threads a new config flag (include_apply_patch_tool) across core, exec, tui, and mcp-server.

Notable changes

  • core/openai_tools.rs: adds apply_patch tool schema and ApplyPatchToolArgs; includes tool selection in ToolsConfig and get_openai_tools.
  • core/codex.rs: handles apply_patch function calls by invoking the apply_patch command with the patch payload.
  • core/config.rs: adds include_apply_patch_tool and propagates it via ConfigOverrides; defaults to model family behavior.
  • core/model_family.rs: introduces uses_apply_patch_tool; enables for gpt-oss.
  • exec, tui, mcp-server: plumb include_apply_patch_tool through overrides and wire formats.

Review
Overall direction looks good and consistent with existing tool patterns. A couple schema/consistency issues need fixing before merge.

  • codex-rs/core/src/openai_tools.rs (create_apply_patch_tool): parameters.required uses "patch" but the single property is "input". This breaks strict validation/use. Change required to ["input"].
  • codex-rs/core/src/codex.rs (handle_function_call “apply_patch”): comment says “expect a single string field patch” but code parses ApplyPatchToolArgs { input }. Update the comment to reference input.
  • codex-rs/core/config.rs (unknown model fallback): new fallback ModelFamily { uses_apply_patch_tool: true } could surprise users by enabling the tool for unknown slugs. Consider defaulting this to false unless there’s a strong reason to prefer the tool.
  • Tests: consider adding a test asserting the tool list includes "apply_patch" when (a) include_apply_patch_tool = true and (b) for a uses_apply_patch_tool = true model (e.g., gpt-oss), plus a round-trip parse test for ApplyPatchToolArgs with the "input" key.
  • Minor: ensure the long apply_patch description remains concise enough for models (current text is thorough; acceptable, but keep an eye on token budget).

View workflow run

@dylan-hurd-oai

Copy link
Copy Markdown
Contributor Author

Fair enough rust review bot!

codex-rs/core/src/openai_tools.rs (create_apply_patch_tool): parameters.required uses "patch" but the single property is "input". This breaks strict validation/use. Change required to ["input"].

Done!

codex-rs/core/src/codex.rs (handle_function_call “apply_patch”): comment says “expect a single string field patch” but code parses ApplyPatchToolArgs { input }. Update the comment to reference input.

Comment removed

codex-rs/core/config.rs (unknown model fallback): new fallback ModelFamily { uses_apply_patch_tool: true } could surprise users by enabling the tool for unknown slugs. Consider defaulting this to false unless there’s a strong reason to prefer the tool.

I strongly suspect that custom models will do better with this setup, but we can let it bake for a few days.

Tests: consider adding a test asserting the tool list includes "apply_patch" when (a) include_apply_patch_tool = true and (b) for a uses_apply_patch_tool = true model (e.g., gpt-oss), plus a round-trip parse test for ApplyPatchToolArgs with the "input" key.

Round-trip test marked for follow-up

@aibrahim-oai aibrahim-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have integration tests of the model sending multiple apply patches and then we test that expected behavior is happening

@dylan-hurd-oai
dylan-hurd-oai merged commit 6df8e35 into main Aug 15, 2025
@dylan-hurd-oai
dylan-hurd-oai deleted the dh--apply-patch-tool branch August 15, 2025 15:55
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants