Skip to content

RFC: Foreground/Background Generate RFC#4892

Draft
ifielker wants to merge 1 commit intomainfrom
if-modeRFC
Draft

RFC: Foreground/Background Generate RFC#4892
ifielker wants to merge 1 commit intomainfrom
if-modeRFC

Conversation

@ifielker
Copy link
Collaborator

@ifielker ifielker commented Mar 6, 2026

Checklist (if applicable):

@github-actions github-actions bot added the docs Improvements or additions to documentation label Mar 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Request for Comments (RFC) document that proposes adding an explicit mode parameter to Genkit's GenerateOptions. This enhancement aims to give developers fine-grained control over whether an AI model runs in 'foreground' (synchronous/streamed) or 'background' (long-running) mode. This change is crucial for future-proofing the API, especially as models evolve to support both execution types, ensuring clarity and explicit choice for users without breaking existing implicit routing behaviors.

Highlights

  • New mode parameter in GenerateOptions: Introduced an optional mode parameter ('foreground' or 'background') to Genkit's GenerateOptions for the generate() method API, allowing explicit control over model execution.
  • Addressing Versatile Models: The mode parameter provides a way to explicitly select execution mode for models capable of both foreground and background operations, which was previously ambiguous with automatic routing.
  • Backwards Compatibility: The change is fully backwards compatible, as existing applications omitting the mode parameter will continue to use the current automatic fallback resolution.
  • Internal Implementation Details: Outlined necessary internal changes, including updating model resolution logic (resolveModel, lookupModel), modifying generateOperation(), and plumbing the mode property through GenerateActionOptionsSchema.

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

Changelog
  • docs/rfc-generate-mode.md
    • Added a new Request for Comments (RFC) document detailing the proposal for a mode parameter in GenerateOptions.
Activity
  • No human activity has been recorded on this pull request yet.
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 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 an RFC for adding a mode parameter to GenerateOptions to allow developers to explicitly choose between foreground and background model execution. The RFC is well-structured and clearly outlines the motivation, API changes, and implementation details for the TypeScript SDK. My feedback focuses on improving the RFC's clarity around error handling and considering the cross-language implications of this core change.

Note: Security Review has been skipped due to the limited scope of the PR.

Comment on lines +93 to +95
## Internal Implementation Details

*This section details the architectural changes required under the hood to support the new `mode` parameter.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This RFC provides a solid plan for the TypeScript implementation. Since GenerateOptions is a core concept in Genkit, it would be valuable for this RFC to briefly touch upon the implications for other supported languages like Go and Python.

Mentioning how this change would propagate to other SDKs would make the RFC more comprehensive. For example, would GenerateActionOptions in Go and Python also get the mode field? A short section or a note on cross-language consistency would be a great addition.

Comment on lines +100 to +103
The internal model lookup utilities (`resolveModel` and `lookupModel` in `js/ai/src/model.ts`) must be updated to respect the `mode` parameter:
- If `mode: 'foreground'` is passed, it strictly targets the `/model/{name}` registry path.
- If `mode: 'background'` is passed, it strictly targets the `/background-model/{name}` registry path.
- If `mode` is `undefined`, it maintains the legacy automatic fallback chain (try `/model/` first, then `/background-model/`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The proposed resolution logic is clear. To further improve clarity, it would be beneficial to explicitly state the behavior when a user provides an explicit mode but no model supporting that mode is found. For example, if a user specifies mode: 'foreground' for a model that only has a background implementation.

I suggest adding a note about error handling, for instance:

If an explicit mode is provided but no model supporting that mode is found under the given name, the resolution should fail with a NOT_FOUND error. This ensures the developer's explicit intent is respected and prevents accidentally falling back to a different execution mode.

@ifielker ifielker added the rfc label Mar 6, 2026
@ifielker ifielker changed the title docs: Foreground/Background Generate RFC rfc: Foreground/Background Generate RFC Mar 6, 2026
@ifielker ifielker changed the title rfc: Foreground/Background Generate RFC RFC: Foreground/Background Generate RFC Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation rfc

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant