mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
# Fix Topic Marker Leakage and Address Reinjection Inquiry
This PR addresses issue #26237 where the text `[active topic]` would sometimes appear in the Gemini CLI output. It also addresses an inquiry regarding the necessity of active topic reinjection in the system prompt. ## Changes - **Refactored Reinjection Format:** Changed the active topic reinjection in `PromptProvider.ts` from bracketed text `[Active Topic: ...]` to XML tags (`<active_topic>...`</active_topic>`). XML tags are more clearly structural metadata and less likely to be echoed as conversational text by the model. - **Added Explicit Instructions:** Updated `mandateTopicUpdateModel` in both `snippets.ts` and `snippets.legacy.ts` to include a clear negative constraint: "Never include topic markers, title text, or the active topic marker (e.g. `[active topic]` or `<active_topic>`) in your chat responses." - **Updated Tests:** Verified the new format in `promptProvider.test.ts`. ## Rationale for Reinjection Regarding the inquiry about why the active topic is reinjected: The reinjection serves as a "pinned state" in the system prompt. While the model can theoretically remember the topic from the tool call history, reinjection ensures that this critical context is preserved even if the history is truncated or compressed during long sessions. It provides a stable anchor for the model to maintain continuity in its progress reporting. ## Impact - Resolves the reported leakage of topic markers in chat responses. - Improves the reliability of topic-based progress narration.
This commit is contained in:
@@ -358,7 +358,7 @@ describe('PromptProvider', () => {
|
||||
const provider = new PromptProvider();
|
||||
const prompt = provider.getCoreSystemPrompt(mockConfig);
|
||||
|
||||
expect(prompt).toContain('[Active Topic: Active Chapter]');
|
||||
expect(prompt).toContain('<active_topic>\nActive Chapter\n</active_topic>');
|
||||
});
|
||||
|
||||
it('should NOT include active topic context when narration is disabled', () => {
|
||||
@@ -369,7 +369,7 @@ describe('PromptProvider', () => {
|
||||
const provider = new PromptProvider();
|
||||
const prompt = provider.getCoreSystemPrompt(mockConfig);
|
||||
|
||||
expect(prompt).not.toContain('[Active Topic: Active Chapter]');
|
||||
expect(prompt).not.toContain('<active_topic>\nActive Chapter\n</active_topic>');
|
||||
});
|
||||
|
||||
it('should filter out update_topic tool when narration is disabled', () => {
|
||||
|
||||
@@ -280,8 +280,8 @@ export class PromptProvider {
|
||||
if (activeTopic) {
|
||||
const sanitizedTopic = activeTopic
|
||||
.replace(/\n/g, ' ')
|
||||
.replace(/\]/g, '');
|
||||
sanitizedPrompt += `\n\n[Active Topic: ${sanitizedTopic}]`;
|
||||
.replace(/[\[\]<>]/g, '');
|
||||
sanitizedPrompt += `\n\n<active_topic>\n${sanitizedTopic}\n</active_topic>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -527,6 +527,7 @@ function mandateTopicUpdateModel(): string {
|
||||
## Topic Updates
|
||||
As you work, the user follows along by reading topic updates that you publish with ${UPDATE_TOPIC_TOOL_NAME}. Keep them informed by doing the following:
|
||||
|
||||
- **No topic markers in chat:** Never include topic markers, title text, or the active topic marker (e.g. \`[active topic]\` or \`<active_topic>\`) in your chat responses. All topic and progress updates MUST be communicated exclusively via the ${UPDATE_TOPIC_TOOL_NAME} tool.
|
||||
- Usage Exception: NEVER use ${UPDATE_TOPIC_TOOL_NAME} for answering questions, providing explanations, or performing isolated lookup tasks (e.g. reading a single file, running a quick search, or checking a version). It is STRICTLY for orchestrating multi-step codebase modifications or complex investigations involving 3 or more tool calls.
|
||||
- Always call ${UPDATE_TOPIC_TOOL_NAME} in your first turn.
|
||||
- For tasks taking multiple turns, also call ${UPDATE_TOPIC_TOOL_NAME} in your last turn to recap what was done.
|
||||
|
||||
@@ -656,6 +656,7 @@ function mandateTopicUpdateModel(): string {
|
||||
## Topic Updates
|
||||
As you work, the user follows along by reading topic updates that you publish with ${UPDATE_TOPIC_TOOL_NAME}. Keep them informed by doing the following:
|
||||
|
||||
- **No topic markers in chat:** Never include topic markers, title text, or the active topic marker (e.g. \`[active topic]\` or \`<active_topic>\`) in your chat responses. All topic and progress updates MUST be communicated exclusively via the ${UPDATE_TOPIC_TOOL_NAME} tool.
|
||||
- Usage Exception: NEVER use ${UPDATE_TOPIC_TOOL_NAME} for answering questions, providing explanations, or performing isolated lookup tasks (e.g. reading a single file, running a quick search, or checking a version). It is STRICTLY for orchestrating multi-step codebase modifications or complex investigations involving 3 or more tool calls.
|
||||
- Always call ${UPDATE_TOPIC_TOOL_NAME} in your first turn.
|
||||
- For tasks taking multiple turns, also call ${UPDATE_TOPIC_TOOL_NAME} in your last turn to recap what was done.
|
||||
|
||||
Reference in New Issue
Block a user