Skip to content

Conversation

jinnigu
Copy link
Contributor

@jinnigu jinnigu commented Oct 12, 2025

Add optional parameter to @Annotations.Schema to mark function parameters as optional, excluding them from the "required" array in generated function schemas.

// Example func
public Map<String, Object> executeExample(
    @Annotations.Schema(name = "requiredParam", description = "A required parameter") 
    String requiredParam,
    
    @Annotations.Schema(name = "optionalParam", description = "An optional parameter", optional = true)
    Integer optionalParam
) {
    // implementation
}

// Generated schema
{
  "required": ["requiredParam"]
}

Fix #493

Copy link
Contributor

Summary of Changes

Hello @jinnigu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement by enabling the definition of optional parameters within function schemas. By adding an optional flag to the @Annotations.Schema annotation, developers can now explicitly mark function arguments as non-mandatory. This change ensures that generated function schemas accurately reflect which parameters are truly required, and during function execution, missing optional arguments are handled by passing null instead of throwing an error, improving flexibility and robustness in function calling.

Highlights

  • Annotation Extension: The @Annotations.Schema annotation now includes an optional boolean parameter, defaulting to false, allowing explicit marking of optional function arguments.
  • Schema Generation Update: The FunctionCallingUtils class has been updated to exclude parameters marked as optional=true from the required array when generating function schemas.
  • Runtime Handling of Optional Parameters: The FunctionTool class now gracefully handles missing optional parameters during function invocation by passing null for them, preventing IllegalArgumentException for non-mandatory arguments.
  • Comprehensive Testing: New unit tests have been added to FunctionToolTest to validate that optional parameters are correctly excluded from schema requirements and handled appropriately during function calls.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for optional parameters in @Annotations.Schema. The changes are well-implemented across the annotation definition, schema building logic, and function invocation. I've provided a couple of suggestions to improve code readability, efficiency, and reduce duplication in FunctionTool and FunctionCallingUtils. The added tests are comprehensive and cover the new functionality well.

@jinnigu jinnigu force-pushed the feature/support-optional-parameter branch from e347b34 to 9f56f3d Compare October 12, 2025 07:14
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.

Annotations.Schema does not support nullable parameter to mark optional function parameters

1 participant