mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-09 04:41:19 -07:00
feat(core): Land experimental auto-truncate / distil for tool output.
This commit is contained in:
@@ -840,6 +840,7 @@ export async function loadCliConfig(
|
||||
skillsSupport: settings.skills?.enabled ?? true,
|
||||
disabledSkills: settings.skills?.disabled,
|
||||
experimentalJitContext: settings.experimental?.jitContext,
|
||||
autoDistillation: settings.experimental?.autoDistillation,
|
||||
experimentalMemoryManager: settings.experimental?.memoryManager,
|
||||
modelSteering: settings.experimental?.modelSteering,
|
||||
topicUpdateNarration: settings.experimental?.topicUpdateNarration,
|
||||
|
||||
@@ -1870,6 +1870,15 @@ const SETTINGS_SCHEMA = {
|
||||
description: 'Enable local and remote subagents.',
|
||||
showInDialog: false,
|
||||
},
|
||||
autoDistillation: {
|
||||
type: 'boolean',
|
||||
label: 'Auto Distillation',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
default: false,
|
||||
description: 'Enable automatic distillation for large tool outputs.',
|
||||
showInDialog: false,
|
||||
},
|
||||
extensionManagement: {
|
||||
type: 'boolean',
|
||||
label: 'Extension Management',
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Auto-distillation Integration > should truncate and summarize massive tool outputs, and we should golden the chat history 1`] = `
|
||||
[
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "<SESSION_CONTEXT>",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "Fetch the massive file.",
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "I will now fetch the data.",
|
||||
},
|
||||
{
|
||||
"functionCall": {
|
||||
"args": {
|
||||
"command": "cat large.txt",
|
||||
},
|
||||
"id": "<CALL_ID>",
|
||||
"name": "run_shell_command",
|
||||
},
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "<CALL_ID>",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output too large. Showing first 10 and last 40 characters. For full output see: <TEST_DIR>/.gemini/tmp/<APP_RIG_ID>/tool-outputs/session-<SESSION_ID>/run_shell_command_<TIMESTAMP>_<INDEX>.txt
|
||||
Output: ca
|
||||
|
||||
... [39 characters omitted] ...
|
||||
|
||||
|
||||
Exit Code: 1
|
||||
Process Group PGID: <PGID>
|
||||
|
||||
--- Structural Map of Truncated Content ---
|
||||
- Line 1: Header
|
||||
- Lines 2-5000: User data
|
||||
- Line 5001: Footer",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
"role": "user",
|
||||
},
|
||||
{
|
||||
"parts": [
|
||||
{
|
||||
"text": "I got the summarized output. Task complete.",
|
||||
},
|
||||
],
|
||||
"role": "model",
|
||||
},
|
||||
]
|
||||
`;
|
||||
68
packages/cli/src/integration-tests/autoDistillation.test.tsx
Normal file
68
packages/cli/src/integration-tests/autoDistillation.test.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { AppRig } from '../test-utils/AppRig.js';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { FakeContentGenerator } from '@google/gemini-cli-core';
|
||||
import { PolicyDecision } from '@google/gemini-cli-core';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
describe('Auto-distillation Integration', () => {
|
||||
let rig: AppRig | undefined;
|
||||
|
||||
afterEach(async () => {
|
||||
if (rig) {
|
||||
await rig.unmount();
|
||||
}
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should truncate and summarize massive tool outputs, and we should golden the chat history', async () => {
|
||||
const fakeResponsesPath = path.join(
|
||||
__dirname,
|
||||
'../test-utils/fixtures/auto-distillation.responses',
|
||||
);
|
||||
const contentGenerator =
|
||||
await FakeContentGenerator.fromFile(fakeResponsesPath);
|
||||
rig = new AppRig({
|
||||
contentGenerator,
|
||||
configOverrides: { autoDistillation: true },
|
||||
});
|
||||
|
||||
await rig.initialize();
|
||||
|
||||
const config = rig.getConfig();
|
||||
// 50 chars threshold. > 75 chars triggers summarization
|
||||
vi.spyOn(config, 'getTruncateToolOutputThreshold').mockReturnValue(50);
|
||||
|
||||
rig.setToolPolicy('run_shell_command', PolicyDecision.ASK_USER);
|
||||
|
||||
rig.setMockCommands([
|
||||
{
|
||||
command: /cat large.txt/,
|
||||
result: {
|
||||
output: 'A'.repeat(100),
|
||||
exitCode: 0,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
await rig.render();
|
||||
await rig.waitForIdle();
|
||||
|
||||
await rig.sendMessage('Fetch the massive file.');
|
||||
|
||||
await rig.waitForOutput('Shell');
|
||||
await rig.resolveTool('Shell');
|
||||
|
||||
await rig.waitForOutput('Task complete.');
|
||||
|
||||
expect(rig.getCuratedHistory()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"role":"model","parts":[{"text":"I will now fetch the data."},{"functionCall":{"name":"run_shell_command","args":{"command":"cat large.txt"}}}]},"finishReason":"STOP"}]}]}
|
||||
{"method":"generateContent","response":{"candidates":[{"content":{"role":"model","parts":[{"text":"- Line 1: Header\n- Lines 2-5000: User data\n- Line 5001: Footer"}]},"finishReason":"STOP"}]}}
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"role":"model","parts":[{"text":"I got the summarized output. Task complete."}]},"finishReason":"STOP"}]}]}
|
||||
Reference in New Issue
Block a user