Skip to content

Commit f31226e

Browse files
xuanyang15copybara-github
authored andcommitted
docs: Update the error message for function parameter ToolContext not named as tool_context
Fixes #1530 Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 830248414
1 parent 93aad61 commit f31226e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/google/adk/tools/_function_parameter_parse_util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from google.genai import types
3030
import pydantic
3131

32+
from ..tools.tool_context import ToolContext
3233
from ..utils.variant_utils import GoogleLLMVariant
3334

3435
_py_builtin_type_to_schema_type = {
@@ -315,6 +316,13 @@ def _parse_schema_from_parameter(
315316
)
316317
_raise_if_schema_unsupported(variant, schema)
317318
return schema
319+
if inspect.isclass(param.annotation) and issubclass(
320+
param.annotation, ToolContext
321+
):
322+
raise ValueError(
323+
'`ToolContext` parameter must be named as `tool_context`. Found'
324+
f' `{param.name}` instead in function `{func_name}`.'
325+
)
318326
if param.annotation is None:
319327
# https://swagger.io/docs/specification/v3_0/data-models/data-types/#null
320328
# null is not a valid type in schema, use object instead.

0 commit comments

Comments
 (0)