Repository navigation
fix(tools): coerce integral floats inside list[int] tool parameters too - #6972
nileshpatil6 wants to merge 2 commits into
Conversation
82bd438 to
109f575
Compare
|
Rebased onto main after the argument-preprocessing refactor.
The tests were unchanged and still exercise it through and with the change the module is green at 43 passed. |
109f575 to
e7758d7
Compare
Merge #6972 PiperOrigin-RevId: 986139946
|
Thank you @nileshpatil6 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit b1cba29. Closing this PR as the changes are now in the main branch. |
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
Some session stores persist call args as a proto
Struct, whose only number type is double, so anintcomes back as afloaton replay. #6885 fixed that for scalarintparameters inFunctionTool._preprocess_args.The same round trip converts list elements too, and those are still passed through untouched. A tool declared as:
receives
[1396683.0, 7.0]instead of[1396683, 7]after a session replay. Anything downstream that indexes, formats, or sends those ids to a typed API then sees floats, so the failure surfaces far from its cause.Solution:
Apply the same coercion to
list[int]parameters, element by element, right after the scalarintbranch it mirrors. Non integral floats are left alone with the same warning the scalar path emits, so no value is silently rounded.Optional[list[int]]is covered because the existing Union handling unwraps the annotation before this point.Other element types are untouched: only
list[int]is coerced, and alist[float]orlist[str]parameter passes through unchanged.Testing Plan
Unit Tests:
Five tests added to
tests/unittests/tools/test_function_tool.py: coercion forlist[int]andOptional[list[int]], plus negative guards assertinglist[float],list[str]and non integral values are not altered.The two coercion tests fail on main and pass with this change.
Manual End-to-End (E2E) Tests:
Not required. The defect is entirely in argument preprocessing and is reproduced directly by the unit tests: passing
{"component_ids": [1396683.0, 7.0]}to a tool typedlist[int]and asserting the callable receives Python ints.