Repository navigation
Conversation
…n path build_function_declaration drops the ignored params (tool_context, input_stream) from the signature but copied every original annotation onto the stripped function. from_function_with_options then resolves them all with get_type_hints, so a context param typed with a TYPE_CHECKING-only import raised NameError although it never reaches the schema. Copy only the kept params' annotations. NameError is still not caught, so a declared param whose annotation cannot be resolved keeps its clear error. Also pins the JSON-schema path fix from 2ecb3fb, which had no test.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Fixes #7436.
Problem:
With
JSON_SCHEMA_FOR_FUNC_DECLdisabled,build_function_declarationremoves the ignored params (tool_context,input_stream) from the signature but copies every original annotation onto the stripped function.from_function_with_optionsthen resolves all of them withget_type_hints. A context param typed with aTYPE_CHECKING-only import, the pattern from #6488, raisesNameErroreven though it never reaches the schema.Solution:
Copy only the kept params' annotations (and
return) onto the stripped function. It's one statement and doesn't add anexcept NameError. The comment on thatget_type_hintscall says not catchingNameErroris deliberate, and this keeps it that way: a declared param whose annotation can't be resolved still raises a clearNameError, and a test now pins that.The JSON-schema path already handles this case since 2ecb3fb, but nothing tested it (see #6488 (comment)). The new test is parametrized over both paths, so it pins that fix too.
Testing Plan
Unit Tests:
Three new cases in
tests/unittests/tools/test_function_tool_with_import_annotations.py. I checked that each one fails when the change it guards is reverted:test_type_checking_only_context_param_is_left_out_of_declaration[False]NameError: name 'ToolContext' is not defined)test_type_checking_only_context_param_is_left_out_of_declaration[True]NameErrorcatch from 2ecb3fb in_get_function_fieldsis narrowed back toTypeErrortest_type_checking_only_annotation_on_declared_param_still_raisesNameErroraroundget_type_hintsinsteadpre-commit runpassed on the changed files (ruff, isort, pyink, codespell, compliance and docs checks).Manual End-to-End (E2E) Tests:
An
LlmAgentusing the tool from #7436, with a scriptedBaseLlmthat calls it once, run throughInMemoryRunnerwithADK_DISABLE_JSON_SCHEMA_FOR_FUNC_DECL=1. On macOS, Python 3.12.13:Before (
main@ 77d4dcd):After:
Checklist
🤖 Generated with Claude Code