Skip to content

Conversation

@saurabhhhcodes
Copy link

Proposes automatic wrapping of function tools whose input type is a non-struct (e.g. string/int) so they accept LLM function-call arguments like {"input": }. Includes wrapper implementation, tests, docs, and a changelog entry.

Automatically wrap function tools with non-struct inputs so LLM map-based function calls like {"input": <value>} are handled. Adds wrapper, tests, and docs.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @saurabhhhcodes, 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 significantly enhances the functiontool package by introducing automatic support for Go functions that accept non-struct input types (such as strings or integers) when called by Large Language Models (LLMs). Previously, LLMs typically expected function arguments as a map[string]any, which could complicate the integration of simple Go types. The new implementation intelligently wraps these functions, presenting a standardized {"input": <value>} schema to the LLM, thereby streamlining tool development and improving the overall flexibility and ease of use for agent applications.

Highlights

  • Automatic Wrapping for Non-Struct Inputs: Function tools whose input type is a non-struct (e.g., string, int) are now automatically wrapped to accept LLM function-call arguments in the format {"input": <value>}.
  • Enhanced LLM Compatibility: This change makes it seamless to author function tools that accept primitive arguments, ensuring consistency with the model's map-based function call format.
  • New Wrapper Implementation and Tests: A nonStructInputWrapper has been implemented, along with comprehensive unit and integration tests, and updated documentation to support this new functionality.
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 introduces a valuable enhancement by adding automatic support for non-struct inputs in function tools, which simplifies their creation and use. The implementation is well-structured, and the inclusion of documentation and tests is commendable. I've identified a few areas for improvement in the new wrapper.go file, primarily related to code simplification by removing unused or redundant code, and a bug in error handling where a specific validation error was being suppressed. Addressing these points will further improve the code's robustness and maintainability.

Comment on lines 179 to 181
if err1 := w.outputSchema.Validate(output); err1 != nil {
return resp, err // if it fails propagate original err.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There's an issue with the error handling in this block. If w.outputSchema.Validate(output) fails, the specific validation error err1 is discarded, and the original, more generic conversion error err is returned. This hides the true cause of the failure. The more specific validation error err1 should be propagated to aid in debugging.

if err1 := w.outputSchema.Validate(output); err1 != nil {
			return nil, fmt.Errorf("output validation failed: %w", err1)
		}

inputSchema *jsonschema.Resolved
outputSchema *jsonschema.Resolved
handler Func[TArgs, TResults]
innerTool *functionTool[TArgs, TResults]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The innerTool field is declared here but appears to be unused throughout the nonStructInputWrapper's methods. To improve code clarity and maintainability, it's best to remove this unused field and its corresponding initialization in the wrapNonStructInput function.

Comment on lines 114 to 119
if w.inputSchema != nil {
wrappedSchema.Properties["input"] = w.inputSchema.Schema()
} else {
// Use string as default if no schema
wrappedSchema.Properties["input"] = &jsonschema.Schema{Type: "string"}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This if-else block can be simplified. The wrapNonStructInput function is called from New, which ensures that inputSchema is non-nil; otherwise, it would have returned an error. Therefore, the else block appears to be unreachable. You can remove the conditional and directly assign w.inputSchema.Schema().

wrappedSchema.Properties["input"] = w.inputSchema.Schema()

Comment on lines 121 to 123
if wrappedSchema != nil {
decl.ParametersJsonSchema = wrappedSchema
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The wrappedSchema variable is initialized using a struct literal, so it cannot be nil. This if check is redundant and can be removed to make the code more concise.

decl.ParametersJsonSchema = wrappedSchema

Copy link
Author

Requesting maintainers' review and workflow approval for this change (wrapper for non-struct functiontool inputs).

Summary: Adds automatic wrapper for function tools with non-struct inputs (e.g., string/int), unit+integration tests, docs, and CHANGELOG entry. Local tests passed. Please review and approve workflows so CI can run. If you prefer different reviewer assignments or a smaller branch, let me know and I can update the PR.

Copy link
Author

saurabhhhcodes commented Dec 2, 2025

(Fallback) Could maintainers @dmitry and @baptmont review this PR? Top contributors identified from repo history: Dmitry Pasiukevich, Jaana Dogan, João Westerberg, Karol Droste. I attempted to add reviewers programmatically but the API returned a permissions error; please add reviewers or approve workflows when you can. Thank you!,isBackground:false}

Copy link
Author

I'll monitor this PR and will merge automatically once the required maintainer approvals and CI/workflow checks complete. If maintainers prefer a smaller PR, I can split this into a minimal wrapper-only PR — please let me know. Thanks!

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.

1 participant