agent: Fix unnecessary "tool result too long" (#30798)

Release Notes:

- N/A
This commit is contained in:
Oleksiy Syvokon 2025-05-16 09:39:02 +03:00 committed by GitHub
parent 0f17e82154
commit cc3a28a8e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {