From cc3a28a8e80a7da2eef143e2c6220b014364f50d Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Fri, 16 May 2025 09:39:02 +0300 Subject: [PATCH] agent: Fix unnecessary "tool result too long" (#30798) Release Notes: - N/A --- crates/agent/src/tool_use.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/agent/src/tool_use.rs b/crates/agent/src/tool_use.rs index 7808ffb145..c26968949f 100644 --- a/crates/agent/src/tool_use.rs +++ b/crates/agent/src/tool_use.rs @@ -425,16 +425,17 @@ impl ToolUseState { let content = match tool_result { ToolResultContent::Text(text) => { - let truncated = truncate_lines_to_byte_limit(&text, tool_output_limit); - - LanguageModelToolResultContent::Text( + let text = if text.len() < tool_output_limit { + text + } else { + let truncated = truncate_lines_to_byte_limit(&text, tool_output_limit); format!( "Tool result too long. The first {} bytes:\n\n{}", truncated.len(), truncated ) - .into(), - ) + }; + LanguageModelToolResultContent::Text(text.into()) } ToolResultContent::Image(language_model_image) => { if language_model_image.estimate_tokens() < tool_output_limit {