diff --git a/src/google/adk/tools/set_model_response_tool.py b/src/google/adk/tools/set_model_response_tool.py index d1dc6ed55d..22605ad037 100644 --- a/src/google/adk/tools/set_model_response_tool.py +++ b/src/google/adk/tools/set_model_response_tool.py @@ -87,8 +87,17 @@ def set_model_response() -> str: annotation=list[inner_type], ) ] + elif isinstance(output_schema, dict): + # Use `dict` type, not the instance — dict instances are unhashable. + params = [ + inspect.Parameter( + 'response', + inspect.Parameter.KEYWORD_ONLY, + annotation=dict, + ) + ] else: - # For other schema types (list[str], dict, etc.), + # For other schema types (list[str], Schema, GenericAlias, etc.), # create a single parameter with the actual schema type params = [ inspect.Parameter( diff --git a/tests/unittests/tools/test_set_model_response_tool.py b/tests/unittests/tools/test_set_model_response_tool.py index 89da394acc..6f2638a588 100644 --- a/tests/unittests/tools/test_set_model_response_tool.py +++ b/tests/unittests/tools/test_set_model_response_tool.py @@ -467,3 +467,18 @@ async def test_run_async_dict_schema(): assert result is not None assert isinstance(result, dict) assert result == {'a': 1, 'b': 2, 'c': 3} + + +def test_tool_initialization_raw_dict_instance(): + """Test tool initialization with a raw dict schema instance.""" + raw_schema = {'type': 'object', 'properties': {'name': {'type': 'string'}}} + tool = SetModelResponseTool(raw_schema) + + assert tool.output_schema == raw_schema + assert not tool._is_basemodel + assert not tool._is_list_of_basemodel + + sig = inspect.signature(tool.func) + assert 'response' in sig.parameters + assert len(sig.parameters) == 1 + assert sig.parameters['response'].annotation is dict