MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / truncate_prompt

Function truncate_prompt

atomic-agent/src/turn/orchestrator/mod.rs:819–834  ·  view source on GitHub ↗

Truncate a string to `max_len` bytes, breaking at a word boundary where possible and appending `"..."`. Mirrors the same helper in sibling modules.

(prompt: &str, max_len: usize)

Source from the content-addressed store, hash-verified

817/// Truncate a string to `max_len` bytes, breaking at a word boundary where
818/// possible and appending `"..."`. Mirrors the same helper in sibling modules.
819pub(crate) fn truncate_prompt(prompt: &str, max_len: usize) -> String {
820 let trimmed = prompt.trim();
821 if trimmed.len() <= max_len {
822 return trimmed.to_string();
823 }
824
825 // Try to break at a word boundary in the first `max_len - 3` bytes.
826 let truncated = &trimmed[..max_len.saturating_sub(3)];
827 if let Some(last_space) = truncated.rfind(' ') {
828 if last_space > max_len / 2 {
829 return format!("{}...", &truncated[..last_space]);
830 }
831 }
832
833 format!("{}...", truncated)
834}
835
836impl TurnOrchestrator {
837 /// Fast check for working copy changes.

Callers 1

ingest_sherpa_traceMethod · 0.70

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected