Skip to content

Conversation

@enyst
Copy link
Collaborator

@enyst enyst commented Nov 14, 2025

Summary

  • Implement ApplyPatch tool compatible with OpenAI GPT-5.1 apply_patch prompting format
  • Port reference logic from OpenAI cookbook (apply_patch.py) into openhands-tools/openhands/tools/apply_patch/core.py with type hints and safer IO injection
  • Add ToolDefinition and executor, registered as apply_patch
  • New example: examples/01_standalone_sdk/28_apply_patch_with_gpt5_1.py demonstrates creating/modifying/deleting FACTS.txt via tool using openai/gpt-5.1-codex-mini

Design notes

  • Follows existing Tool patterns (ToolDefinition, ToolAnnotations, executor). Enforces workspace root, rejects absolute/escaping paths
  • Core diff/patch logic is pure and injected with open/read/write/remove callables for testability
  • Observation returns message, fuzz metric, and Commit summary

Usage

  • Register default tools and include Tool(name="apply_patch") or rely on auto-registration
  • Example runs against direct OpenAI API (requires OPENAI_API_KEY):
    uv run python examples/01_standalone_sdk/28_apply_patch_with_gpt5_1.py

Responses API/tool-calling

  • GPT-5.1 models default to OpenAI Responses API in our SDK; some accounts require verified org for reasoning summaries and tool_output semantics. The example sets LLM.native_tool_calling=False to route via Chat Completions path for a straightforward tool loop, and avoids setting reasoning_summary

Testing performed

  • Pre-commit hooks (ruff/pydantic/pyright) pass on changed files
  • Ran the example; initial attempts with Responses path hit two known OpenAI errors (missing tool output in same request; org verification for reasoning.summary). Adjusted example + sdk to allow forcing Chat Completions path when native_tool_calling=False
  • Functional validation of parser and executor via local calls; example integrates end-to-end

Next steps

  • Optional: add apply_patch to default preset tools
  • Optional: more unit tests around fuzzy matching and multi-chunk edits

Co-authored-by: openhands [email protected]

@enyst can click here to continue refining the PR


Agent Server images for this PR

GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:1b9eb96-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-1b9eb96-python \
  ghcr.io/openhands/agent-server:1b9eb96-python

All tags pushed for this build

ghcr.io/openhands/agent-server:1b9eb96-golang-amd64
ghcr.io/openhands/agent-server:1b9eb96-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:1b9eb96-golang-arm64
ghcr.io/openhands/agent-server:1b9eb96-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:1b9eb96-java-amd64
ghcr.io/openhands/agent-server:1b9eb96-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:1b9eb96-java-arm64
ghcr.io/openhands/agent-server:1b9eb96-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:1b9eb96-python-amd64
ghcr.io/openhands/agent-server:1b9eb96-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-amd64
ghcr.io/openhands/agent-server:1b9eb96-python-arm64
ghcr.io/openhands/agent-server:1b9eb96-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-arm64
ghcr.io/openhands/agent-server:1b9eb96-golang
ghcr.io/openhands/agent-server:1b9eb96-java
ghcr.io/openhands/agent-server:1b9eb96-python

About Multi-Architecture Support

  • Each variant tag (e.g., 1b9eb96-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 1b9eb96-python-amd64) are also available if needed

enyst and others added 2 commits November 14, 2025 06:44
…tch format\n\n- Port reference parser/applicator into core module\n- Integrate as ToolDefinition with executor and safe workspace I/O\n- New example using openai/gpt-5.1-codex-mini to create/modify/delete FACTS.txt via tool\n\nCo-authored-by: openhands <[email protected]>
…1 example; keep reasoning_summary=None to avoid org verification

Co-authored-by: openhands <[email protected]>
@enyst enyst marked this pull request as draft November 14, 2025 07:14
@enyst enyst changed the title feat(tools): Add ApplyPatch tool (GPT-5.1 apply_patch) + example using openai/gpt-5.1-codex-mini feat(tools): Add ApplyPatch tool (GPT-5.1 apply_patch) Nov 14, 2025
enyst and others added 6 commits November 14, 2025 07:41
…example: run gpt-5.1-codex-mini end-to-end

