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 {