Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(orchestration): escape control characters in prompt-safe text

Steven Enamakelf19163312c70
diff --git a/src/openhuman/agent/orchestration/tools/collapsed_delegation.rs b/src/openhuman/agent/orchestration/tools/collapsed_delegation.rs
index 1ba557568b..5c71eb75c1 100644
--- a/src/openhuman/agent/orchestration/tools/collapsed_delegation.rs
+++ b/src/openhuman/agent/orchestration/tools/collapsed_delegation.rs
@@ -145,14 +145,15 @@ fn build_description(targets: &[DelegateTarget]) -> String {
}
fn prompt_safe(value: &str) -> String {
- value
- .chars()
- .map(|ch| match ch {
- '`' => '\'',
- ch if ch.is_control() => ' ',
- ch => ch,
- })
- .collect()
+ let mut out = String::with_capacity(value.len());
+ for ch in value.chars() {
+ match ch {
+ '`' => out.push('\''),
+ ch if ch.is_control() => out.push_str(&format!("\\u{{{:x}}}", ch as u32)),
+ ch => out.push(ch),
+ }
+ }
+ out
}
#[async_trait]