Repository navigation
Conversation
validate_tool_arguments classified AgentImage and AgentAudio values as 'object' (they subclass PIL.Image.Image and str), so passing them through a ToolCallingAgent state reference failed for tools declaring 'image' or 'audio' inputs, while the direct sanitized call worked. Match agent-typed values against media input types explicitly; values for 'object' inputs keep validating as before. Fixes huggingface#2943
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.
Fixes #2943
validate_tool_argumentsderived the argument type from_get_json_schema_type(type(value)).AgentImagesubclassesPIL.Image.ImageandAgentAudiosubclassesstr, so neither is in the base mapping and both fall back to"object". A tool declaring animage/audioinput therefore rejected the value when it came through aToolCallingAgentstate reference, even though calling the tool directly withsanitize_inputs_outputs=Trueworked.Change: a small helper matches
AgentImage→"image"andAgentAudio→"audio", but only when the input schema actually expects that type. The guard is there because@toolfunctions annotated withPIL.Image.Imagecurrently get an"object"schema, and they keep validating exactly as before. The single-value branch uses the same helper.Tests
TestValidateToolArgumentsAgentTypes: AgentImage →imageinput (dict and single-value forms), AgentAudio →audioinput, AgentImage still valid for anobjectinput, and still rejected for astringinput.TestToolCallingAgent::test_execute_tool_call_accepts_agent_image_from_state: the reproduction from the issue.Without the fix, the 3 media tests fail and the 2 guard tests pass. With it, all pass, and
ruff check/ruff format --checkare clean. The rest oftest_tools.py,test_agents.py,test_types.pyandtest_tool_validation.pyshows the same results before and after the change (the only local failures are from optional deps I don't have installed).I used an AI assistant while working on this. I've read and run every line of the diff and I'm happy to address review comments. I also know #2943 doesn't have
status:acceptedyet, so feel free to hold this until it's triaged.