summaryrefslogtreecommitdiff
path: root/packages/core/src/tools
diff options
context:
space:
mode:
authoranj-s <[email protected]>2025-07-11 09:29:08 -0700
committerGitHub <[email protected]>2025-07-11 16:29:08 +0000
commit23197151c2384c3ef9b72e3c83b6e0d87d738d14 (patch)
tree75afdc24340ce0e3e42dbf4dbb0422def5bfab9d /packages/core/src/tools
parentcdbe2fffd998218cf9836f5303f2286dbebb52ff (diff)
Summarize tool call outputs using tool specific summarizers (#3745)
Diffstat (limited to 'packages/core/src/tools')
-rw-r--r--packages/core/src/tools/shell.ts4
-rw-r--r--packages/core/src/tools/tool-registry.ts2
-rw-r--r--packages/core/src/tools/tools.ts20
3 files changed, 25 insertions, 1 deletions
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<string, unknown>;
@@ -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
@@ -44,6 +45,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`
* `shouldConfirmExecute` should return false immediately if invalid
@@ -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,
) {}
/**
@@ -174,6 +189,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.
*/