Revert "Get around the initial empty response from gemini-2.5-flash. … (#10688)

This commit is contained in:
Sandy Tao
2025-10-07 20:15:55 -07:00
committed by GitHub
parent 024aaf95ec
commit a0987602b6
3 changed files with 8 additions and 26 deletions
+6 -20
View File
@@ -221,37 +221,23 @@ export class GeminiClient {
async startChat(extraHistory?: Content[]): Promise<GeminiChat> { async startChat(extraHistory?: Content[]): Promise<GeminiChat> {
this.forceFullIdeContext = true; this.forceFullIdeContext = true;
this.hasFailedCompressionAttempt = false; this.hasFailedCompressionAttempt = false;
const envParts = await getEnvironmentContext(this.config);
const toolRegistry = this.config.getToolRegistry(); const toolRegistry = this.config.getToolRegistry();
const toolDeclarations = toolRegistry.getFunctionDeclarations(); const toolDeclarations = toolRegistry.getFunctionDeclarations();
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }]; const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
// 1. Get the environment context parts as an array
const envParts = await getEnvironmentContext(this.config);
// 2. Convert the array of parts into a single string
const envContextString = envParts
.map((part) => part.text || '')
.join('\n\n');
// 3. Combine the dynamic context with the static handshake instruction
const allSetupText = `
${envContextString}
Reminder: Do not return an empty response when a tool call is required.
My setup is complete. I will provide my first command in the next turn.
`.trim();
// 4. Create the history with a single, comprehensive user turn
const history: Content[] = [ const history: Content[] = [
{ {
role: 'user', role: 'user',
parts: [{ text: allSetupText }], parts: envParts,
},
{
role: 'model',
parts: [{ text: 'Got it. Thanks for the context!' }],
}, },
...(extraHistory ?? []), ...(extraHistory ?? []),
]; ];
try { try {
const userMemory = this.config.getUserMemory(); const userMemory = this.config.getUserMemory();
const systemInstruction = getCoreSystemPrompt(userMemory); const systemInstruction = getCoreSystemPrompt(userMemory);
+1 -1
View File
@@ -251,7 +251,7 @@ describe('Turn', () => {
expect(reportError).toHaveBeenCalledWith( expect(reportError).toHaveBeenCalledWith(
error, error,
'Error when talking to Gemini API', 'Error when talking to Gemini API',
[...historyContent, { role: 'user', parts: reqParts }], [...historyContent, reqParts],
'Turn.run-sendMessageStream', 'Turn.run-sendMessageStream',
); );
}); });
+1 -5
View File
@@ -28,7 +28,6 @@ import {
} from '../utils/errors.js'; } from '../utils/errors.js';
import type { GeminiChat } from './geminiChat.js'; import type { GeminiChat } from './geminiChat.js';
import { parseThought, type ThoughtSummary } from '../utils/thoughtUtils.js'; import { parseThought, type ThoughtSummary } from '../utils/thoughtUtils.js';
import { createUserContent } from '@google/genai';
// Define a structure for tools passed to the server // Define a structure for tools passed to the server
export interface ServerTool { export interface ServerTool {
@@ -307,10 +306,7 @@ export class Turn {
throw error; throw error;
} }
const contextForReport = [ const contextForReport = [...this.chat.getHistory(/*curated*/ true), req];
...this.chat.getHistory(/*curated*/ true),
createUserContent(req),
];
await reportError( await reportError(
error, error,
'Error when talking to Gemini API', 'Error when talking to Gemini API',