Skip to content

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

feat(agent): flatten image parts into text markers for provider requests

Steven Enamakel460f4a350c33
diff --git a/crates/openhuman-core/src/agent/message_convert.rs b/crates/openhuman-core/src/agent/message_convert.rs
index 2294ff0677..b0b7c0599b 100644
--- a/crates/openhuman-core/src/agent/message_convert.rs
+++ b/crates/openhuman-core/src/agent/message_convert.rs
@@ -474,6 +474,30 @@ pub(crate) fn message_to_native_chat_message(msg: &Message) -> Option<Transcript
})
}
+/// [`message_to_native_chat_message`] for a row that is about to become a
+/// **provider request** by the session driver: a user turn's image parts are
+/// flattened into the private `[OH_IMAGE:<url>]` text marker (text containing
+/// that marker is escaped to `[OH_IMAGE_LITERAL:`), exactly as the string row
+/// bridge always did, so the request bytes are unchanged.
+///
+/// This is a deliberate compatibility shim, not a feature: it means the model
+/// receives the marker as literal text instead of an image block (the
+/// #6872/#6881 corpus pins that request). Returning the typed row unflattened
+/// here is the one-line fix, and needs the `image_user` golden regenerated.
+pub(crate) fn message_to_provider_chat_message(msg: &Message) -> Option<TranscriptMessage> {
+ let mut row = message_to_native_chat_message(msg)?;
+ if let Some(parts) = row.parts.take() {
+ row.content = parts
+ .iter()
+ .map(|part| match part {
+ TranscriptPart::Text { text } => text.replace("[OH_IMAGE:", "[OH_IMAGE_LITERAL:"),
+ TranscriptPart::Image { url } => format!("[OH_IMAGE:{url}]"),
+ })
+ .collect();
+ }
+ Some(row)
+}
+
/// The row of a user message: its text, plus ordered parts when it carries an
/// image. Json / provider-extension blocks carry no user-visible text, so they
/// are dropped, as [`Message::text`] drops them.
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index 6135a21cab..943674d891 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -147,7 +147,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
let mut messages: Vec<TranscriptMessage> = request
.history
.iter()
- .filter_map(crate::agent::message_convert::message_to_native_chat_message)
+ .filter_map(crate::agent::message_convert::message_to_provider_chat_message)
.collect();
if (turn_models.supports_vision() || self.model_vision)
&& crate::agent::multimodal::has_image_placeholders(&messages)
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
index a7e20edbe7..fc3b282c3d 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
@@ -12,7 +12,7 @@ use tinyinference_llm::model::{ModelRequest, ModelStreamItem};
use tinytools_agent::dialect::ToolDialect;
use crate::agent::{
- message_convert::{dialect_response_from_provider, message_to_native_chat_message},
+ message_convert::{dialect_response_from_provider, message_to_provider_chat_message},
session_host::turn_checkpoint::{
self, build_deterministic_checkpoint, build_deterministic_final_summary,
close_repair_instruction, close_verification_prompt, final_answer_instruction,
@@ -91,7 +91,7 @@ pub(super) async fn repair_required_output(
let mut prompt_history: Vec<TranscriptMessage> = history
.iter()
- .filter_map(message_to_native_chat_message)
+ .filter_map(message_to_provider_chat_message)
.collect();
prompt_history.push(TranscriptMessage::user(wrap_harness_instruction(
&required::repair_instruction(contract),
@@ -180,7 +180,7 @@ pub(super) async fn close_if_needed(
};
let base: Vec<TranscriptMessage> = base_history
.iter()
- .filter_map(message_to_native_chat_message)
+ .filter_map(message_to_provider_chat_message)
.collect();
let stop_reason = outcome.breaker_halt.as_deref();