Skip to content

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

fix(agent): handle empty message content in conversion

Steven Enamakeldc18690e4660
diff --git a/crates/openhuman-core/src/agent/message_convert.rs b/crates/openhuman-core/src/agent/message_convert.rs
index 042c0c3b77..1b1fe98795 100644
--- a/crates/openhuman-core/src/agent/message_convert.rs
+++ b/crates/openhuman-core/src/agent/message_convert.rs
@@ -135,16 +135,34 @@ pub(crate) fn reasoning_content_block(reasoning: Option<&str>) -> Option<Content
})
}
+/// Separator between distinct thinking blocks joined by
+/// [`reasoning_from_content`].
+const REASONING_BLOCK_SEPARATOR: &str = "\n\n";
+
/// Recover `reasoning_content` from an assistant message's content blocks.
+///
+/// A message can carry several thinking blocks (interleaved thinking emits one
+/// per reasoning span). All of them are kept, in order, joined by a blank
+/// line — keeping only the first silently dropped every later span from the
+/// persisted transcript and the reasoning shown for that step.
pub(crate) fn reasoning_from_content(content: &[ContentBlock]) -> Option<String> {
- content.iter().find_map(|block| match block {
- ContentBlock::Thinking { text, .. } => Some(text.clone()),
- ContentBlock::ProviderExtension(value) => value
- .get(REASONING_EXT_KEY)
- .and_then(serde_json::Value::as_str)
- .map(str::to_string),
- _ => None,
- })
+ let parts: Vec<String> = content
+ .iter()
+ .filter_map(|block| match block {
+ ContentBlock::Thinking { text, .. } => Some(text.clone()),
+ ContentBlock::ProviderExtension(value) => value
+ .get(REASONING_EXT_KEY)
+ .and_then(serde_json::Value::as_str)
+ .map(str::to_string),
+ _ => None,
+ })
+ .filter(|text| !text.trim().is_empty())
+ .collect();
+ match parts.len() {
+ 0 => None,
+ 1 => parts.into_iter().next(),
+ _ => Some(parts.join(REASONING_BLOCK_SEPARATOR)),
+ }
}
/// The `extra_metadata` an assistant [`ChatMessage`] should carry so