feat: Support instance methods for automatic function calling in Google GenAI Java SDK. - #1199
Open
copybara-service[bot] wants to merge 1 commit into
Open
feat: Support instance methods for automatic function calling in Google GenAI Java SDK.#1199copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
copybara_964733917
branch
2 times, most recently
from
August 24, 2026 16:37
2965fb4 to
6af6b61
Compare
copybara-service
Bot
force-pushed
the
copybara_964733917
branch
6 times, most recently
from
August 25, 2026 19:52
36ed0c9 to
b4848bf
Compare
copybara-service
Bot
force-pushed
the
copybara_964733917
branch
7 times, most recently
from
August 26, 2026 23:36
277c7c0 to
d170708
Compare
…le GenAI Java SDK.
Automatic Function Calling (AFC) previously restricted function declarations and invocations to public static methods only, throwing an `IllegalArgumentException` ("Instance methods are not supported. Please use static methods.") if an instance method was provided. This forced users to encapsulate state in static fields or create static wrappers when calling methods on service objects.
Support passing an instance or instance mapping along with `Method` references when configuring tools for Automatic Function Calling:
- Remove static modifier validation in `FunctionDeclaration.fromMethod(...)` so schemas can be generated from instance methods.
- Add `function_instances` mapping field to `Tool` definition and builder overloads to `Tool.Builder`:
- `functions(Method, Object)`
- `functions(List<Method>, Object)`
- `functions(Map<Method, Object>)`
- Update `AfcUtil` to extract function instances from `GenerateContentConfig` and invoke target methods with their bound instance (`method.invoke(instance, args)`).
- Pass `functionInstanceMap` across synchronous and asynchronous model generation loops (`Models`, `AsyncModels`, `Chat`, and `AsyncChat`).
- Add unit tests in `FunctionDeclarationTest`, `AfcUtilTest`, and `PrivateChatAfcTest`.
Closes #807
PiperOrigin-RevId: 964733917
copybara-service
Bot
force-pushed
the
copybara_964733917
branch
from
August 28, 2026 02:11
d170708 to
ca9f846
Compare
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.
feat: Support instance methods for automatic function calling in Google GenAI Java SDK.
Automatic Function Calling (AFC) previously restricted function declarations and invocations to public static methods only, throwing an
IllegalArgumentException("Instance methods are not supported. Please use static methods.") if an instance method was provided. This forced users to encapsulate state in static fields or create static wrappers when calling methods on service objects.Support passing an instance or instance mapping along with
Methodreferences when configuring tools for Automatic Function Calling:FunctionDeclaration.fromMethod(...)so schemas can be generated from instance methods.function_instancesmapping field toTooldefinition and builder overloads toTool.Builder:functions(Method, Object)functions(List<Method>, Object)functions(Map<Method, Object>)AfcUtilto extract function instances fromGenerateContentConfigand invoke target methods with their bound instance (method.invoke(instance, args)).functionInstanceMapacross synchronous and asynchronous model generation loops (Models,AsyncModels,Chat, andAsyncChat).FunctionDeclarationTest,AfcUtilTest, andPrivateChatAfcTest.Closes #807