Skip to content

feat: Support instance methods for automatic function calling in Google GenAI Java SDK. - #1199

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara_964733917
Open

feat: Support instance methods for automatic function calling in Google GenAI Java SDK.#1199
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara_964733917

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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 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

@copybara-service
copybara-service Bot force-pushed the copybara_964733917 branch 2 times, most recently from 2965fb4 to 6af6b61 Compare August 24, 2026 16:37
@copybara-service copybara-service Bot changed the title No public description Support instance methods for automatic function calling in Google GenAI Java SDK. Aug 24, 2026
@copybara-service
copybara-service Bot force-pushed the copybara_964733917 branch 6 times, most recently from 36ed0c9 to b4848bf Compare August 25, 2026 19:52
@copybara-service copybara-service Bot changed the title Support instance methods for automatic function calling in Google GenAI Java SDK. feat: Support instance methods for automatic function calling in Google GenAI Java SDK. Aug 25, 2026
@copybara-service
copybara-service Bot force-pushed the copybara_964733917 branch 7 times, most recently from 277c7c0 to d170708 Compare August 26, 2026 23:36
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Support Automatic Function Calling (AFC) with non-static instance methods

1 participant