feat(plan): unify workflow location in system prompt to optimize caching#18258
feat(plan): unify workflow location in system prompt to optimize caching#18258
Conversation
Summary of ChangesHello @jerop, 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 refactors the system prompt generation logic to enhance efficiency and maintainability. It unifies the placement of primary and planning workflow sections within the prompt, ensuring a consistent structure that maximizes the static content prefix. This strategic change is designed to improve prompt caching performance and reduce latency by allowing more of the prompt to be cached across different operational modes. Additionally, the refactor includes renaming key interfaces and functions for better clarity and introduces environmental variable control for the planning workflow. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
…ze caching Moves the 'Primary Workflows' and 'Planning Workflows' sections to a shared, consistent location within the system prompt. Previously, 'Primary Workflows' appeared in the middle of the prompt, while 'Planning Workflows' appeared at the very end. By placing both sections in the same logical slot, we ensure that all preceding static content (Preamble, Mandates, Skills, Contexts) remains identical regardless of the active mode. The system now renders exactly one of these two mutually exclusive workflows at this position. Changes: - Unified Location: Both workflow sections now reside immediately after 'Hook Context' and before 'Operational Guidelines', following the shared static prefix. - Renaming: Renamed 'ApprovalModePlanOptions' to 'PlanningWorkflowOptions' and 'renderApprovalModePlan' to 'renderPlanningWorkflow' for consistency. - Simplification: 'renderFinalShell' now strictly handles appending user memory, removing hidden logic injections. - Logic Consistency: Wrapped 'planningWorkflow' in 'withSection' with an explicit 'isPlanMode' guard, matching the pattern of other optional prompt components. - Configurable: 'Planning Workflows' can now be disabled via environment variables (GEMINI_PROMPT_PLANNINGWORKFLOW=0), just like 'Primary Workflows' can be disabled with GEMINI_PROMPT_PRIMARYWORKFLOWS=0. This change maximizes the static shared prefix between modes, ensuring that core workflow instructions remain part of the high-value cached prefix even as user memory evolves.
c4b66ae to
11770aa
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the system prompt generation to unify the location of 'Primary Workflows' and 'Planning Workflows', enhancing prompt caching performance. However, this refactor inadvertently weakens 'Plan Mode' security by moving its core constraints from the end to the middle of the prompt, increasing susceptibility to prompt injection attacks via userMemory. Specifically, moving planningWorkflow and removing planOptions from the end of the prompt allows untrusted userMemory to more easily override critical constraints. To address this, consider moving planningWorkflow back to the end or reinforcing Plan Mode constraints in the Final Reminder section when isPlanMode is active. Additionally, for performance optimization, it is recommended to create the Set of tool names only once at the beginning of the getCoreSystemPrompt method.
|
Size Change: +94 B (0%) Total Size: 23.7 MB ℹ️ View Unchanged
|
Moves the 'Primary Workflows' and 'Planning Workflows' sections to a shared, consistent location within the system prompt.
Previously, 'Primary Workflows' appeared in the middle of the prompt, while 'Planning Workflows' appeared at the very end. By placing both sections in the same logical slot, we ensure that all preceding static content (Preamble, Mandates, Skills, Contexts) remains identical regardless of the active mode. The system now renders exactly one of these two mutually exclusive workflows at this position. This change maximizes the static shared prefix between modes, improving prompt caching performance and reducing latency.
Changes:
GEMINI_PROMPT_PLANNINGWORKFLOW=0, just like 'Primary Workflows' can be disabled withGEMINI_PROMPT_PRIMARYWORKFLOWS=0.Closes #17555