Q22: cap every tool result and bound connector responses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 05:04:59 -04:00
1 parent 4d6c74a21e
commit 8e8b66fed4
5 files changed
+79 -5

No files matched your search

@@ -3,6 +3,14 @@ import type { AgentTurnMessage } from "./provider-tool-turn";
const KEEP_RECENT_TOOL_TURNS = 3;
const ELIDE_ABOVE_CHARS = 600;
const PREVIEW_CHARS = 300;
const TOOL_RESULT_CHAR_LIMIT = 26_000;
/** One tool result never exceeds the per-result cap. */
export function capToolOutput(toolName: string, output: string): string {
if (output.length <= TOOL_RESULT_CHAR_LIMIT) return output;
console.warn(`[run-loop] ${toolName} returned ${output.length} chars; cut to ${TOOL_RESULT_CHAR_LIMIT}`);
return `${output.slice(0, TOOL_RESULT_CHAR_LIMIT)}\n\n[result of ${toolName} cut at ${TOOL_RESULT_CHAR_LIMIT} of ${output.length} characters; ask for less (filters, pagination, fewer fields)]`;
}
/** Older tool results shrink to a preview; the latest turns stay verbatim. */
export function compactToolHistory(messages: AgentTurnMessage[], keepRecent = KEEP_RECENT_TOOL_TURNS): { messages: AgentTurnMessage[]; elided: number } {