Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/google/adk/tools/set_model_response_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions tests/unittests/tools/test_set_model_response_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading