Skip to content

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

test(observability): add test for tool call events using tool's own display label and detail

Steven Enamakel4fac425b0b07
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
index e8f13acf02..31aef3de14 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
@@ -374,3 +374,83 @@ async fn duplicate_usage_for_same_model_call_is_recorded_once() {
// `ToolStarted` arm above — it no longer special-cases a sentinel). The test
// referenced the deleted constant (a stale reference reintroduced by a merge)
// and asserted behaviour that no longer exists.
+
+/// #6XXX (tool-call presentation): `ToolCallStarted`/`ToolCallCompleted` must
+/// carry the tool's OWN `display_label`/`display_detail` when the bridge was
+/// built with the turn's tool sets, not a name-derived guess — proven with a
+/// fake tool whose label is a fixed phrase and whose detail comes from a
+/// `"to"` argument only known once the call completes.
+#[tokio::test]
+async fn tool_call_events_use_the_tool_s_own_display_label_and_detail() {
+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);
+ let bridge = OpenhumanEventBridge::with_scope(
+ Some(tx),
+ "mock-model",
+ "managed",
+ 10,
+ None,
+ Arc::default(),
+ Arc::default(),
+ Arc::default(),
+ Arc::default(),
+ fake_tool_sets(),
+ );
+ let sink = EventSink::new();
+ sink.subscribe(bridge.clone());
+
+ sink.emit(AgentEvent::ModelStarted {
+ call_id: "c1".into(),
+ model: "mock-model".to_string(),
+ });
+ sink.emit(AgentEvent::ToolStarted {
+ call_id: "c1".into(),
+ tool_name: "fake_send_email".to_string(),
+ });
+ sink.emit(AgentEvent::ToolCompleted {
+ call_id: "c1".into(),
+ tool_name: "fake_send_email".to_string(),
+ started_at_ms: None,
+ input: Some(serde_json::json!({"to": "[email protected]"})),
+ output: Some(serde_json::Value::String("sent".to_string())),
+ duration_ms: Some(5),
+ output_bytes: Some(4),
+ error: None,
+ metadata: None,
+ });
+
+ let mut started_label = None;
+ let mut completed = None;
+ while let Ok(p) = rx.try_recv() {
+ match p {
+ AgentProgress::ToolCallStarted {
+ display_label,
+ display_detail,
+ ..
+ } => started_label = Some((display_label, display_detail)),
+ AgentProgress::ToolCallCompleted {
+ display_label,
+ display_detail,
+ ..
+ } => completed = Some((display_label, display_detail)),
+ _ => {}
+ }
+ }
+
+ let (started_label, started_detail) = started_label.expect("ToolCallStarted projected");
+ assert_eq!(
+ started_label,
+ Some("Sending email".to_string()),
+ "the started label comes from the tool's own display_label, not a humanized name"
+ );
+ // No arguments exist yet at call-start, so the arg-derived detail is
+ // absent — this is recovered on the completed event below.
+ assert_eq!(started_detail, None);
+
+ let (completed_label, completed_detail) = completed.expect("ToolCallCompleted projected");
+ assert_eq!(completed_label, Some("Sending email".to_string()));
+ assert_eq!(
+ completed_detail,
+ Some("[email protected]".to_string()),
+ "the completed detail is recomputed from the real call arguments"
+ );
+}