fix(rig-gemini-grpc): populate FunctionDeclaration.parameters from ToolDefinition#1763
Open
abhicris wants to merge 1 commit into
Open
fix(rig-gemini-grpc): populate FunctionDeclaration.parameters from ToolDefinition#1763abhicris wants to merge 1 commit into
abhicris wants to merge 1 commit into
Conversation
…olDefinition
create_grpc_request mapped ToolDefinition into proto::FunctionDeclaration
but forwarded only `name` and `description`, leaving `parameters` at the
default `None`. Every tool was therefore sent to Gemini with no argument
shape, degrading tool calls to argument-less invocations.
Add a small JSON Schema -> proto::Schema converter local to this crate
(no rig-core leak), and pipe `tool.parameters` through it inside
create_grpc_request. The empty-object schema
({"type": "object", "properties": {}}) still resolves to None to avoid
emitting a vacuous schema, matching the convention used by
rig-core::providers::gemini::completion.
Tests cover the empty/null shortcut, scalar object properties with
required, typed array items, string enums, and a request-level
assertion that exercises create_grpc_request end-to-end and would have
caught the original regression.
cargo test -p rig-gemini-grpc --lib
10 passed; 0 failed; 0 ignored
cargo clippy -p rig-gemini-grpc --all-targets
clean
Fixes 0xPlaygrounds#1710
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.
Why
create_grpc_requestbuildsproto::FunctionDeclarationfrom arig_core::completion::ToolDefinition, but only forwardsnameanddescription. TheToolDefinition.parametersJSON schema is silently dropped, so Gemini receives every tool with no argument shape. In practice this turns every tool call into an argument-less invocation, which surfaces as the model either omitting required args or guessing.The proto already exposes the destination field:
Fixes #1710. Same field present in
rig-gemini-grpc 0.2.0through the current0.2.5.What
Add a small JSON Schema →
proto::Schemaconverter (json_value_to_proto_schema/tool_parameters_to_proto_schema) local torig-gemini-grpc::completion, and pipetool.parametersthrough it where theFunctionDeclarationis built.Conventions chosen to match the existing
rig-core::providers::geminiimplementation:{"type": "object", "properties": {}}(the defaultToolDefinition.parametersfor argument-less tools) is mapped toNonerather than a vacuousSchema, so we don't emitproperties: {}to the API for tools that genuinely take no arguments.Nullinput also maps toNone.type/format/description/nullable/enum/items/properties/requiredare mapped 1:1; recursion handles nested arrays/objects.rig-coreschema-helper leak) and uses onlyserde_json+ the generatedprototypes, so it doesn't widen the public API.How validated
Five new unit tests in
crates/rig-gemini-grpc/src/completion.rs:tool_params_empty_object_maps_to_none— preserves the existing "no-args" convention.tool_params_null_maps_to_none— defensive coverage for aNullparameters value.tool_params_object_with_scalar_properties_round_trips— checkstype,required, nestedpropertiestypes and descriptions.tool_params_array_with_typed_items— recursiveitemshandling.tool_params_enum_strings_preserved— stringenumround-trip.create_grpc_request_populates_tool_parameters— end-to-end regression test that drivescreate_grpc_requestwith aToolDefinitionand assertsFunctionDeclaration.parametersis populated with the expected typed schema. This is the test that would have caught the original bug.Out of scope
FunctionDeclaration.parameters_json_schema(field 6) — Gemini's newer JSON-Schema-passthrough field. The typedSchemapath is whatrig-core::providers::geminiuses today, so this PR stays on that path for consistency. A follow-up could add an opt-in to send the raw JSON schema asparameters_json_schemafor callers that want to bypass the type mapping.FunctionDeclaration.response(field 4) — tool response schemas. Not currently carried onToolDefinition; out of scope here.anyOf/oneOf/allOf) —rig-core::providers::geminihas additional flattening for these; the gRPC path can follow if real-world tools start tripping it, but bug(rig-gemini-grpc): tool parameter schemas dropped from FunctionDeclaration #1710's reproduction doesn't require it.