-
Notifications
You must be signed in to change notification settings - Fork 223
Open
Labels
api:gemini-apipriority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Bug Report: sendMessage/ sendMessageStream return empty response when a specific systemInstruction is used with googleSearch tool
Description
I am experiencing an issue with the @google/genai SDK where sendMessageStream returns an empty response when both systemInstruction and googleSearch tool are configured.
Key Findings:
googleSearch+systemInstruction: The stream async iterator never yields. The loopfor await (const chunk of result)is never entered.googleSearchONLY: If I removesystemInstruction, the API works correctly.urlContext: AddingurlContextalso seems to cause 100% empty responses, similar to this issue.sendMessage: When I switch to the non-streamingsendMessagemethod, it also returns an empty response with"finishReason": "STOP".
Reproduction Code
I am using @google/genai (version ^1.41.0).
import { GoogleGenAI } from "@google/genai";
const API_KEY = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenAI({ apiKey: API_KEY });
async function run() {
try {
const systemInstruction = `...`; // (Long system prompt)
// Scenario 1: FAILS (Stream loop is not entered)
const chat = genAI.chats.create({
model: "gemini-2.5-flash",
config: {
systemInstruction: systemInstruction, // <--- Presence of this causes the issue when combined with tools
tools: [
{ googleSearch: {} },
// { urlContext: {} } // <--- Adding this causes 100% empty responses
],
}
});
// Scenario 2: WORKS (If systemInstruction is removed)
/*
const chat = genAI.chats.create({
model: "gemini-2.5-flash",
config: {
// systemInstruction: systemInstruction, // <--- Commenting this out fixes the issue
tools: [
{ googleSearch: {} },
],
}
});
*/
const message = "...";
console.log(`User: ${message}\n`);
const result = await chat.sendMessageStream({ message });
console.log("Stream started...");
// PROBLEM: This loop is NEVER entered in Scenario 1
for await (const chunk of result) {
const chunkText = chunk.text();
process.stdout.write(chunkText);
}
console.log(`\n\n[Stream ended]`);
} catch (error) {
console.error("\nError:", error);
}
}
run();Environment
- SDK:
@google/genai@1.41.0 - OS: macOS
Full Reproduction Code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api:gemini-apipriority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.