Commit d69dedd
fix(tools): accept dict output_schema in SetModelResponseTool (#5469)
Merge #5516
## Summary
Fixes #5469. When `output_schema` is a raw dict (e.g. `{"type": "object", "properties": {...}}`), `SetModelResponseTool.__init__` previously fell through to the generic `else` branch and used the dict **instance** as the parameter annotation. Downstream, `_function_parameter_parse_util._is_builtin_primitive_or_compound` does `annotation in _py_builtin_type_to_schema_type.keys()`, which calls `__hash__` on the annotation and raises `TypeError: unhashable type: 'dict'`.
This change adds an explicit `elif isinstance(output_schema, dict)` branch that uses the `dict` type (hashable) as the annotation, so the existing builtin lookup maps it to `Type.OBJECT` cleanly. `run_async` already handles this case via the existing `args.get('response')` pass-through.
## Reproduction (before fix)
```python
from google.adk.agents import Agent
agent = Agent(
name="test",
model="gemini-2.5-flash",
instruction="You are a helpful agent.",
output_schema={"type": "object", "properties": {"result": {"type": "string"}}},
)
# -> TypeError: unhashable type: 'dict'
```
## Testing plan
- Added regression unit tests in `tests/unittests/tools/test_set_model_response_tool.py`:
- `test_tool_initialization_raw_dict_schema` — `__init__` with a raw dict does not crash and stores the schema.
- `test_function_signature_generation_raw_dict_schema` — generated signature has a single `response: dict` parameter (annotation is the `dict` type, not the dict instance).
- `test_get_declaration_raw_dict_schema` — `_get_declaration()` returns a valid declaration without raising `TypeError`.
- `test_run_async_raw_dict_schema` — `run_async` returns the response unchanged.
- Run: `pytest tests/unittests/tools/test_set_model_response_tool.py -q`
- Existing tests for `BaseModel`, `list[BaseModel]`, `list[str]`, `dict[str, int]` schemas remain unchanged and still pass.
## Notes
- Schema fidelity (propagating dict-schema constraints into the function declaration) is intentionally out of scope; this PR only fixes the crash, matching the issue's reported scope and the existing handling for `list[str]` / `dict[str, int]`.
Co-authored-by: Xuan Yang <xygoogle@google.com>
COPYBARA_INTEGRATE_REVIEW=#5516 from MukundaKatta:fix/set-model-response-tool-dict-schema 5e808a9
PiperOrigin-RevId: 9411696111 parent d60ac69 commit d69dedd
2 files changed
Lines changed: 119 additions & 1 deletion
File tree
- src/google/adk/tools
- tests/unittests/tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
90 | 108 | | |
91 | | - | |
| 109 | + | |
92 | 110 | | |
93 | 111 | | |
94 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
472 | 473 | | |
473 | 474 | | |
474 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
475 | 575 | | |
476 | 576 | | |
477 | 577 | | |
| |||
0 commit comments