Skip to content

Accept AgentImage/AgentAudio state values for image/audio tool inputs - #2950

Open
syahra712 wants to merge 1 commit into
huggingface:mainfrom
syahra712:fix/typed-media-state-args-2943
Open

syahra712 wants to merge 1 commit into
huggingface:mainfrom
syahra712:fix/typed-media-state-args-2943

Conversation

@syahra712

Copy link
Copy Markdown

Fixes #2943

validate_tool_arguments derived the argument type from _get_json_schema_type(type(value)). AgentImage subclasses PIL.Image.Image and AgentAudio subclasses str, so neither is in the base mapping and both fall back to "object". A tool declaring an image / audio input therefore rejected the value when it came through a ToolCallingAgent state reference, even though calling the tool directly with sanitize_inputs_outputs=True worked.

Change: a small helper matches AgentImage → "image" and AgentAudio → "audio", but only when the input schema actually expects that type. The guard is there because @tool functions annotated with PIL.Image.Image currently get an "object" schema, and they keep validating exactly as before. The single-value branch uses the same helper.

Tests

  • TestValidateToolArgumentsAgentTypes: AgentImage → image input (dict and single-value forms), AgentAudio → audio input, AgentImage still valid for an object input, and still rejected for a string input.
  • 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 --check are clean. The rest of test_tools.py, test_agents.py, test_types.py and test_tool_validation.py shows 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:accepted yet, so feel free to hold this until it's triaged.

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
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.

BUG: ToolCallingAgent rejects typed image and audio state arguments before sanitization

1 participant