Skip to content

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

fix(claude_code): strip native image markers from prior conversation turns

Steven Enamakele6931c949827
diff --git a/src/openhuman/inference/provider/claude_code/input_builder.rs b/src/openhuman/inference/provider/claude_code/input_builder.rs
index aacfa1add2..d881c1b2a4 100644
--- a/src/openhuman/inference/provider/claude_code/input_builder.rs
+++ b/src/openhuman/inference/provider/claude_code/input_builder.rs
@@ -123,6 +123,7 @@ fn prior_conversation_preamble(non_system: &[&ChatMessage], end: usize) -> Optio
.is_some_and(|message| message.role == "assistant");
if answered && !m.content.is_empty() {
let (text, _images) = parse_image_markers(&m.content);
+ let text = strip_native_image_markers(&text);
if !text.is_empty() {
turns.push(format!("User: {text}"));
}
@@ -140,6 +141,21 @@ fn prior_conversation_preamble(non_system: &[&ChatMessage], end: usize) -> Optio
))
}
+fn strip_native_image_markers(mut text: &str) -> String {
+ const PREFIX: &str = "[OH_IMAGE:";
+ let mut cleaned = String::with_capacity(text.len());
+ while let Some(start) = text.find(PREFIX) {
+ cleaned.push_str(&text[..start]);
+ let rest = &text[start + PREFIX.len()..];
+ let Some(end) = rest.find(']') else {
+ return cleaned;
+ };
+ text = &rest[end + 1..];
+ }
+ cleaned.push_str(text);
+ cleaned
+}
+
/// Split a message's text into stream-json content blocks: the prose as a
/// `text` block, plus one native `image` block per `[IMAGE:<ref>]` marker (the
/// `claude` CLI + Opus are vision-capable). An image that cannot be read
@@ -161,10 +177,7 @@ fn content_blocks(raw: &str) -> Vec<Value> {
{
let start = cursor + relative;
let Some(end_relative) = raw[start..].find(']') else {
- if start > cursor {
- blocks.push(json!({"type": "text", "text": &raw[cursor..start]}));
- }
- blocks.push(json!({"type": "text", "text": &raw[start..]}));
+ blocks.push(json!({"type": "text", "text": &raw[cursor..]}));
cursor = raw.len();
break;
};