Repository navigation
Commit da35ca7
fix: harden callable type hint resolution and FunctionNode TypeAdapter handling
When `from __future__ import annotations` is active and a callable imports ADK context types (`Context`, `ToolContext`, `CallbackContext`, `ReadonlyContext`) or other symbols inside `if TYPE_CHECKING:`, `typing.get_type_hints` previously raised `NameError` and discarded all resolved type hints for the entire callable. In addition, `FunctionNode` did not catch `NameError` or `PydanticUserError` when constructing `TypeAdapter` instances and had an unguarded `TypeAdapter(annotated_type)` call at runtime in `_coerce_param`.
- Retry `typing.get_type_hints` with ADK context types in `localns` on `NameError`, and add `get_best_effort_type_hints` per-parameter fallback so an unresolvable `TYPE_CHECKING`-only annotation does not wipe out sibling parameter hints in `context_utils`, `FunctionNode`, or `FunctionTool` runtime argument preprocessing and validation.
- Share `get_callable_globals`, `resolve_annotation`, and `is_unresolvable` between `_callable_utils` and `_function_tool_declarations`, resolving individual annotations via `typing.get_type_hints` on a single-annotation holder.
- Catch `(TypeError, NameError, PydanticSchemaGenerationError, PydanticUserError)` across `FunctionNode.__init__`, `_infer_schemas_from_func_signature`, and `_coerce_param`, and rebuild incomplete `TypeAdapter` instances inside `_build_type_adapter`.
Co-authored-by: Shangjie Chen <[email protected]>
PiperOrigin-RevId: 10065863181 parent 12c7bed commit da35ca7
9 files changed
Lines changed: 774 additions & 134 deletions
File tree
- src/google/adk
- tools
- utils
- workflow
- tests/unittests
- tools
- utils
- workflow
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | | - | |
37 | 34 | | |
38 | 35 | | |
39 | | - | |
40 | 36 | | |
41 | 37 | | |
42 | 38 | | |
| |||
50 | 46 | | |
51 | 47 | | |
52 | 48 | | |
| 49 | + | |
53 | 50 | | |
| 51 | + | |
54 | 52 | | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | 140 | | |
237 | 141 | | |
238 | 142 | | |
| |||
262 | 166 | | |
263 | 167 | | |
264 | 168 | | |
265 | | - | |
| 169 | + | |
| 170 | + | |
266 | 171 | | |
267 | 172 | | |
268 | 173 | | |
| |||
283 | 188 | | |
284 | 189 | | |
285 | 190 | | |
286 | | - | |
287 | | - | |
| 191 | + | |
| 192 | + | |
288 | 193 | | |
289 | | - | |
| 194 | + | |
290 | 195 | | |
291 | 196 | | |
292 | 197 | | |
| |||
469 | 374 | | |
470 | 375 | | |
471 | 376 | | |
472 | | - | |
473 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
474 | 382 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
478 | 389 | | |
479 | | - | |
| 390 | + | |
480 | 391 | | |
481 | 392 | | |
482 | 393 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
265 | 267 | | |
266 | 268 | | |
267 | 269 | | |
| |||
293 | 295 | | |
294 | 296 | | |
295 | 297 | | |
296 | | - | |
| 298 | + | |
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
| |||
0 commit comments