Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gemini-live-property-ordering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents-plugin-google': patch
---

Send `propertyOrdering` in Gemini Live tool schemas so tool arguments are generated in declared order.
19 changes: 19 additions & 0 deletions plugins/google/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,29 @@ describe('Gemini function declarations', () => {
expect(declaration.parameters).toEqual({
type: 'object',
properties: { fields: { type: 'object' } },
propertyOrdering: ['fields'],
required: ['fields'],
});
});

it('keeps declared property order on the Live API, nested objects included', () => {
const decide = llm.tool({
name: 'decide',
description: 'Reason first, then answer.',
parameters: z.object({
reasoning: z.string(),
answer: z.enum(['a', 'b']),
detail: z.object({ why: z.string(), confidence: z.number() }),
}),
execute: async () => {},
});
const parameters = singleDeclaration(new llm.ToolContext([decide]), false).parameters!;

expect(parameters.propertyOrdering).toEqual(['reasoning', 'answer', 'detail']);
expect(parameters.properties!.detail!.propertyOrdering).toEqual(['why', 'confidence']);
expect(parameters.properties!.reasoning!.propertyOrdering).toBeUndefined();
});

it('omits the schema for a function tool without parameters', () => {
const toolCtx = new llm.ToolContext([ping]);
const textDeclaration = singleDeclaration(toolCtx);
Expand Down
4 changes: 4 additions & 0 deletions plugins/google/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export function convertJSONSchemaToOpenAPISchema(jsonSchema: JSONSchema7Definiti
},
{} as Record<string, unknown>,
);
// Gemini generates an OpenAPI schema's properties alphabetically unless told
// otherwise; keep the declared order so earlier fields can inform later ones.
const keys = Object.keys(properties);
if (keys.length > 0) result.propertyOrdering = keys;
}

if (items) {
Expand Down