The open-source agent harness - the runtime layer that turns an LLM into a working agent.
fix: improve large tool response messages with detailed size and blocking thresholds (#1134)
Sujai Kumar Gupta98ea71ec543d
diff --git a/.changeset/large-tool-response-size.md b/.changeset/large-tool-response-size.mdindex 67fdc615c..c850b2117 100644--- a/.changeset/large-tool-response-size.md+++ b/.changeset/large-tool-response-size.md@@ -2,4 +2,4 @@'@truefoundry/trueforge-core': patch----The sandbox file-dump message for a blocked large tool response now states its exact size (`Content too large (50,000 characters). Result saved to: …`) and prompts the model to plan reads against that total, instead of guessing with small incremental reads.+Blocked large tool response messages now state the exact content size and which limit blocked it, in characters (`Content too large (50,000 characters; this response exceeds the 24,000-character limit for a single response). Result saved to: …`, at the default thresholds; responses blocked by the parallel total instead say the parallel responses together exceed the combined limit), and the file-dump message prompts the model to plan reads against the total instead of guessing with small incremental reads.diff --git a/packages/trueforge-core/src/core/capabilities/builtins/LargeToolResponse.ts b/packages/trueforge-core/src/core/capabilities/builtins/LargeToolResponse.tsindex fb6cd0774..974782ea9 100644--- a/packages/trueforge-core/src/core/capabilities/builtins/LargeToolResponse.ts+++ b/packages/trueforge-core/src/core/capabilities/builtins/LargeToolResponse.ts@@ -70,7 +70,17 @@ export class LargeToolResponseProcessor implements ToolResponseProcessor {this.logger = param.logger.child({ module: 'LargeToolResponse' });}- private createLargeToolResponseGuidance(sandbox: HarnessSandbox | undefined): string {+ // Thresholds are configured in tokens, estimated at 4 characters per token; state them in characters for the model.+ // An entry at/above the individual threshold was blocked for its own size; below it, only the combined limit can block it.+ private blockReasonDescription(entry: ToolResultWithInfo): string {+ const perResponse = (this.individualTokenThreshold * 4).toLocaleString('en-US');+ const combined = (this.totalTokenThreshold * 4).toLocaleString('en-US');+ return entry.originalTokens >= this.individualTokenThreshold+ ? `this response exceeds the ${perResponse}-character limit for a single response`+ : `the parallel responses together exceed the ${combined}-character combined limit`;+ }++ private createLargeToolResponseGuidance(sandbox: HarnessSandbox | undefined, entry: ToolResultWithInfo): string {const steps = ['Check if some parameter can be passed in order to reduce the output size.'];if (sandbox) {@@ -81,13 +91,13 @@ export class LargeToolResponseProcessor implements ToolResponseProcessor {steps.push(createDynamicSubAgentLargeToolResponseGuidance());}- return `Content too big. To handle a large tool call the Agent can do the following:\n${steps+ return `Content too big (${this.blockReasonDescription(entry)}). To handle a large tool call the Agent can do the following:\n${steps.map((step, index) => `${String(index + 1)}. ${step}`).join('\n')}`;}- private createFileDumpMessage(params: { filePath: string; preview: string; size: string }): string {- const { filePath, preview, size } = params;+ private createFileDumpMessage(params: { filePath: string; preview: string; size: string; reason: string }): string {+ const { filePath, preview, size, reason } = params;const steps: string[] = [dedent`Use sandbox to read parts of the file or extract data.Use ${SANDBOX_SCHEMA_INFER_TAG} to understand the schema.@@ -104,7 +114,7 @@ export class LargeToolResponseProcessor implements ToolResponseProcessor {.map((step, index) => `${String(index + 1)}. ${step}`).join('\n')}`;- return `Content too large (${size}). Result saved to: ${filePath}.\n\n${guidance}\n\nPreview (first and last ${String(this.previewNumberOfCharacters)} chars):\n${preview}`;+ return `Content too large (${size}; ${reason}). Result saved to: ${filePath}.\n\n${guidance}\n\nPreview (first and last ${String(this.previewNumberOfCharacters)} chars):\n${preview}`;}private buildResultsWithInfo(results: ToolCallResult[], sandbox: HarnessSandbox | undefined): ToolResultWithInfo[] {@@ -129,10 +139,10 @@ export class LargeToolResponseProcessor implements ToolResponseProcessor {newContent = entry.originalContent.slice(0, FAILURE_MESSAGE_TRUNCATION_LENGTH);break;case 'sandbox':- newContent = `Content too big. The Agent should write to a file if required and use grep and sed.\n\nPreview:\n${preview}`;+ newContent = `Content too big (${this.blockReasonDescription(entry)}). The Agent should write to a file if required and use grep and sed.\n\nPreview:\n${preview}`;break;case 'mcp':- newContent = `${this.createLargeToolResponseGuidance(sandbox)}\n\nPreview (first and last ${String(this.previewNumberOfCharacters)} chars):\n${preview}`;+ newContent = `${this.createLargeToolResponseGuidance(sandbox, entry)}\n\nPreview (first and last ${String(this.previewNumberOfCharacters)} chars):\n${preview}`;if (sandbox) {pendingSandboxDumps.push(entry);}@@ -166,6 +176,7 @@ export class LargeToolResponseProcessor implements ToolResponseProcessor {filePath: stored.filePath,preview,size: describeContentSize(entry.originalContent),+ reason: this.blockReasonDescription(entry),});entry.toolCallResult.isStructuredContent = false;return stored.sandboxCreated;