Skip to main content

truncate_tool_output_at

Function truncate_tool_output_at 

Source
pub fn truncate_tool_output_at(output: &str, max_chars: usize) -> String
Expand description

Truncate tool output that exceeds max_chars using a head+tail split.

Preserves the first and last max_chars / 2 characters and inserts a truncation marker in the middle. Both boundaries are snapped to valid UTF-8 character boundaries.

ยงExample

use zeph_tools::executor::truncate_tool_output_at;

let long = "a".repeat(200);
let truncated = truncate_tool_output_at(&long, 100);
assert!(truncated.contains("truncated"));
assert!(truncated.len() < long.len());