Skip to content

feat: support @Schema on FunctionTool object properties - #1694

Open
YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:feat/issue-611-pojo-schema
Open

YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:feat/issue-611-pojo-schema

Conversation

@YuqiGuo105

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Closes #611.

Problem:

POJO properties used by FunctionTool rely on Jackson annotations for their model-facing names and required flags. Applications cannot independently describe tool properties with ADK's @Schema annotation without changing their ordinary business JSON representation. Renaming only the generated schema would also leave tool argument deserialization using the old names.

Solution:

  • Allow Annotations.Schema on fields and record components, in addition to methods and parameters.
  • Create an isolated copy of the configured ObjectMapper with a schema-aware annotation introspector. Non-empty @Schema.name takes precedence over Jackson's name; @Schema.optional overrides the schema's required marker. Without an ADK annotation, existing Jackson behavior remains in effect.
  • Include property descriptions in recursively generated schemas, including nested POJOs and collections.
  • Use the same tool-specific mapper for declaration generation, argument binding, and result conversion, keeping the model-facing contract and runtime behavior consistent without mutating the application's mapper.

For example, a property annotated with @JsonProperty("business_id") and @Schema(name = "customer_id", description = "Customer identifier") remains business_id in ordinary business JSON, while the tool schema and tool argument binding use customer_id.

Testing Plan

Unit Tests:

  • Added 15 regression tests covering annotation precedence, descriptions, optionality, fields/getters/setters, private fields, record components, nested collections, @JsonIgnore, unannotated POJOs, custom naming strategies, mapper isolation, and return-value/schema consistency.
  • ./mvnw -o -B -pl core -Dtest=FunctionToolSchemaTest test passes.
  • ./mvnw -B -Prelease -pl core -am clean package passes on OpenJDK 25.0.3 (Java release target 17), including source/Javadoc jars. Both full-core executions (default-test and basic) run 2,904 tests with 0 failures, 0 errors, and 30 skipped; the additional environment-specific executions also pass.
  • Google Java formatting produces no changes, and git diff --check upstream/main...HEAD passes.

Manual End-to-End (E2E) Tests:

Not run against a live model. Regression tests exercise local FunctionTool declaration generation and invocation; no model credentials or external services are required.

Checklist

  • I have read CONTRIBUTING.md.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • Added concise Javadocs for annotation behavior.
  • Added tests for the feature and backward-compatible Jackson fallback.
  • New and existing core unit tests pass locally.
  • I have manually tested my changes against a live model.

Additional context

The optional flag controls the generated tool schema's required list; this change does not introduce a separate business-validation framework. This is the Java/Jackson implementation of the requested ADK annotation semantics, rather than a new model-provider protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support @Schema annotation for Object parameters in FunctionTool

1 participant