Skip to content

openai: support custom apply_patch Responses tools - #10

Draft
pd95 wants to merge 8 commits into
feature/responses-namespace-tools-upstreamfrom
feature/responses-custom-apply-patch-tool
Draft

pd95 wants to merge 8 commits into
feature/responses-namespace-tools-upstreamfrom
feature/responses-custom-apply-patch-tool

Conversation

@pd95

@pd95 pd95 commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary and motivation

Codex now exposes apply_patch as a Responses API custom/freeform tool. That
tool carries a patch as raw text, while Ollama's internal chat tool interface
uses JSON function arguments. Without a compatibility bridge, Ollama cannot
pass the declaration, model call, tool output, and continued conversation
through /v1/responses in the shapes expected by coding agents.

What this changes

This PR adds a deliberately narrow bridge for apply_patch:

  • converts a directly declared top-level custom tool into an internal function
    with one required string field, input;
  • exposes the expected free-form Lark grammar on the Responses wire format;
  • converts a valid generated patch into custom_tool_call events in streaming
    and non-streaming responses;
  • accepts custom_tool_call and custom_tool_call_output history so a client
    can execute the patch and continue the turn;
  • retains call/output pairs together during compaction, failing closed rather
    than preserving an orphaned half;
  • rejects nested declarations, dynamically discovered custom tools, and custom
    tool names other than apply_patch;
  • leaves malformed patch output visible through the ordinary fallback instead
    of silently discarding or misclassifying it.

The server translates protocol data only. It does not apply patches or execute
model-produced commands.

Dependency and scope

This PR depends on Responses namespace PR #8 and changes only Responses
request/output conversion, compaction, and focused middleware coverage.

Compare:
feature/responses-namespace-tools-upstream...feature/responses-custom-apply-patch-tool

Validation

Conversion, schema, grammar, collision, history, ordering, compaction,
malformed-output, streaming, and mixed-tool middleware tests pass. The required
Linux test/lint/build and integrated Darwin gates also pass.

Refresh and AI assistance

Adapted onto Ollama v0.34.0; head
4cec20fde16a9aac9ff800c7a77463e38b0fd2ed. The final commit repairs a test
fixture so it declares the custom tool it exercises. Codex materially assisted
implementation review, tests, refresh validation, and this PR description.

@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from 0ef6086 to a7cb2b3 Compare June 22, 2026 19:59
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from a7cb2b3 to 3eff875 Compare July 8, 2026 12:30
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from 3eff875 to c2cc216 Compare August 8, 2026 17:37
@pd95 pd95 changed the title openai: adapt custom apply_patch responses tool openai: support custom apply_patch Responses tools Aug 8, 2026
@pd95
pd95 changed the base branch from main to feature/responses-namespace-tools-upstream August 8, 2026 17:41
@pd95
pd95 marked this pull request as draft August 8, 2026 19:28
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from c2cc216 to 03f4f0e Compare August 12, 2026 15:26
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from 03f4f0e to 6400d1e Compare August 14, 2026 21:08
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch 2 times, most recently from 3f931fe to f75f4a1 Compare August 28, 2026 14:46
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from f75f4a1 to fd443f3 Compare August 31, 2026 05:38
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from fd443f3 to 261b9f4 Compare September 5, 2026 09:33
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from 261b9f4 to 4cec20f Compare September 14, 2026 06:09
@pd95
pd95 removed this pull request from stack #26 September 14, 2026 18:24
@pd95
pd95 added this pull request to stack #27 September 14, 2026 18:24
pd95 and others added 8 commits September 17, 2026 20:48
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@pd95
pd95 force-pushed the feature/responses-custom-apply-patch-tool branch from 4cec20f to 65e8803 Compare September 18, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant