Skip to content

Add support for system instructions in the ondevice sdk. - #8663

Merged
VinayGuthal merged 3 commits into
mainfrom
add_system_instructions
Oct 6, 2026
Merged

VinayGuthal merged 3 commits into
mainfrom
add_system_instructions

Conversation

@VinayGuthal

@VinayGuthal VinayGuthal commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for systemInstruction when generating content using on-device and hybrid inference modes.

Summary of Changes

  • firebase-ai-ondevice-interop: Added an optional systemInstruction: TextPart? property to GenerateContentRequest and updated api.txt.
  • firebase-ai-ondevice: Updated GenerateContentRequest.toMlKit() in Converters.kt to convert the interop TextPart into an ML Kit SystemInstruction.
  • firebase-ai:
    • Passed systemInstruction from GenerativeModel.Builder to OnDeviceGenerativeModelProvider.
    • Updated OnDeviceGenerativeModelProvider to validate that systemInstruction contains only text parts (throwing FirebaseAIOnDeviceInvalidRequestException for non-text parts), concatenate multiple TextPart instances with a newline, and attach it to the on-device request.
  • Tests & Changelogs: Added unit tests in ConvertersTest, GenerativeModelBuilderTests, and OnDeviceGenerativeModelProviderTests, and updated CHANGELOG.md across all three modules.

Tested updating the quickstart app to add testing functionality for system instruction at firebase/quickstart-android#2846

@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

github-actions Bot commented Oct 1, 2026

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
VinayGuthal requested a review from rlazo October 1, 2026 20:39
@VinayGuthal VinayGuthal changed the title add system instructions Add support for system instructions in the ondevice sdk. Oct 1, 2026
@rlazo

rlazo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/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 systemInstruction in on-device content generation requests across the firebase-ai-ondevice-interop, firebase-ai-ondevice, and firebase-ai modules. It includes API updates, converters, validation logic to ensure only text parts are used in system instructions, and comprehensive unit tests. The feedback suggests optimizing the validation logic in OnDeviceGenerativeModelProvider to avoid filtering the parts list twice in the happy path.

@rlazo rlazo 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.

Shouldn't the other api.txt files be updated too?

Comment thread ai-logic/firebase-ai-ondevice-interop/CHANGELOG.md Outdated
Comment thread ai-logic/firebase-ai-ondevice/CHANGELOG.md Outdated
Comment thread ai-logic/firebase-ai/CHANGELOG.md Outdated
@VinayGuthal
VinayGuthal force-pushed the add_system_instructions branch from a5c77a5 to e745be5 Compare October 6, 2026 14:20
@VinayGuthal
VinayGuthal requested a review from rlazo October 6, 2026 15:34
@VinayGuthal

Copy link
Copy Markdown
Contributor Author

Shouldn't the other api.txt files be updated too?

I have run the apitext command for all sdks.

@VinayGuthal
VinayGuthal merged commit 46ae3a2 into main Oct 6, 2026
39 of 41 checks passed
@VinayGuthal
VinayGuthal deleted the add_system_instructions branch October 6, 2026 15:42
@github-actions github-actions Bot mentioned this pull request Oct 7, 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