Skip to content

Commit 9fa5fc4

Browse files
committed
tool output summarization integrated with build test tool - prompt tuning needed.
1 parent 6d87aff commit 9fa5fc4

4 files changed

Lines changed: 63 additions & 7 deletions

File tree

.gemini/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
"gemmaSubagentSettings": {
77
"enabled": false,
88
// "model": "gemma3n:e4b"
9-
"model": "gemma3:12b"
9+
"model": "gemma3:12b",
10+
"subagentSummarizeToolOutput": { "enabled": false }
1011
},
1112
"buildAndTestSettings": {
1213
"enabled": true,
1314
// "model": "gemma3n:e4b"
14-
"model": "gemma3:12b"
15+
"model": "gemma3:12b",
1516
// "model": "gemma3:12b"
17+
"subagentSummarizeToolOutput": { "enabled": true }
1618
},
1719
"useModelRouter": {
1820
"useGemmaRouting": {

packages/core/src/agents/executor.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
/* eslint-disable @typescript-eslint/no-unused-vars */
88

99
import { Type } from '@google/genai';
10-
import type { Config } from '../config/config.js';
10+
import type {
11+
Config,
12+
SubagentSummarizeToolOutputSettings,
13+
} from '../config/config.js';
1114
import { reportError } from '../utils/errorReporting.js';
1215
import { OllamaChat } from '../core/ollamaChat.js';
1316
import { GeminiChat, StreamEventType } from '../core/geminiChat.js';
@@ -1346,8 +1349,29 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
13461349
const toolResponsePartsToReturn: GeminiPart[] =
13471350
toolResponse.responseParts;
13481351

1349-
// Apply summarization if enabled and content is present
1350-
if (this.definition.runConfig.summarizeToolOutput) {
1352+
// Apply summarization if the specific subagent config has it enabled.
1353+
const agentName = this.definition.name;
1354+
let agentSummarizeConfig:
1355+
| SubagentSummarizeToolOutputSettings
1356+
| undefined;
1357+
1358+
if (agentName === 'codebase_investigator') {
1359+
agentSummarizeConfig =
1360+
this.runtimeContext.getCodebaseInvestigatorSettings()
1361+
.subagentSummarizeToolOutput;
1362+
} else if (agentName === 'gemma_agent') {
1363+
agentSummarizeConfig =
1364+
this.runtimeContext.getGemmaSubagentSettings()
1365+
.subagentSummarizeToolOutput;
1366+
} else if (agentName === 'build_and_test_agent') {
1367+
agentSummarizeConfig =
1368+
this.runtimeContext.getBuildAndTestSettings()
1369+
.subagentSummarizeToolOutput;
1370+
}
1371+
1372+
// IMPORTANT: Only summarize if the agent-specific config is present and enabled.
1373+
// Do not fall back to a global setting.
1374+
if ((agentSummarizeConfig as { enabled?: boolean })?.enabled) {
13511375
const summary = await this.summarizationService.summarize(
13521376
toolResponse.responseParts,
13531377
this.definition.modelConfig,
@@ -1358,8 +1382,6 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
13581382
);
13591383
for (const part of toolResponsePartsToReturn) {
13601384
if ('functionResponse' in part && part.functionResponse) {
1361-
// This is a bit awkward, but `response` is just `object`
1362-
// in the type, so we have to cast.
13631385
const responseObject = part.functionResponse.response as {
13641386
llmContent?: unknown;
13651387
};
@@ -1370,6 +1392,10 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
13701392
}
13711393
}
13721394
}
1395+
} else {
1396+
debugLogger.log(
1397+
`[AgentExecutor] Skipping summarization for tool: ${functionCall.name} (ID: ${callId})`,
1398+
);
13731399
}
13741400

13751401
return toolResponsePartsToReturn;

packages/core/src/config/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export interface SummarizeToolOutputSettings {
102102
tokenBudget?: number;
103103
}
104104

105+
export interface SubagentSummarizeToolOutputSettings {
106+
enabled?: boolean;
107+
}
108+
105109
export interface TelemetrySettings {
106110
enabled?: boolean;
107111
target?: TelemetryTarget;
@@ -122,18 +126,21 @@ export interface CodebaseInvestigatorSettings {
122126
maxTimeMinutes?: number;
123127
thinkingBudget?: number;
124128
model?: string;
129+
subagentSummarizeToolOutput?: SubagentSummarizeToolOutputSettings;
125130
}
126131

127132
export interface GemmaSubagentSettings {
128133
enabled?: boolean;
129134
model?: string;
130135
host?: string;
136+
subagentSummarizeToolOutput?: SubagentSummarizeToolOutputSettings;
131137
}
132138

133139
export interface BuildAndTestSettings {
134140
enabled?: boolean;
135141
model?: string;
136142
host?: string;
143+
subagentSummarizeToolOutput?: SubagentSummarizeToolOutputSettings;
137144
}
138145

139146
export interface UseModelRouterSettings {
@@ -584,11 +591,15 @@ export class Config {
584591
enabled: params.gemmaSubagentSettings?.enabled ?? false,
585592
model: params.gemmaSubagentSettings?.model ?? 'gemma3n:e2b',
586593
host: params.gemmaSubagentSettings?.host ?? 'http://localhost:11434',
594+
subagentSummarizeToolOutput:
595+
params.gemmaSubagentSettings?.subagentSummarizeToolOutput,
587596
};
588597
this.buildAndTestSettings = {
589598
enabled: params.buildAndTestSettings?.enabled ?? false,
590599
model: params.buildAndTestSettings?.model ?? 'gemma3n:e4b',
591600
host: params.buildAndTestSettings?.host ?? 'http://localhost:11434',
601+
subagentSummarizeToolOutput:
602+
params.buildAndTestSettings?.subagentSummarizeToolOutput,
592603
};
593604
// debugLogger.log(
594605
// `[DEBUG] Codebase Investigator Settings: ${JSON.stringify(this.codebaseInvestigatorSettings)}`,

packages/core/src/services/summarizer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { OllamaModelConfig, ModelConfig } from '../agents/types.js';
88
import { type Part as OllamaPart, OllamaChat } from '../core/ollamaChat.js';
99
import type { Part as GeminiPart } from '@google/genai';
1010
import { StreamEventType } from '../core/geminiChat.js';
11+
import { debugLogger } from '../utils/debugLogger.js';
12+
import * as fs from 'node:fs/promises';
1113

1214
const SUMMARIZER_SYSTEM_PROMPT = `You are a text summarizer. Your sole purpose is to receive text and provide a concise, factual summary of it. Do not add any commentary or analysis. Focus on the key information presented in the text.`;
1315

@@ -18,6 +20,9 @@ export class SummarizationService {
1820
tollResponseParts: GeminiPart[],
1921
modelConfig: OllamaModelConfig | ModelConfig,
2022
): Promise<string | null> {
23+
debugLogger.log(
24+
`[SummarizationService] Starting summarization using model: ${modelConfig.model}`,
25+
);
2126
if ('host' in modelConfig) {
2227
const userParts: OllamaPart[] = [];
2328
for (const part of tollResponseParts) {
@@ -58,6 +63,18 @@ export class SummarizationService {
5863
}
5964
}
6065

66+
try {
67+
await fs.writeFile('summarized_tool_output.txt', textResponse);
68+
debugLogger.log(
69+
'[DEBUG] Summarized tool output saved to summarized_tool_output.txt',
70+
);
71+
} catch (error) {
72+
debugLogger.error(
73+
'[DEBUG] Failed to save summarized tool output to summarized_tool_output.txt:',
74+
error,
75+
);
76+
}
77+
6178
// Just return the raw text response from the summarizer model.
6279
return textResponse;
6380
} else {

0 commit comments

Comments
 (0)