Skip to content

Fix: Prevent integer to float conversion for tool parameters invoked via agent skills#2845

Closed
pavankrishna13 wants to merge 1 commit into
googleapis:mainfrom
pavankrishna13:Bug-fix-for-issue-with-integer-parameter-through-agent-skills
Closed

Fix: Prevent integer to float conversion for tool parameters invoked via agent skills#2845
pavankrishna13 wants to merge 1 commit into
googleapis:mainfrom
pavankrishna13:Bug-fix-for-issue-with-integer-parameter-through-agent-skills

Conversation

@pavankrishna13

Copy link
Copy Markdown
Contributor

Description

This PR addresses a bug where tools fail to execute due to a type mismatch error when integer parameters are provided. Crucially, this issue only occurs when the tool is invoked through agent skills; it does not happen when the tools are executed directly. When an agent skill routes a payload via the Gemini CLI, JSON integers are incorrectly unmarshalled as floats before being passed down to the underlying tool.

Steps to Reproduce:

Activate an agent skill (e.g., cloud-sql-postgres-data from the cloud-sql-postgresql extensions) via the Gemini CLI.

Invoke a tool that requires an integer parameter (like list_indexes) using a natural language prompt, such as:

"List all the indexes in the database, max limit of rows is 2"

The Gemini CLI agent internally constructs and executes the following command:

node /usr/local/google/home/pavanrampalli/.gemini/extensions/cloud-sql-postgresql/skills/cloud-sql-postgres-data/scripts/list_indexes.js '{"limit": 2}'
The execution fails because the tool expects an integer for the limit parameter, but the agent's request parser has converted and passed it as a float.

Root Cause:
Upon investigation of the agent skill invocation path, the standard json.Unmarshal function defaults to parsing all JSON numbers as float64. When this parsed request is handed off to a tool that strictly enforces an integer type, it triggers a validation error.

Proposed Solution:
Replaced the standard json.Unmarshal with util.DecodeJSON specifically within the request unmarshalling logic for agent skills. This ensures that numeric types are decoded accurately and integers are preserved without being implicitly converted to floats before reaching the tools.

Should include a concise description of the changes (bug or feature), it's
impact, along with a summary of the solution

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the agent skill invocation process where integer parameters were inadvertently converted to floats during JSON unmarshalling. This type mismatch caused tools requiring integer inputs to fail when called through agent skills. The fix involves updating the JSON decoding mechanism to correctly preserve integer types, ensuring robust tool execution.

Highlights

  • Bug Fix: Integer to Float Conversion: Resolved an issue where integer parameters for tools were incorrectly converted to floats when invoked via agent skills, leading to execution failures.
  • JSON Unmarshalling Logic: Replaced json.Unmarshal with util.DecodeJSON in the agent skill invocation path to ensure accurate numeric type preservation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the JSON parameter decoding in the runInvoke function. It replaces the direct use of json.Unmarshal with a new util.DecodeJSON function, which processes the input from a strings.NewReader. This change likely aims to improve JSON parsing, potentially offering better error handling or more flexible input processing. No specific feedback was provided in the review comments.

@pavankrishna13

Copy link
Copy Markdown
Contributor Author

Code changes committed and merged as part of this PR : #2847

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.

1 participant