- Override to_responses_tool() to return minimal {type:function, name}
- Add validation_alias/serialization_alias so server-sent 'patch' is accepted
- Update example to register ApplyPatch and run create/modify/delete FACTS.txt

Co-authored-by: openhands <[email protected]>
…ix example tool registration

- Add AliasChoices to accept server arg name 'patch'
- Provide minimal parameters in to_responses_tool to steer Responses tools
- Example: remove register_default_tools; import classes to register

Co-authored-by: openhands <[email protected]>
…input; send only tool outputs

- Remove assistant function_call emission in Message.to_responses_dict
- Stop passing back previous turn 'reasoning' items to avoid ordering errors
- This aligns with OpenAI Responses pattern: client supplies only function_call_output

Co-authored-by: openhands <[email protected]>
…assthrough

- Keep assistant function_call in input so paired tool outputs validate
- Do not echo prior 'reasoning' items to avoid ordering constraints

Co-authored-by: openhands <[email protected]>
- Capture design choices, telemetry observations, and pending items
- Reference PR #1166 and branch name for continuity

Co-authored-by: openhands <[email protected]>
…tant function_call in input

- Reinstate reasoning passthrough to satisfy existing unit tests
- Keep assistant function_call items and pair with tool outputs in same request

Co-authored-by: openhands <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/llm/utils
   telemetry.py1537153%58–61, 67–69, 104, 110, 119, 123, 126, 131–132, 167, 171, 178, 200, 204–205, 213–215, 221, 238–240, 242–244, 246, 254–255, 260–261, 266–273, 276–279, 284, 289, 292, 297, 300, 306, 312, 314, 317–318, 323, 328–332, 339–340, 343, 345, 348–351
openhands-tools/openhands/tools/apply_patch
   core.py30125116%40–46, 51–52, 56–57, 62–63, 91–95, 98–101, 104–110, 113–122, 124–133, 136–146, 149, 152–154, 163–179, 182–188, 191–195, 197–205, 208–209, 212–217, 226–227, 229–233, 236–238, 241–242, 248–254, 260–268, 278–292, 294–298, 305–315, 322–329, 333–334, 339, 341, 346–347, 351–358, 362–369, 373–374, 378–394, 398–401, 404–405, 408–410, 416, 424–427, 435–445, 447, 460–466
   definition.py522846%71, 75, 80–82, 91–94, 96–100, 102–104, 106–107, 112–113, 115, 118–120, 140–141, 169
TOTAL12613597952% 

enyst and others added 3 commits November 14, 2025 08:39
…_output ids

- Fix imports and formatting for pre-commit

Co-authored-by: openhands <[email protected]>
…esponses notes

- FileEditor example mirrors ApplyPatch for log comparison
- Notes: restore reasoning passthrough; pair assistant calls with tool outputs

Co-authored-by: openhands <[email protected]>
…t; fix pairing error.

Telemetry: trim system instructions from logs and compact tool metadata for readability.

Co-authored-by: openhands <[email protected]>
@enyst enyst force-pushed the feat/apply-patch-tool-gpt5-1 branch from 9a9234e to e910dbf Compare November 14, 2025 20:19
enyst and others added 2 commits November 14, 2025 20:24
… rejection.\n\nAligned expected newline behavior with upstream apply_patch (no enforced trailing newline).\n\nCo-authored-by: openhands <[email protected]>
@enyst enyst force-pushed the feat/apply-patch-tool-gpt5-1 branch from 17d2380 to e772cbb Compare November 14, 2025 21:31
enyst and others added 6 commits November 14, 2025 21:33
…ross action and executor.

- Update tests to pass 'patch' field
- Keep Responses tool schema minimal with required 'patch'

Co-authored-by: openhands <[email protected]>
…via Tool(name="apply_patch").

Co-authored-by: openhands <[email protected]>
@openhands-ai
Copy link

openhands-ai bot commented Nov 15, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Check Documented Examples

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1166 at branch `feat/apply-patch-tool-gpt5-1`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

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.

2 participants