Summarize tool call outputs using tool specific summarizers (#3745)

This commit is contained in:
anj-s
2025-07-11 09:29:08 -07:00
committed by GitHub
parent cdbe2fffd9
commit 23197151c2
9 changed files with 421 additions and 9 deletions

View File

@@ -27,6 +27,7 @@ export interface ShellToolParams {
directory?: string;
}
import { spawn } from 'child_process';
import { llmSummarizer } from '../utils/summarizer.js';
const OUTPUT_UPDATE_INTERVAL_MS = 1000;
@@ -73,6 +74,8 @@ Process Group PGID: Process group started or \`(none)\``,
},
false, // output is not markdown
true, // output can be updated
llmSummarizer,
true, // should summarize display output
);
}
@@ -487,7 +490,6 @@ Process Group PGID: Process group started or \`(none)\``,
// returnDisplayMessage will remain empty, which is fine.
}
}
return { llmContent, returnDisplay: returnDisplayMessage };
}
}

View File

@@ -11,6 +11,7 @@ import { spawn } from 'node:child_process';
import { StringDecoder } from 'node:string_decoder';
import { discoverMcpTools } from './mcp-client.js';
import { DiscoveredMCPTool } from './mcp-tool.js';
import { defaultSummarizer } from '../utils/summarizer.js';
import { parse } from 'shell-quote';
type ToolParams = Record<string, unknown>;
@@ -47,6 +48,7 @@ Signal: Signal number or \`(none)\` if no signal was received.
parameterSchema,
false, // isOutputMarkdown
false, // canUpdateOutput
defaultSummarizer,
);
}

View File

@@ -5,6 +5,7 @@
*/
import { FunctionDeclaration, PartListUnion, Schema } from '@google/genai';
import { Summarizer, defaultSummarizer } from '../utils/summarizer.js';
/**
* Interface representing the base Tool functionality
@@ -43,6 +44,16 @@ export interface Tool<
*/
canUpdateOutput: boolean;
/**
* A function that summarizes the result of the tool execution.
*/
summarizer?: Summarizer;
/**
* Whether the tool's display output should be summarized
*/
shouldSummarizeDisplay?: boolean;
/**
* Validates the parameters for the tool
* Should be called from both `shouldConfirmExecute` and `execute`
@@ -98,6 +109,8 @@ export abstract class BaseTool<
* @param isOutputMarkdown Whether the tool's output should be rendered as markdown
* @param canUpdateOutput Whether the tool supports live (streaming) output
* @param parameterSchema JSON Schema defining the parameters
* @param summarizer Function to summarize the tool's output
* @param shouldSummarizeDisplay Whether the tool's display output should be summarized
*/
constructor(
readonly name: string,
@@ -106,6 +119,8 @@ export abstract class BaseTool<
readonly parameterSchema: Schema,
readonly isOutputMarkdown: boolean = true,
readonly canUpdateOutput: boolean = false,
readonly summarizer: Summarizer = defaultSummarizer,
readonly shouldSummarizeDisplay: boolean = false,
) {}
/**
@@ -173,6 +188,11 @@ export abstract class BaseTool<
}
export interface ToolResult {
/**
* A short, one-line summary of the tool's action and result.
* e.g., "Read 5 files", "Wrote 256 bytes to foo.txt"
*/
summary?: string;
/**
* Content meant to be included in LLM history.
* This should represent the factual outcome of the tool execution.