Skip to content

fix(agents): patch tool schemas for Claude/Gemini compatibility - #785

Closed
hsrvc wants to merge 3 commits into
openclaw:mainfrom
hsrvc:fix/read-tool-schema-patch
Closed

hsrvc wants to merge 3 commits into
openclaw:mainfrom
hsrvc:fix/read-tool-schema-patch

Conversation

@hsrvc

@hsrvc hsrvc commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PR #768 introduced runtime normalization for Claude-style parameters (e.g., converting file_path -> path). However, it did not update the JSON Schema definitions for these tools.

As a result, strict schema validation (used by Gemini/Claude) rejects requests containing file_path before the runtime normalization logic is ever executed.

This PR fixes that by:

  1. Patching the Tool Schema: Explicitly updating the JSON Schema for read, write, and edit to accept file_path, old_string, and new_string as valid (optional) parameters.
  2. Making Original Params Optional: Relaxing the requirement for path etc. in the schema, since the alias is sufficient.

This "unlocks" the logic from PR #768, allowing it to function as intended.

Changes

  • Added patchToolSchemaForClaudeCompatibility in src/agents/pi-tools.ts.
  • Applied this patch to read, write, and edit tools.

Verification

  • Confirmed locally that read tool calls with file_path now pass schema validation.

Gemini Verification update (2026-01-12)

Confirmed effective against INVALID_ARGUMENT errors on gemini-3-pro-low.

  • Test: Captured successful tool use in live session logs where previous runs failed with validation loops.
  • Analysis: The read tool schema was confirmed to include file_path and have an empty required list in the actual payload sent to Gemini.
  • Result: The "Validation failed" loop is eliminated; Gemini can successfully call read using file_path without triggering a 400 error.

hsrvc added 3 commits January 12, 2026 14:53
Patches the read, write, and edit tool schemas to accept file_path, old_string, and new_string aliases. This ensures strict schema validation passes before the existing normalization logic runs.
@steipete

Copy link
Copy Markdown
Contributor
  • Blocking – patchToolSchemaForClaudeCompatibility drops all required
    fields for read/write/edit (src/agents/pi-tools.ts ~485). Schema now
    accepts empty params, so models can call edit without path/oldText/
    newText and we only fail at runtime. Better: keep required via anyOf/
    oneOf so either path or file_path (and old/new pairs) stays mandatory.
  • Nit – alias props are added as bare {type:"string"} (src/agents/pi-
    tools.ts ~500), losing descriptions/constraints from the canonical
    fields. Suggest cloning the original property shape when creating the
    alias.

@steipete

Copy link
Copy Markdown
Contributor

Re-implemented in main without merging this PR: added schema aliases for file_path/old_string/new_string, kept runtime required guards, and added regression tests + changelog. Closing since the fix landed on main in 2563040.

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