Skip to content

[AI] Add hybrid support with Foundation Models - #16111

Merged
andrewheard merged 14 commits into
mainfrom
ah/ai-afm-hybrid
Apr 24, 2026
Merged

[AI] Add hybrid support with Foundation Models#16111
andrewheard merged 14 commits into
mainfrom
ah/ai-afm-hybrid

Conversation

@andrewheard

Copy link
Copy Markdown
Contributor

Conformed FirebaseAI.SystemLanguageModel to LanguageModel to add support for on-device inference using the Foundation Models framework. This allows FirebaseAI.SystemLanguageModel to be used in a HybridModel for hybrid inference locally and in the cloud with Gemini.

#no-changelog

@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

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.

@danger-firebase-ios

Copy link
Copy Markdown
1 Warning
⚠️ New public headers were added, did you remember to add them to the umbrella header?

Generated by 🚫 Danger

Comment thread FirebaseAI/Sources/Extensions/Public/SystemLanguageModel+LanguageModel.swift Outdated
@andrewheard andrewheard modified the milestone: 12.13.0 - M180 Apr 23, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request integrates Apple's Foundation Models framework into the Firebase AI SDK, enabling on-device language model inference. By conforming the system model to the existing LanguageModel protocol, it allows developers to create hybrid inference workflows that combine local processing with cloud-based Gemini models. The changes include necessary infrastructure for prompt conversion, tool validation, and updated API surface area to facilitate this new hybrid functionality.

Highlights

  • Foundation Models Integration: Conformed FirebaseAI.SystemLanguageModel to LanguageModel to enable on-device inference using Apple's Foundation Models framework.
  • Hybrid Inference Support: Enabled the use of FirebaseAI.SystemLanguageModel within a HybridModel, allowing for seamless switching between local on-device inference and cloud-based Gemini models.
  • Tooling and Validation: Added validation and assertions to ensure only supported tools and function declarations are used when leveraging on-device models.
  • API Enhancements: Introduced a new systemModel() provider method and updated error handling to support the new hybrid capabilities.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Activity
  • Initial pull request created by andrewheard.
  • Gemini Code Assist documentation comment posted.
  • Danger bot identified a warning regarding new public headers.
  • Reviewer paulb777 suggested adding assertions for unsupported tool types.
  • Author andrewheard implemented assertions for manual function calls and unsupported tools in response to feedback.
  • Author requested a summary of the pull request.

@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 integrates Apple's Foundation Models framework into FirebaseAI, enabling on-device language model support via the new SystemLanguageModel. The changes include session management for on-device models, prompt conversion logic, and tool compatibility validation. Review feedback suggests ensuring consistent platform support by adding visionOS 26.0 to several @available attributes and refactoring the _hasHistory property to use more idiomatic Swift.

Comment thread FirebaseAI/Sources/Extensions/Internal/LanguageModelSession+ModelSession.swift Outdated
Comment thread FirebaseAI/Sources/Extensions/Internal/LanguageModelSession+ModelSession.swift Outdated
Comment thread FirebaseAI/Sources/Protocols/Internal/ConvertibleToGeneratedContent.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/Part.swift Outdated
@andrewheard

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 integrates Apple's Foundation Models into the FirebaseAI framework, introducing the SystemLanguageModel and support for hybrid model configurations. The changes include session management, response streaming, and prompt conversion logic for on-device models, along with updated tool compatibility checks and integration tests. Review feedback identifies missing visionOS 26.0 availability markers in several files, recommending their addition for consistency with the rest of the platform support implementation.

Comment thread FirebaseAI/Sources/Extensions/Internal/LanguageModelSession+ModelSession.swift Outdated
Comment thread FirebaseAI/Sources/Protocols/Internal/ConvertibleToGeneratedContent.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/Part.swift Outdated

@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 integrates Apple's Foundation Models framework into Firebase AI, enabling the use of on-device system language models. It introduces SystemLanguageModel as a LanguageModel provider, implements session management, and provides conversion logic for prompts and tools. A critical issue was identified in the _startSession implementation where the LanguageModelSession initializer is missing a required model argument, which will lead to a compilation error. Additionally, feedback suggests using TextPart for better consistency with the public API and improving documentation regarding the current limitation of only supporting text-based prompt parts.

Comment thread FirebaseAI/Sources/Extensions/Public/SystemLanguageModel+LanguageModel.swift Outdated
Comment thread FirebaseAI/Sources/Extensions/Internal/LanguageModelSession+ModelSession.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/Part.swift

@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 integrates Apple's Foundation Models into the Firebase AI SDK to support on-device language model sessions. It implements the necessary protocols for LanguageModelSession, adds a SystemLanguageModel provider, and includes logic for prompt and tool conversion. Integration tests for hybrid model fallbacks and unit tests for session initialization are also included. Feedback was provided to improve the robustness of tool compatibility checks by throwing errors instead of using assertions.

@andrewheard
andrewheard marked this pull request as ready for review April 23, 2026 23:43
@andrewheard
andrewheard requested a review from a team as a code owner April 23, 2026 23:43
@andrewheard
andrewheard requested a review from paulb777 April 23, 2026 23:44
@andrewheard

Copy link
Copy Markdown
Contributor Author

@paulb777 Please ignore the CI failure for now. Attempting to address in #16115.

@andrewheard
andrewheard merged commit b1c9e27 into main Apr 24, 2026
87 checks passed
@andrewheard
andrewheard deleted the ah/ai-afm-hybrid branch April 24, 2026 03:45
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.

2 participants