The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(transcript_view): handle text-dialect tool results in projection
Steven Enamakel3e5f76569c24
diff --git a/crates/openhuman-core/src/threads/transcript_view/project.rs b/crates/openhuman-core/src/threads/transcript_view/project.rsindex 912dc54fe1..a1c6be38e7 100644--- a/crates/openhuman-core/src/threads/transcript_view/project.rs+++ b/crates/openhuman-core/src/threads/transcript_view/project.rs@@ -10,6 +10,9 @@ use std::fs;use std::path::{Path, PathBuf};use tinyagents_session::transcript::{self, CompactionMarker, DisplayMessage, DisplayRecord};+use tinytools_agent::dialect::{parse_replayed_results, ToolResultEntry};++use crate::agent::messages::TOOL_RESULT_FAILURES_METADATA_KEY;use super::types::{DisplayItem, ProjectedTranscript, ToolCallFailure, ToolCallStatus};@@ -364,6 +367,12 @@ fn project_message(log::debug!("{LOG_PREFIX} sanitize: dropped system line from projection");}"user" => {+ // A text dialect folds a round's results into one user turn; it is+ // tool output, never the user's words.+ if let Some(results) = parse_replayed_results(&msg.message.content) {+ project_text_tool_results(msg, results, items, pending);+ return;+ }let raw = msg.message.content.clone();let sanitized = sanitize_user_content(&raw);if sanitized.is_some() {@@ -450,6 +459,21 @@ fn project_assistant(for (call_id, name, arguments) in tool_calls {let args = parse_tool_args(&arguments);+ // Transcripts written while the codec filed a turn's calls on its final+ // row record a call *after* its own result, which already projected as+ // an orphan. Name that settled row rather than adding a second one+ // that never settles.+ if let Some(DisplayItem::ToolCall {+ name: settled_name,+ args: settled_args,+ ..+ }) = settled_orphan_mut(items, &call_id)+ {+ log::debug!("{LOG_PREFIX} call {call_id} recorded after its result — merged");+ *settled_name = name;+ *settled_args = args;+ continue;+ }items.push(DisplayItem::ToolCall {call_id: call_id.clone(),name,@@ -544,6 +568,80 @@ fn project_tool_result(});}+/// Pair each result of a text-dialect `[Tool results]` row with its pending+/// call. Failure status comes from the ids the session codec recorded on the+/// row ([`TOOL_RESULT_FAILURES_METADATA_KEY`]); a result with no pending call+/// surfaces as an orphan row, as for a native `tool` line.+fn project_text_tool_results(+ msg: &DisplayMessage,+ results: Vec<ToolResultEntry>,+ items: &mut Vec<DisplayItem>,+ pending: &mut VecDeque<(String, usize)>,+) {+ let failed: Vec<&str> = msg+ .message+ .extra_metadata+ .as_ref()+ .and_then(|meta| meta.get(TOOL_RESULT_FAILURES_METADATA_KEY))+ .and_then(serde_json::Value::as_array)+ .map(|ids| ids.iter().filter_map(serde_json::Value::as_str).collect())+ .unwrap_or_default();+ log::debug!(+ "{LOG_PREFIX} text-dialect results row results={} failed={} pending={}",+ results.len(),+ failed.len(),+ pending.len()+ );+ for result in results {+ let (status, failure) = if failed.contains(&result.tool_call_id.as_str()) {+ (+ ToolCallStatus::Error,+ Some(ToolCallFailure { detail: None }),+ )+ } else {+ (ToolCallStatus::Success, None)+ };+ if let Some(idx) = take_pending_by_id(pending, &result.tool_call_id) {+ if let Some(DisplayItem::ToolCall {+ result: slot,+ status: status_slot,+ failure: failure_slot,+ ..+ }) = items.get_mut(idx)+ {+ *slot = Some(result.content);+ *status_slot = status;+ *failure_slot = failure;+ continue;+ }+ }+ items.push(DisplayItem::ToolCall {+ call_id: result.tool_call_id,+ name: "tool".to_string(),+ args: None,+ result: Some(result.content),+ status,+ failure,+ });+ }+}++/// The already-settled orphan row for `call_id` in the current turn — a result+/// that projected before any call named it.+fn settled_orphan_mut<'a>(items: &'a mut [DisplayItem], call_id: &str) -> Option<&'a mut DisplayItem> {+ let turn_start = items+ .iter()+ .rposition(|item| matches!(item, DisplayItem::TurnBoundary { .. }))+ .map_or(0, |idx| idx + 1);+ items[turn_start..].iter_mut().find(|item| {+ matches!(+ item,+ DisplayItem::ToolCall { call_id: id, name, result: Some(_), .. }+ if id == call_id && name == "tool"+ )+ })+}+/// Remove and return the pending entry whose call id matches `id`, if any.fn take_pending_by_id(pending: &mut VecDeque<(String, usize)>, id: &str) -> Option<usize> {let pos = pending.iter().position(|(cid, _)| cid == id)?;