Repository navigation
Use parametersJsonSchema for function declarations and preserve Gemini call IDs - #51
Merged
Merged
Conversation
Build function declarations from known fields only, so newer fields
like `annotations` from php-ai-client 1.5.0 are not sent to Google.
Send schema maps such as `properties` and `$defs` as JSON objects.
This fixes empty maps and maps with numeric keys, which PHP encodes
as JSON lists. Empty sub-schemas are sent as `{}` too.
Simplify function call ID handling and add tests for missing,
null and invalid IDs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
saarnilauri
approved these changes
Oct 19, 2026
saarnilauri
left a comment
Contributor
There was a problem hiding this comment.
Thank you for carrying on the work. This LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fixes #50.
Fixes #33.
Supersedes #45 and #35.
This PR builds on the commits from #45 by @superdav42 and addresses the review feedback from @saarnilauri.
parametersJsonSchemafield instead of the legacyparametersfield.uniqueItems,additionalProperties, type unions and booleanenumvalues.properties,$defs,definitionsandpatternPropertiesas JSON objects. This covers empty maps and maps with numeric keys like'0', which PHP would otherwise encode as lists. Empty sub-schemas are sent as{}.name,description,parametersJsonSchema). Newer fields likeannotationsfrom php-ai-client 1.5.0 are not sent to Google.Why?
The legacy
parametersfield only accepts a subset of OpenAPI. Google rejects the whole request when one tool uses an unsupported keyword. For example, thecore/users-queryability failed because ofuniqueItemsand"enum": [true].PHP encodes an empty array as
[]. Google expects an object forproperties, so it returns400 value for properties at top-level must be an object. One ability with no parameters was enough to break every request that included tools.Google also rejects unknown fields in function declarations. php-ai-client 1.5.0 adds
annotationstoFunctionDeclaration::toArray(), so forwarding that array as-is would break requests once annotations are used.Testing
composer testpasses with php-ai-client 1.5.0 and 1.3.1. The annotations test is skipped on 1.3.1.composer lintpasses (PHPCS and PHPStan).core/users-querycases, empty and nested empty schemas, numeric property names, leaving out annotations, and missing, null or invalid function call IDs.Follow-up
Structured output still uses
responseSchemawith the same OpenAPI subset. Switching it toresponseJsonSchemawill be a separate PR.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Opus 5.5, GPT-6-Astra
Used for: Reviewing #45 and its feedback, drafting the schema normalization, tests and this description. I reviewed and edited the final code and tests and take responsibility for them.