Skip to content

fix(afc): accept whole numbers for Optional[float] tool parameters - #3463

Closed
Sun-Wukhan wants to merge 1 commit into
googleapis:mainfrom
Sun-Wukhan:fix/afc-optional-float-int
Closed

Sun-Wukhan wants to merge 1 commit into
googleapis:mainfrom
Sun-Wukhan:fix/afc-optional-float-int

Conversation

@Sun-Wukhan

Copy link
Copy Markdown

Fixes #3453

Automatic function calling rejected whole numbers for Optional[float] parameters. Whole floats are converted to int before argument conversion, and the Union branch of convert_if_exist_pydantic_model matched members only with isinstance, so an int value never matched a float member and the call failed with "value 21 cannot be converted to parameter annotation typing.Optional[float]". The non-Union path already has the int to float exception; this adds the same exception to the Union branch, excluding bool.

Tests: a new case in test_convert_if_exist_pydantic_model.py covering Optional[float] with an int, float | None with an int, Union[int, float], None, and a fractional value. The file passes with the fix (15 tests) and the new test fails on the unfixed code with the error reported in the issue.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Dec 3, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:L Code changes between 40-100 lines label Dec 3, 2026
@Venkaiahbabuneelam

Copy link
Copy Markdown

Hi @Sun-Wukhan,

Thank you for your contribution and for putting together a clean fix for #3453!

Closing this PR as a duplicate of #3461, which was opened earlier for the same issue (#3453) and also covers the non-Union bool guard and end-to-end invoke_function_from_dict_args tests.

We really appreciate your continued contributions to the repo—we'll track the fix in #3461. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L Code changes between 40-100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatic function calling never runs a tool with an Optional[float] parameter when the model passes a whole number

2 participants