mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-12 02:50:41 -07:00
feat: implement explicit context caching for main agent with stable SI hashing
This commit is contained in:
@@ -90,6 +90,22 @@ describe('apiConversionUtils', () => {
|
||||
expect(result['generationConfig']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('omits systemInstruction when cachedContent is present', () => {
|
||||
const req: GenerateContentParameters = {
|
||||
model: 'gemini-3-flash',
|
||||
contents: [{ role: 'user', parts: [{ text: 'Hello' }] }],
|
||||
config: {
|
||||
systemInstruction: 'Original instruction',
|
||||
cachedContent: 'cached-content-id',
|
||||
},
|
||||
};
|
||||
|
||||
const result = convertToRestPayload(req);
|
||||
|
||||
expect(result['cachedContent']).toBe('cached-content-id');
|
||||
expect(result['systemInstruction']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('retains pure hyperparameters in generationConfig', () => {
|
||||
const req: GenerateContentParameters = {
|
||||
model: 'gemini-3-flash',
|
||||
|
||||
@@ -46,12 +46,16 @@ export function convertToRestPayload(
|
||||
}
|
||||
|
||||
// Assign extracted capabilities to the root level.
|
||||
if (restSystemInstruction)
|
||||
// CRITICAL: systemInstruction and cachedContent are mutually exclusive in the API.
|
||||
if (sdkCachedContent) {
|
||||
restPayload['cachedContent'] = sdkCachedContent;
|
||||
} else if (restSystemInstruction) {
|
||||
restPayload['systemInstruction'] = restSystemInstruction;
|
||||
}
|
||||
|
||||
if (sdkTools) restPayload['tools'] = sdkTools;
|
||||
if (sdkToolConfig) restPayload['toolConfig'] = sdkToolConfig;
|
||||
if (sdkSafetySettings) restPayload['safetySettings'] = sdkSafetySettings;
|
||||
if (sdkCachedContent) restPayload['cachedContent'] = sdkCachedContent;
|
||||
|
||||
return restPayload;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ describe('checkNextSpeaker', () => {
|
||||
generateContentStream: vi.fn(),
|
||||
countTokens: vi.fn(),
|
||||
embedContent: vi.fn(),
|
||||
createCachedContent: vi.fn(),
|
||||
updateCachedContent: vi.fn(),
|
||||
} as ContentGenerator,
|
||||
mockConfig,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user