Repository navigation
fix(tools): keep T | None arguments in BaseTool.from_config - #7841
Open
adityasingh2400 wants to merge 1 commit into
Open
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
Before Python 3.14, get_origin(int | None) is types.UnionType, not typing.Union, so from_config never unwrapped PEP 604 optionals and dropped those arguments with an "Unsupported parsing" warning. YAML configs for VertexAiRagRetrieval, GoogleSearchTool and ExecuteBashTool silently lost them, e.g. a RAG tool with no corpus. Unwrap both forms. Fixes google#7840
adityasingh2400
marked this pull request as draft
October 31, 2026 01:48
adityasingh2400
marked this pull request as ready for review
October 31, 2026 01:48
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
T | Nonearguments on Python 3.11-3.13 #7840Problem:
BaseTool.from_configunwrapsOptional[T]withif get_origin(param_type) is Union. Before Python 3.14, a PEP 604 optional (T | None) has origintypes.UnionType, so the unwrap was skipped, no branch matched, and the argument was dropped with an "Unsupported parsing for argument" warning. Built-in tools that use the defaultfrom_configand annotate their arguments this way silently lost them from YAML configs. That includesVertexAiRagRetrieval(rag_corpora,similarity_top_k, …),GoogleSearchTool(model) andExecuteBashTool(workspace).Solution:
Treat
types.UnionTypeliketyping.Unionwhen unwrapping the optional, soT | Nonemaps exactly likeOptional[T]. On Python 3.14, where the two are the same type, nothing changes.Testing Plan
Unit Tests:
Added to
tests/unittests/tools/test_base_tool.py:test_from_config_unwraps_pep604_optional_args:int | None,list[str] | Noneandfloat | Nonearguments are passed through, andOptional[str]still works.test_vertex_ai_rag_retrieval_from_config_keeps_pep604_args:rag_corpora,similarity_top_kandvector_distance_thresholdreach the tool'sVertexRagStore.pre-commit runpasses on the changed files, andmypyreports no issues inbase_tool.py.Manual End-to-End (E2E) Tests:
I loaded a YAML agent config through
config_agent_utils.from_config. The config holds aVertexAiRagRetrievaltool withrag_corpora,similarity_top_kandvector_distance_threshold, and I inspectedagent.tools[0].vertex_rag_store(Python 3.11):Checklist
Additional context
#4371 / #4406 dealt with PEP 604 unions in function-declaration parsing. This is the separate tool-config path.