fix(core): fallback to name when Agent description is missing#1164
Open
svetanis wants to merge 1 commit intogoogle:mainfrom
Open
fix(core): fallback to name when Agent description is missing#1164svetanis wants to merge 1 commit intogoogle:mainfrom
svetanis wants to merge 1 commit intogoogle:mainfrom
Conversation
Prevents a NullPointerException in the google-genai library when an Agent is defined without a description. Includes a regression test.
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.
Prevents a NullPointerException in the google-genai library when an Agent is defined without a description. Includes a regression test.
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):
2. Or, if no issue exists, describe the change:
If applicable, please follow the issue templates to provide as much detail as
possible.
Problem:
Calling AgentTool.declaration() triggers a NullPointerException when an Agent is defined without an explicit description. The crash occurs because the underlying google-genai library's generated FunctionDeclaration builder uses Optional.of() for the description field, which is not null-safe.
Solution:
Implemented defensive logic in AgentTool.java to sanitize the description. If this.description() is null or blank, the tool now falls back to using this.name(). This ensures the builder always receives a valid string and prevents the crash.
Testing Plan
Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.
Unit Tests:
Summary of passed java test results:
Passed AgentToolTest.declaration_withNullDescription_fallsBackToName which verifies that a null description no longer triggers an NPE and correctly falls back to the agent's name.
Manual End-to-End (E2E) Tests:
Verified by running a sample agentic workflow where the Agent class lacked a description field. Previously, this resulted in a crash during tool registration; it now initializes and executes correctly.
Checklist
Additional context
Stack Trace:
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:220)
at java.base/java.util.Optional.of(Optional.java:113)
at com.google.genai.types.AutoValue_FunctionDeclaration$Builder.description(AutoValue_FunctionDeclaration.java:160)
at com.google.adk.tools.AgentTool.declaration(AgentTool.java:135)
Note on Root Cause:
While this PR ensures stability within adk-java, the underlying issue appears to be in the google-genai library. The generated AutoValue_FunctionDeclaration.Builder uses Optional.of() for the description field, which enforces a non-null constraint. A more robust upstream fix would involve the generator using Optional.ofNullable(). This local fix is necessary to prevent crashes in the meantime.