Update experimental JSON schema per issue #1048 - #2182
Open
zyantw wants to merge 1 commit into
Open
Conversation
Adds documentation for the experimental JSON schema-based function declaration feature to `function-tools.md`. Includes: * An explanation of the `ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECL` environment variable. * CLI instructions for enabling and disabling the feature across macOS, Linux, and Windows (CMD & PowerShell) using tabbed code blocks. * A Python code snippet demonstrating how to explicitly configure the feature in-code.
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.
Adds documentation for the experimental JSON schema-based function declaration feature to
function-tools.md.Includes:
ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECLenvironment variable.1. JSON Schema Generation Capability & Default Status
Quoted Claim
FeatureName.JSON_SCHEMA_FOR_FUNC_DECLis registered in_FEATURE_REGISTRYwithFeatureConfig(FeatureStage.EXPERIMENTAL, default_on=True).FunctionTool,_get_declaration()passesis_feature_enabled(FeatureName.JSON_SCHEMA_FOR_FUNC_DECL)tobuild_function_declaration(), which delegates to_function_tool_declarations.build_function_declaration_with_json_schema()._build_parameters_json_schema()extracts parameter types from the callable using Pythoninspectandget_type_hints, dynamically generates a Pydantic model viapydantic.create_model, and exports the schema usingmodel_json_schema().src/google/adk/features/_feature_registry.py#L52src/google/adk/features/_feature_registry.py#L174-L176src/google/adk/tools/_automatic_function_calling_util.py#L220-L237src/google/adk/tools/_function_tool_declarations.py#L15-L23src/google/adk/tools/_function_tool_declarations.py#L191-L215src/google/adk/tools/_function_tool_declarations.py#L282-L356src/google/adk/tools/function_tool.py#L145-L1562. Feature Resolution Hierarchy & Environment Variables
Quoted Claim
PASSis_feature_enabled()implements a strict 3-tier priority resolution:_FEATURE_OVERRIDES(set viaoverride_feature_enabled()).ADK_ENABLE_<NAME>returnsTrueif set to1ortrue. If not enabled,ADK_DISABLE_<NAME>returnsFalseif set to1ortrue.config.default_on(TrueforJSON_SCHEMA_FOR_FUNC_DECL).src/google/adk/features/_feature_registry.py#L258-L284src/google/adk/features/_feature_registry.py#L286-L344src/google/adk/utils/env_utils.py#L27-L60docs/guides/features/feature_registry/index.md#L36-L903. Option 1: Command Line Configuration (Enable & Disable)
ADK_ENABLE_JSON_SCHEMA_FOR_FUNC_DECLis formed dynamically viaf"ADK_ENABLE_{feature_name_str}".ADK_DISABLE_JSON_SCHEMA_FOR_FUNC_DECLis formed dynamically viaf"ADK_DISABLE_{feature_name_str}".is_env_enabled()executesos.environ.get(env_var_name, default).lower() in ['true', '1']. Setting"1"in Bash, CMD, and PowerShell satisfies this requirement.src/google/adk/features/_feature_registry.py#L331-L339src/google/adk/utils/env_utils.py#L27-L60docs/guides/features/feature_registry/index.md#L39-L544. Option 2 - Method A: Programmatic Feature Override
FeatureNameandoverride_feature_enabledare exported insrc/google/adk/features/__init__.py.override_feature_enabled(FeatureName.JSON_SCHEMA_FOR_FUNC_DECL, True)registers the boolean in_FEATURE_OVERRIDES, superseding environment variables and defaults.FunctionTool(func=...)receives callableget_current_weather, parses its docstring, annotations, and parameters cleanly.Agent(model="gemini-2.5-flash", name="my_agent", instruction="...", tools=[...])matches:name:strvalidated identifier fromBaseNode(src/google/adk/workflow/_base_node.py#L48-L56).model:Union[str, BaseLlm]fromLlmAgent(src/google/adk/agents/llm_agent.py#L291).instruction:Union[str, InstructionProvider]fromLlmAgent(src/google/adk/agents/llm_agent.py#L314).tools:list[ToolUnion]fromLlmAgent(src/google/adk/agents/llm_agent.py#L392).src/google/adk/features/__init__.py#L1-L26src/google/adk/features/_feature_registry.py#L258-L279src/google/adk/agents/__init__.py#L29-L62src/google/adk/agents/llm_agent.py#L260-L394src/google/adk/agents/llm_agent.py#L1451src/google/adk/tools/__init__.py#L34-L72src/google/adk/tools/function_tool.py#L99-L143src/google/adk/workflow/_base_node.py#L48-L565. Option 2 - Method B: In-Script Environment Variable Setting
is_feature_enabled()does not cache initialos.environlookups at import time; it evaluatesos.environon every invocation when resolving flags. Settingos.environbefore tool declaration instantiation takes effect reliably.src/google/adk/features/_feature_registry.py#L331-L336src/google/adk/utils/env_utils.py#L27-L60docs/guides/features/feature_registry/index.md#L99-L100