Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packages/core/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,37 @@ export class GeminiClient {
async startChat(extraHistory?: Content[]): Promise<GeminiChat> {
this.forceFullIdeContext = true;
this.hasFailedCompressionAttempt = false;
const envParts = await getEnvironmentContext(this.config);

const toolRegistry = this.config.getToolRegistry();
const toolDeclarations = toolRegistry.getFunctionDeclarations();
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[] = [
{
role: 'user',
parts: envParts,
},
{
role: 'model',
parts: [{ text: 'Got it. Thanks for the context!' }],
parts: [{ text: allSetupText }],
},
...(extraHistory ?? []),
];

try {
const userMemory = this.config.getUserMemory();
const systemInstruction = getCoreSystemPrompt(userMemory);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/turn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('Turn', () => {
expect(reportError).toHaveBeenCalledWith(
error,
'Error when talking to Gemini API',
[...historyContent, reqParts],
[...historyContent, { role: 'user', parts: reqParts }],
'Turn.run-sendMessageStream',
);
});
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/core/turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../utils/errors.js';
import type { GeminiChat } from './geminiChat.js';
import { parseThought, type ThoughtSummary } from '../utils/thoughtUtils.js';
import { createUserContent } from '@google/genai';

// Define a structure for tools passed to the server
export interface ServerTool {
Expand Down Expand Up @@ -306,7 +307,10 @@ export class Turn {
throw error;
}

const contextForReport = [...this.chat.getHistory(/*curated*/ true), req];
const contextForReport = [
...this.chat.getHistory(/*curated*/ true),
createUserContent(req),
];
await reportError(
error,
'Error when talking to Gemini API',
Expand Down