fix(google): keep declared property order in Gemini Live tool schemas - #2537
Open
CodeWithMoin wants to merge 1 commit into
Open
CodeWithMoin wants to merge 1 commit into
CodeWithMoin wants to merge 1 commit into
Conversation
The Live API path converts tool parameters to Gemini's OpenAPI Schema, which never carried propertyOrdering, so Gemini generated tool arguments alphabetically. A field meant to be written first (reasoning) could come after the field it should inform (answer). Emit propertyOrdering from each object schema's own key order, nested objects included. The text API already sends parametersJsonSchema and is unchanged. Fixes livekit#2529
🦋 Changeset detectedLatest commit: deffd30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Description
Fixes #2529. Gemini Live was generating tool arguments in alphabetical order, not the order the tool declares them. So a
reasoningfield meant to come first got written afteranswer, the field it's supposed to inform.The Live path (
useParametersJsonSchema: false) converts parameters to Gemini's OpenAPISchema, and that schema never carriedpropertyOrdering. Gemini sorts properties alphabetically without it. We now emit it from each object's own key order, nested objects included.The text API already sends
parametersJsonSchema(#2516) and is untouched.Changes Made
plugins/google/src/utils.ts:convertJSONSchemaToOpenAPISchemasetspropertyOrderingwhenever an object has properties. It recurses, so nested objects get it too.plugins/google/src/utils.test.ts: new test for a{ reasoning, answer, detail: { why, confidence } }tool on the Live path, checking top-level and nested order and that non-object fields get no ordering. The existing Live API assertion now includespropertyOrdering..changeset/gemini-live-property-ordering.md: patch for@livekit/agents-plugin-google.Pre-Review Checklist
Testing
restaurant_agent.tsandrealtime_agent.tswork properly (for major changes): not a major changeWithout the fix, the new test and the updated Live API test both fail. With it, all pass.
Additional Notes
Google docs on this: https://ai.google.dev/gemini-api/docs/structured-output#property-ordering