Skip to content

Function calling support for on device sdk. - #8758

Merged
VinayGuthal merged 8 commits into
mainfrom
add_function_calling_support
Oct 30, 2026
Merged

VinayGuthal merged 8 commits into
mainfrom
add_function_calling_support

Conversation

@VinayGuthal

@VinayGuthal VinayGuthal commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Tested at firebase/quickstart-android#2855

Description

Adds support for function calling when generating content using on-device and hybrid (PREFER_ON_DEVICE) inference modes, following the ML Kit GenAI Prompt APIs.

When function calling tools are supplied, OnDeviceGenerativeModelProvider verifies that the underlying on-device model supports function calling via isFunctionCallingAvailable(). If function calling is not supported by the on-device model or if unsupported non-function tools (such as Google Search or Code Execution) are configured, a FirebaseAIOnDeviceNotAvailableException is raised, triggering automatic fallback to cloud inference in PREFER_ON_DEVICE mode.

Summary of Changes

  • gradle/libs.versions.toml:

    • Updated genaiPrompt to 1.0.0-beta5 and genaiSchema to 1.0.0-alpha2.
  • ai-logic/firebase-ai-ondevice-interop:

    • Added FunctionDeclaration and FunctionSchema interop data structures.
    • Added FunctionCallPart and FunctionResponsePart to Part.kt.
    • Added functionCalls: List<FunctionCallPart> to Candidate.
    • Added tools: List<FunctionDeclaration>? to GenerateContentRequest.
    • Added suspend fun isFunctionCallingAvailable(): Boolean to GenerativeModel.
    • Updated api.txt and CHANGELOG.md.
  • ai-logic/firebase-ai-ondevice:

    • Implemented GenerativeModelImpl.isFunctionCallingAvailable() delegating to ML Kit's getAvailableFeatures().contains(Feature.FUNCTION_CALLING).
    • Added converters in Converters.kt for FunctionCallPart, FunctionResponsePart, FunctionDeclaration, and FunctionSchema to/from ML Kit equivalents.
    • Mapped candidate function calls in GenerateContentResponse.toInterop().
    • Updated api.txt and CHANGELOG.md.
    • Added unit test coverage in GenerativeModelImplTest and ConvertersTest.
  • ai-logic/firebase-ai:

    • Added tools: List<Tool>? = null to OnDeviceConfig to allow configuring tools for on-device inference, defaulting to model-level tools when omitted.
    • Forwarded tools configuration in GenerativeModel to OnDeviceGenerativeModelProvider.
    • Updated Candidate.fromInterop to convert interop function calls into FunctionCallPart instances.
    • In OnDeviceGenerativeModelProvider:
      • Checks onDeviceModel.isFunctionCallingAvailable() when function declarations are provided.
      • Throws FirebaseAIOnDeviceNotAvailableException if non-function tools are passed to on-device inference or if function calling is unsupported.
      • Converts FunctionCallPart and FunctionResponsePart in conversation history.
      • Maps function declarations and auto-function declarations into interop schemas.
    • Updated api.txt and CHANGELOG.md.
    • Added unit tests in OnDeviceGenerativeModelProviderTests covering tool execution, candidate mapping, multi-turn history with function responses, streaming support, and cloud fallback behavior.

Testing

  • ./gradlew :ai-logic:firebase-ai-ondevice-interop:check
  • ./gradlew :ai-logic:firebase-ai-ondevice:check
  • ./gradlew :ai-logic:firebase-ai:check
  • ./gradlew spotlessCheck

@gemini-code-assist

Copy link
Copy Markdown
Contributor
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 the 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 counterproductive. 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.

@github-actions

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@VinayGuthal

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 support for function calling in on-device content generation requests and responses across the 'firebase-ai-ondevice-interop', 'firebase-ai-ondevice', and 'firebase-ai' modules. It adds new classes such as 'FunctionCallPart', 'FunctionDeclaration', 'FunctionResponsePart', and 'FunctionSchema', along with corresponding converters and comprehensive unit tests. Feedback on the changes suggests ensuring that the 'nullable' property is correctly propagated during schema conversions in 'Schema.toInterop()' and 'JsonSchema<*>.toInterop()' to respect nullability constraints.

VinayGuthal and others added 2 commits October 28, 2026 14:40
…nerativemodel/OnDeviceGenerativeModelProvider.kt

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…nerativemodel/OnDeviceGenerativeModelProvider.kt

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@VinayGuthal VinayGuthal changed the title Add function calling. Function calling support for on device sdk. Oct 28, 2026
@VinayGuthal
VinayGuthal force-pushed the add_function_calling_support branch from 7669591 to 2aad1ca Compare October 30, 2026 15:35
@VinayGuthal
VinayGuthal requested a review from rlazo October 30, 2026 17:51
@VinayGuthal
VinayGuthal merged commit 752de10 into main Oct 30, 2026
177 of 182 checks passed
@VinayGuthal
VinayGuthal deleted the add_function_calling_support branch October 30, 2026 18:45
@github-actions github-actions Bot mentioned this pull request Oct 31, 2026
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.

2 participants