Skip to content

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

feat(progress_tracing): track model call events in collector

Steven Enamakel6d308b6131a5
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
index 683961fa9e..fb745eebb7 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
@@ -58,6 +58,9 @@ impl SpanCollector {
attrs.insert("tool.name".to_string(), json_str(tool_name));
attrs.insert("tool.call_id".to_string(), json_str(call_id));
attrs.insert("agent.iteration".to_string(), json_u32(*iteration));
+ if let Some(model) = &self.last_model {
+ attrs.insert("tool.model".to_string(), json_str(model));
+ }
let (_, index) = self.open_span(
SpanKind::Tool,
format!("tool.{tool_name}"),
@@ -97,20 +100,7 @@ impl SpanCollector {
);
extra.insert("tool.output_chars".to_string(), json_usize(*output_chars));
extra.insert("tool.elapsed_ms".to_string(), json_u64(*elapsed_ms));
- // Failed tool calls surface a Langfuse statusMessage: the
- // classified plain-language cause, truncated, gated on
- // content capture (it can quote user data / paths).
- if let Some(failure) = failure {
- if self.ctx.capture_content {
- extra.insert(
- "error.message".to_string(),
- serde_json::Value::String(truncate_chars(
- &failure.cause_plain,
- MAX_ERROR_MESSAGE_CHARS,
- )),
- );
- }
- }
+ self.insert_failure_attrs(failure.as_ref(), &mut extra);
self.close_span(index, start + elapsed_ms, status_of(*success), extra);
}
}
@@ -197,6 +187,7 @@ impl SpanCollector {
current_iteration_span_id: None,
open_tools: BTreeMap::new(),
first_deltas: Default::default(),
+ last_model: None,
},
);
}
@@ -253,17 +244,23 @@ impl SpanCollector {
iteration,
..
} => {
- let parent_id = match self.subagents.get(task_id) {
- Some(state) => match &state.current_iteration_span_id {
- Some(id) => id.clone(),
- None => self.spans[state.span_index].span_id.clone(),
- },
+ let (parent_id, model) = match self.subagents.get(task_id) {
+ Some(state) => (
+ match &state.current_iteration_span_id {
+ Some(id) => id.clone(),
+ None => self.spans[state.span_index].span_id.clone(),
+ },
+ state.last_model.clone(),
+ ),
None => return,
};
let mut attrs = BTreeMap::new();
attrs.insert("tool.name".to_string(), json_str(tool_name));
attrs.insert("tool.call_id".to_string(), json_str(call_id));
attrs.insert("agent.iteration".to_string(), json_u32(*iteration));
+ if let Some(model) = model {
+ attrs.insert("tool.model".to_string(), json_str(&model));
+ }
let (_, index) = self.open_span(
SpanKind::Tool,
format!("tool.{tool_name}"),
@@ -285,6 +282,7 @@ impl SpanCollector {
output,
arguments,
elapsed_ms,
+ failure,
..
} => {
let Some(index) = self
@@ -308,6 +306,7 @@ impl SpanCollector {
);
extra.insert("tool.output_chars".to_string(), json_usize(*output_chars));
extra.insert("tool.elapsed_ms".to_string(), json_u64(*elapsed_ms));
+ self.insert_failure_attrs(failure.as_ref(), &mut extra);
self.close_span(index, start + elapsed_ms, status_of(*success), extra);
}
@@ -500,3 +499,36 @@ impl SpanCollector {
self.subagents.clear();
}
}
+
+impl SpanCollector {
+ /// Failure attributes for a closing tool span (parent or child).
+ ///
+ /// * `tool.failure_class` — the classified class (`CommandFailed`,
+ /// `InvalidArguments`, `NotFound`, …). Content-free, so not gated: it is
+ /// what separates a program that exited non-zero from a harness failure
+ /// on an error-level observation.
+ /// * `error.message` — the classified plain-language cause, truncated,
+ /// which Langfuse renders as the statusMessage. Gated on content capture
+ /// (it can quote user data / paths).
+ fn insert_failure_attrs(
+ &self,
+ failure: Option<&crate::tools::status::ClassifiedFailure>,
+ extra: &mut BTreeMap<String, serde_json::Value>,
+ ) {
+ let Some(failure) = failure else {
+ return;
+ };
+ if let Ok(serde_json::Value::String(class)) = serde_json::to_value(failure.class) {
+ extra.insert("tool.failure_class".to_string(), serde_json::Value::String(class));
+ }
+ if self.ctx.capture_content {
+ extra.insert(
+ "error.message".to_string(),
+ serde_json::Value::String(truncate_chars(
+ &failure.cause_plain,
+ MAX_ERROR_MESSAGE_CHARS,
+ )),
+ );
+ }
+ }
+}
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
index d698765a73..e26de326e7 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs
@@ -82,6 +82,22 @@ impl SpanCollector {
};
let labeled_model = format!("{provider_id}.{model}");
+ // Remember which model this scope is on so the tool spans it requests
+ // name it (correlating tool errors to models without a join). The
+ // journal replay has no provider id; name the bare model there.
+ let tool_model = if provider_id.is_empty() {
+ model.to_string()
+ } else {
+ labeled_model.clone()
+ };
+ match subagent_task_id {
+ Some(id) => {
+ if let Some(state) = self.subagents.get_mut(id) {
+ state.last_model = Some(tool_model);
+ }
+ }
+ None => self.last_model = Some(tool_model),
+ }
let pricing = crate::agent::cost::lookup_pricing(model);
let mut attrs = BTreeMap::new();
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs
index 28a09c1a85..33b37aac75 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs
@@ -37,6 +37,9 @@ pub(super) struct SubagentState {
pub(super) open_tools: BTreeMap<String, usize>,
/// First streamed delta of the child's in-flight model call.
pub(super) first_deltas: FirstDeltas,
+ /// Langfuse-facing label (`{provider}.{model}`) of the child's latest
+ /// model call, stamped on the child tool spans it requests.
+ pub(super) last_model: Option<String>,
}
/// Pure state machine that folds an [`crate::agent::progress::AgentProgress`]
@@ -68,6 +71,10 @@ pub struct SpanCollector {
pub(super) subagents: BTreeMap<String, SubagentState>,
/// First streamed delta of the parent turn's in-flight model call.
pub(super) first_deltas: FirstDeltas,
+ /// Langfuse-facing label (`{provider}.{model}`) of the parent turn's latest
+ /// model call. Tool calls run after the model call that requested them
+ /// completes, so this names the model behind every tool span opened next.
+ pub(super) last_model: Option<String>,
}
impl SpanCollector {
@@ -84,6 +91,7 @@ impl SpanCollector {
open_tools: BTreeMap::new(),
subagents: BTreeMap::new(),
first_deltas: FirstDeltas::default(),
+ last_model: None,
}
}
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 2e2f5ed6dc..be756f3460 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 2e2f5ed6dc952e0e8944c2cd7033b70b930824d2
+Subproject commit be756f3460c52ff55cc12f57ac615cfe608ad5fd