Skip to content

feat(js/core): add overwrite option in definePrompt#4924

Open
7hokerz wants to merge 1 commit intogenkit-ai:mainfrom
7hokerz:7hokerz/core-prompt-registry-logging
Open

feat(js/core): add overwrite option in definePrompt#4924
7hokerz wants to merge 1 commit intogenkit-ai:mainfrom
7hokerz:7hokerz/core-prompt-registry-logging

Conversation

@7hokerz
Copy link
Contributor

@7hokerz 7hokerz commented Mar 14, 2026

Description here... Help the reviewer by:

  • Added an overwrite flag to avoid displaying excessive log messages
  • Current Genkit implementation primarily focuses on static declarations during app initialization.
    (In my personal backend development, I faced a problem with excessive logging during the dynamic prompt management process, especially when applying changes post-initialization.)

Checklist (if applicable):

@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 an overwrite option to the definePrompt and defineAction mechanisms, addressing a common issue in dynamic application environments where re-registering prompts or actions can lead to excessive logging. By allowing developers to explicitly permit overwriting existing definitions, this change provides greater flexibility for managing application configurations post-initialization, particularly in scenarios involving hot-reloading or dynamic updates, without cluttering logs with warnings about duplicate registrations.

Highlights

  • Introduced overwrite option: A new overwrite boolean option has been added to the PromptConfig and ActionParams interfaces, allowing explicit control over re-registration behavior.
  • Enabled dynamic prompt/action registration: The definePrompt and defineAction functions now accept and pass this overwrite option to the underlying registry mechanisms.
  • Suppressed duplicate registration warnings: The Registry class's registerAction and registerActionAsync methods now check the overwrite flag, preventing error logs when re-registering actions or prompts if overwrite is true.

🧠 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
  • js/ai/src/prompt.ts
    • Added overwrite?: boolean to the PromptConfig interface.
    • Modified definePrompt to pass the new options.overwrite parameter to definePromptAsync.
    • Updated definePromptAsync to accept an overwrite?: boolean parameter and pass it to the registry.registerActionAsync calls.
  • js/core/src/action.ts
    • Added overwrite?: boolean to the ActionParams interface.
    • Modified defineAction to pass config.overwrite to the registry.registerAction method.
    • Updated defineActionAsync to accept an opts?: { overwrite?: boolean } parameter and pass it to registry.registerActionAsync.
  • js/core/src/registry.ts
    • Updated the opts parameter in registerAction and registerActionAsync methods to include overwrite?: boolean.
    • Modified the duplicate registration check (this.actionsById.hasOwnProperty(key)) in both registerAction and registerActionAsync to only log an error if opts?.overwrite is not true.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for 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 overwrite option to definePrompt to suppress log messages when re-defining prompts, which is particularly useful for dynamic prompt management. The changes are well-plumbed through definePrompt, defineAction, defineActionAsync, and into the Registry methods registerAction and registerActionAsync. The core logic correctly uses the overwrite flag to conditionally log errors for duplicate registrations.

I have one suggestion regarding the API design of defineActionAsync to improve clarity and prevent potential misuse. Overall, this is a solid improvement.

@MichaelDoyle
Copy link
Contributor

@7hokerz can you speak more to the use case, and why you want/need to register the same prompt multiple times?

I wonder if we should just change the log level from error to warn or even info, and let you filter out the appropriate log level instead. cc @pavelgj

@7hokerz
Copy link
Contributor Author

7hokerz commented Mar 18, 2026

@MichaelDoyle , Thanks for reply.
I am implementing a backend feature that allows prompts to be modified and applied in real-time without requiring a server restart in my company project. The execution flow is:
​A prompt is modified and saved to the database.
​definePrompt is immediately called to update the prompt definition in memory for the running application.

When definePrompt is executed to update an existing prompt, it generates an overwrite warning or log.
The overwrite logs are definitely helpful for preventing errors. However, I’ve noticed they can clutter the console when updates are intentional.

@7hokerz
Copy link
Contributor Author

7hokerz commented Mar 23, 2026

@MichaelDoyle, @pavelgj, Could you please look over the comment I left?

@MichaelDoyle
Copy link
Contributor

@7hokerz if I understand the PR, we're adding an overwrite flag, however, it's only purpose is to flag whether or not a log is written; the registry behavior is unchanged?

If that's the case, I think this is a bit confusing and we're better off just adjusting the log level to warn, so you can more easily filter it out.

@7hokerz
Copy link
Contributor Author

7hokerz commented Mar 24, 2026

@MichaelDoyle , Oh, I think your approach is simpler and more efficient than the current PR. However, my intention was to allow developers to explicitly determine whether the behavior is an error or not through the overwrite option.
I agree with changing it to 'warn,' but personally, I feel that if only this change is made, my intentions ultimately won't be incorporated into the bigger picture.

@7hokerz
Copy link
Contributor Author

7hokerz commented Mar 24, 2026

@MichaelDoyle In that case, would it be best to actually add special logic regarding overwriting here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants