You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
find_context_parameter fails to detect context-typed parameters with postponed annotations #4754
If a tool function is defined in a module that uses from __future__ import annotations, ADK can fail to recognize Context / ToolContext parameters because find_context_parameter() looks at the raw annotation string instead of resolved type hints. When that happens, find_context_parameter() misses the real context parameter. FunctionTool then falls back to the literal name tool_context, so a custom-named context parameter like ctx is not excluded from declaration building and eventually triggers a misleading ValueError saying it must be named tool_context. This is easy to miss because a parameter already named tool_context happens to match the fallback and masks the bug.
Steps to Reproduce:
Install google-adk from source (main branch)
Create a file with the following code:
from __future__ importannotationsfromgoogle.adk.tools.function_toolimportFunctionToolfromgoogle.adk.tools.tool_contextimportToolContextdefmy_tool(query: str, ctx: ToolContext) ->str:
"""A tool that searches for something."""returnf"Result for {query}"tool=FunctionTool(my_tool)
print(tool._get_declaration())
Run the file with uv run python my_tool.py
Expected Behavior:
The tool should be created successfully with ctx excluded from the schema, identical to the behavior without from __future__ import annotations
Observed Behavior:
ValueError: `ToolContext` parameter must be named as `tool_context`. Found `ctx` instead in function `my_tool`.
@gautamvarmadatla Thanks for the detailed report and for already putting up PR #4755 — the root cause is spot on: find_context_parameter() uses an identity check (annotation is Context) that breaks when from __future__ import annotations turns annotations into strings.
As an immediate workaround until the PR lands, renaming the context parameter to tool_context will unblock you since FunctionTool falls back to that name — could you confirm if that works for your case in the meantime?
Once you've validated the fix in PR #4755 holds up across your use cases, it'd be great to get that reviewed and merged.
hi @surajksharma07, thanks so much for the prompt response.
I’ve been testing locally with the same patch as in #4755, and it seems to be working on my end.
Activity
surajksharma07 commentedon Mar 8, 2026
@gautamvarmadatla Thanks for the detailed report and for already putting up PR #4755 — the root cause is spot on:
find_context_parameter()uses an identity check (annotation is Context) that breaks whenfrom __future__ import annotationsturns annotations into strings.As an immediate workaround until the PR lands, renaming the context parameter to
tool_contextwill unblock you sinceFunctionToolfalls back to that name — could you confirm if that works for your case in the meantime?Once you've validated the fix in PR #4755 holds up across your use cases, it'd be great to get that reviewed and merged.
Team is looking more into it.
gautamvarmadatla commentedon Mar 8, 2026
hi @surajksharma07, thanks so much for the prompt response.
I’ve been testing locally with the same patch as in #4755, and it seems to be working on my end.
surajksharma07 commentedon Mar 8, 2026
@gautamvarmadatla Good to hear the patch in #4755 is working on your end — that confirms the fix is on the right track.
We'll move ahead with the PR review; once it's been looked at on our side, we'll get it merged in.
Team is looking more into it.
Thanks!
surajksharma07 commentedon Mar 8, 2026
@xuanyang15 Please have a look into it.
xuanyang15 commentedon Mar 26, 2026
Covered by 22fc332
fix: build function declaration when a param uses a TYPE_CHECKING-onl…
fix: build function declaration when a param uses a TYPE_CHECKING-onl…
fix: build function declaration when a param uses a TYPE_CHECKING-onl…