From 23197151c2384c3ef9b72e3c83b6e0d87d738d14 Mon Sep 17 00:00:00 2001 From: anj-s <32556631+anj-s@users.noreply.github.com> Date: Fri, 11 Jul 2025 09:29:08 -0700 Subject: Summarize tool call outputs using tool specific summarizers (#3745) --- packages/core/src/tools/shell.ts | 4 +++- packages/core/src/tools/tool-registry.ts | 2 ++ packages/core/src/tools/tools.ts | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) (limited to 'packages/core/src/tools') diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index c8fa6ba7..e9f59f10 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -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 }; } } diff --git a/packages/core/src/tools/tool-registry.ts b/packages/core/src/tools/tool-registry.ts index 1778c6d6..4040e4ce 100644 --- a/packages/core/src/tools/tool-registry.ts +++ b/packages/core/src/tools/tool-registry.ts @@ -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; @@ -47,6 +48,7 @@ Signal: Signal number or \`(none)\` if no signal was received. parameterSchema, false, // isOutputMarkdown false, // canUpdateOutput + defaultSummarizer, ); } diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index 5347caa0..e99eda92 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -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. -- cgit v1.2.3