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(flows): export flow traces via harness span exporter
Steven Enamakel92ac3f607140
diff --git a/crates/openhuman-cli/Cargo.toml b/crates/openhuman-cli/Cargo.tomlindex 44dab78730..924e2f3387 100644--- a/crates/openhuman-cli/Cargo.toml+++ b/crates/openhuman-cli/Cargo.toml@@ -407,7 +407,6 @@ hex = "0.4"parking_lot = "0.12"sha2 = "0.10"tar = "0.4"-tinyagents-graph = { path = "../../vendor/tinyagents/crates/tinyagents-graph", features = ["sqlite", "storage-drivers"] }tinyagents-harness = { path = "../../vendor/tinyagents/crates/tinyagents-harness", features = ["sqlite", "multimodal"] }tinyagents-definition = { path = "../../vendor/tinyagents/crates/tinyagents-definition" }tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session" }diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.tomlindex 292dc40e5c..21eeb3e09f 100644--- a/crates/openhuman-core/Cargo.toml+++ b/crates/openhuman-core/Cargo.toml@@ -74,11 +74,11 @@ tinyflows-import = { path = "../../vendor/tinyflows/crates/tinyflows-import", de# work): there is no longer a single `tinyagents` package. openhuman now depends# directly on the members it actually uses — `tinyagents-harness` (agent loop,# tools, middleware), `tinyagents-hooks` (host-provided lifecycle and stop-# hooks), `tinyagents-graph` (durable state graphs),+# hooks),# `tinyagents-registry` (capability/model registry), and# `tinyagents-session` (durable session history + run ledger, previously gated# behind this crate's own `sqlite` feature — it is its own always-on crate now).-# The `sqlite` feature is enabled on the harness/graph crates now that openhuman's+# The `sqlite` feature is enabled on the harness now that openhuman's# direct rusqlite pin is aligned to 0.40, avoiding duplicate `links = "sqlite3"`# native bindings. Durable graph checkpoints still use `SqlRunLedgerCheckpointer`# until the migration re-points those rows to the crate checkpointer.@@ -114,10 +114,6 @@ tinyagents-definition = { path = "../../vendor/tinyagents/crates/tinyagents-defi# Agents, the Sarvam cascade) and executes its tool calls through the turn# harness pipeline. Only the `voice` feature's `voice::live` uses it.tinyagents-live = { path = "../../vendor/tinyagents/crates/tinyagents-live", optional = true }-tinyagents-graph = { path = "../../vendor/tinyagents/crates/tinyagents-graph", features = [- "sqlite",- "storage-drivers",-] }tinyagents-registry = { path = "../../vendor/tinyagents/crates/tinyagents-registry" }tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session", features = ["storage-drivers"] }# The storage ports and the URL-to-backend facade (`storage` domain). No driverdiff --git a/crates/openhuman-core/src/core/observability/progress_tracing.rs b/crates/openhuman-core/src/core/observability/progress_tracing.rsindex b361468dba..4f2d4081e0 100644--- a/crates/openhuman-core/src/core/observability/progress_tracing.rs+++ b/crates/openhuman-core/src/core/observability/progress_tracing.rs@@ -8,10 +8,7 @@ mod export;#[path = "trace_export_adoption_tests.rs"]mod adoption_tests;-use serde_json::Value;-use tinyagents_graph::{GraphLangfuseExporter, GraphObservation};use tinyagents_harness::observability::trace_export::ExportBrand;-use tinyagents_harness::observability::LangfuseTraceConfig;/// Product identity stamped onto exported telemetry.pub(crate) fn export_brand() -> ExportBrand<'static> {@@ -25,26 +22,3 @@ pub(crate) fn export_brand() -> ExportBrand<'static> {pub(crate) use export::build_subagent_trace;pub(crate) use export::{export_run_trace_from_journal, export_subagent_journal_trace};-/// Build the generic graph-to-OTLP projection with OpenHuman's product name.-/// Flow identity and metadata stay with the flow adapter; this layer owns the-/// shared projection boundary used by both durable graph event sources.-pub(crate) fn build_graph_otlp_requests(- exporter: &GraphLangfuseExporter,- trace: LangfuseTraceConfig,- observations: &[GraphObservation],-) -> tinyagents_harness::error::Result<Vec<Value>> {- exporter.build_otlp_requests(trace, observations, export_brand().product)-}--/// Send a generic graph trace through the exporter’s authenticated OTLP-/// client. Callers own timeout and best-effort policy for their run lifecycle.-pub(crate) async fn send_graph_otlp_requests(- exporter: &GraphLangfuseExporter,- requests: Vec<Value>,-) -> tinyagents_harness::error::Result<usize> {- let count = requests.len();- for request in requests {- exporter.client().send_otlp(request).await?;- }- Ok(count)-}diff --git a/crates/openhuman-core/src/flows/ops/execution.rs b/crates/openhuman-core/src/flows/ops/execution.rsindex 9653f76627..949ccc182b 100644--- a/crates/openhuman-core/src/flows/ops/execution.rs+++ b/crates/openhuman-core/src/flows/ops/execution.rs@@ -3,7 +3,7 @@//! TinyFlows module; this file only consumes its typed PollRun projection.use serde_json::json;-use tinyagents_graph::GraphObservation;+use tinyflows::engine::GraphObservation;use tinyflows_bus::catalog::Workflow as Flow;use tinyflows_bus::runs::FlowRunTrigger;diff --git a/crates/openhuman-core/src/flows/ops/langfuse_export.rs b/crates/openhuman-core/src/flows/ops/langfuse_export.rsindex ed0dcee3f2..a28e6c80fa 100644--- a/crates/openhuman-core/src/flows/ops/langfuse_export.rs+++ b/crates/openhuman-core/src/flows/ops/langfuse_export.rs@@ -26,9 +26,13 @@use std::time::Duration;-use serde_json::{json, Map, Value};-use tinyagents_graph::{GraphLangfuseExporter, GraphObservation};+use std::collections::{BTreeMap, HashMap, VecDeque};++use serde_json::{json, Value};+use tinyagents_harness::observability::spans::{Span, SpanExporter, SpanState};use tinyagents_harness::{LangfuseAuth, LangfuseClient, LangfuseTraceConfig};+use tinyflows::graph::stream::GraphEvent;+use tinyflows::engine::GraphObservation;use tinyflows_bus::runs::FlowRunTrigger;use crate::config::Config;@@ -106,30 +110,186 @@ fn build_flow_trace_config(}}-/// Builds the graph exporter for a flow run: the batch builder plus a host-/// span-metadata injector that stamps `flow_id` on every span (node spans-/// already carry `langgraph_node`/`langgraph_step` from `tinyagents`).-fn build_flow_exporter(client: LangfuseClient, flow_id: &str) -> GraphLangfuseExporter {- let flow_id = flow_id.to_string();- GraphLangfuseExporter::new(client).with_span_metadata_fn(move |_obs| {- let mut extra = Map::new();- extra.insert("flow_id".to_string(), json!(flow_id));- Some(extra)- })+/// Converts TinyFlows' durable events to the generic harness span contract.+/// Pairing is FIFO so repeated node activations keep their event order.+fn flow_spans(flow_id: &str, observations: &[GraphObservation]) -> Vec<Span> {+ let Some(first) = observations.first() else {+ return Vec::new();+ };+ let trace_id = first+ .thread_id+ .as_ref()+ .map(|thread| thread.as_str())+ .unwrap_or_else(|| first.root_run_id.as_str());+ let run_id = first.run_id.as_str();+ let root_run_id = first.root_run_id.as_str();+ let run_span_id = format!("{trace_id}:run:{root_run_id}");+ let terminal = observations.iter().rev().find(|obs| {+ matches!(obs.event, GraphEvent::RunCompleted { .. } | GraphEvent::RunFailed { .. })+ });+ let mut run_span = Span::new(+ run_span_id.clone(),+ run_id,+ first.graph_id.as_str(),+ first.ts_ms,+ )+ .with_root_run_id(root_run_id)+ .with_event_id(terminal.unwrap_or(first).event_id.as_str());+ if let Some(end) = terminal.or_else(|| observations.last()) {+ run_span = run_span.finish(+ end.ts_ms,+ if matches!(end.event, GraphEvent::RunFailed { .. }) {+ SpanState::Error+ } else {+ SpanState::Ok+ },+ );+ }+ add_observation_metadata(&mut run_span, first, flow_id);++ let mut output = vec![run_span];+ let mut consumed = vec![false; observations.len()];+ let mut step_starts: HashMap<usize, VecDeque<usize>> = HashMap::new();+ let mut node_starts: HashMap<(String, usize), VecDeque<usize>> = HashMap::new();+ let mut subgraph_starts: HashMap<(String, Vec<String>), VecDeque<usize>> = HashMap::new();++ for (index, observation) in observations.iter().enumerate() {+ match &observation.event {+ GraphEvent::StepStarted { step, .. } => {+ step_starts.entry(*step).or_default().push_back(index);+ consumed[index] = true;+ }+ GraphEvent::StepCompleted { step } => {+ if let Some(start) = pop_start(&mut step_starts, step) {+ consumed[index] = true;+ output.push(step_span(flow_id, trace_id, &run_span_id, *step, observations, start, index));+ }+ }+ GraphEvent::NodeStarted { node, step } => {+ node_starts.entry((node.as_str().to_owned(), *step)).or_default().push_back(index);+ consumed[index] = true;+ }+ GraphEvent::NodeCompleted { node, step } => {+ if let Some(start) = pop_start(&mut node_starts, &(node.as_str().to_owned(), *step)) {+ consumed[index] = true;+ output.push(node_span(flow_id, trace_id, node.as_str(), *step, observations, start, index, None));+ }+ }+ GraphEvent::NodeFailed { node, step, error } => {+ if let Some(start) = pop_start(&mut node_starts, &(node.as_str().to_owned(), *step)) {+ consumed[index] = true;+ output.push(node_span(flow_id, trace_id, node.as_str(), *step, observations, start, index, Some(error)));+ }+ }+ GraphEvent::SubgraphStarted { node, namespace } => {+ subgraph_starts.entry((node.as_str().to_owned(), namespace.clone())).or_default().push_back(index);+ consumed[index] = true;+ }+ GraphEvent::SubgraphCompleted { node, namespace } => {+ if let Some(start) = pop_start(&mut subgraph_starts, &(node.as_str().to_owned(), namespace.clone())) {+ consumed[index] = true;+ output.push(subgraph_span(flow_id, trace_id, &run_span_id, node.as_str(), namespace, observations, start, index));+ }+ }+ _ => {}+ }+ }+ for (step, starts) in step_starts {+ for start in starts {+ output.push(step_span(flow_id, trace_id, &run_span_id, step, observations, start, start));+ output.last_mut().expect("just pushed").end_ms = None;+ }+ }+ for ((node, step), starts) in node_starts {+ for start in starts {+ output.push(node_span(flow_id, trace_id, &node, step, observations, start, start, None));+ output.last_mut().expect("just pushed").end_ms = None;+ }+ }+ for ((node, namespace), starts) in subgraph_starts {+ for start in starts {+ output.push(subgraph_span(flow_id, trace_id, &run_span_id, &node, &namespace, observations, start, start));+ output.last_mut().expect("just pushed").end_ms = None;+ }+ }+ for (index, observation) in observations.iter().enumerate() {+ if consumed[index] || matches!(observation.event, GraphEvent::RunStarted { .. }) {+ continue;+ }+ let failed = matches!(observation.event, GraphEvent::RunFailed { .. });+ let error = match &observation.event {+ GraphEvent::RunFailed { error, .. } | GraphEvent::NodeFailed { error, .. } => Some(error.as_str()),+ _ => None,+ };+ let mut span = Span::new(observation.event_id.as_str(), observation.run_id.as_str(), observation.event.kind(), observation.ts_ms)+ .with_root_run_id(observation.root_run_id.as_str())+ .with_parent(&run_span_id)+ .with_event_id(observation.event_id.as_str());+ span.kind = "event-create".to_owned();+ span.status = if failed { SpanState::Error } else { SpanState::Unset };+ span.status_message = error.map(str::to_owned);+ add_observation_metadata(&mut span, observation, flow_id);+ output.push(span);+ }+ output}-/// The Langfuse v4 OTLP requests for one flow run, under the product's-/// `service.name` (the same one agent-turn traces use).-fn flow_otlp_requests(- exporter: &GraphLangfuseExporter,- trace: LangfuseTraceConfig,- observations: &[GraphObservation],-) -> tinyagents_harness::error::Result<Vec<Value>> {- crate::core::observability::progress_tracing::build_graph_otlp_requests(- exporter,- trace,- observations,- )+fn pop_start<K: std::hash::Hash + Eq>(starts: &mut HashMap<K, VecDeque<usize>>, key: &K) -> Option<usize> {+ let queue = starts.get_mut(key)?;+ let start = queue.pop_front();+ if queue.is_empty() { starts.remove(key); }+ start+}++fn add_observation_metadata(span: &mut Span, observation: &GraphObservation, flow_id: &str) {+ span.metadata.insert("flow_id".into(), json!(flow_id));+ span.metadata.insert("graph_id".into(), json!(observation.graph_id.as_str()));+ span.metadata.insert("run_id".into(), json!(observation.run_id.as_str()));+ span.metadata.insert("root_run_id".into(), json!(observation.root_run_id.as_str()));+ span.metadata.insert("parent_run_id".into(), json!(observation.parent_run_id.as_ref().map(|id| id.as_str())));+ span.metadata.insert("checkpoint_id".into(), json!(observation.checkpoint_id.as_ref().map(|id| id.as_str())));+ span.metadata.insert("namespace".into(), json!(observation.namespace));+ span.metadata.insert("step".into(), json!(observation.step));+ span.metadata.insert("offset".into(), json!(observation.offset));+ span.metadata.insert("event".into(), json!(observation.event));+}++fn step_span(flow_id: &str, trace_id: &str, run_span_id: &str, step: usize, observations: &[GraphObservation], start: usize, end: usize) -> Span {+ let first = &observations[start];+ let last = &observations[end];+ let mut span = Span::new(format!("{trace_id}:step:{step}"), first.run_id.as_str(), format!("step {step}"), first.ts_ms)+ .with_root_run_id(first.root_run_id.as_str()).with_parent(run_span_id).with_event_id(last.event_id.as_str());+ if end != start { span = span.finish(last.ts_ms, SpanState::Ok); }+ add_observation_metadata(&mut span, first, flow_id);+ span.metadata.insert("langgraph_step".into(), json!(step));+ span+}++fn node_span(flow_id: &str, trace_id: &str, node: &str, step: usize, observations: &[GraphObservation], start: usize, end: usize, error: Option<&str>) -> Span {+ let first = &observations[start];+ let last = &observations[end];+ let mut span = Span::new(format!("{trace_id}:node:{node}:{step}"), first.run_id.as_str(), node, first.ts_ms)+ .with_root_run_id(first.root_run_id.as_str()).with_parent(format!("{trace_id}:step:{step}")).with_event_id(last.event_id.as_str());+ if end != start { span = span.finish(last.ts_ms, if error.is_some() { SpanState::Error } else { SpanState::Ok }); }+ span.status_message = error.map(str::to_owned);+ add_observation_metadata(&mut span, last, flow_id);+ span.metadata.insert("langgraph_node".into(), json!(node));+ span.metadata.insert("langgraph_step".into(), json!(step));+ span+}++fn subgraph_span(flow_id: &str, trace_id: &str, run_span_id: &str, node: &str, namespace: &[String], observations: &[GraphObservation], start: usize, end: usize) -> Span {+ let first = &observations[start];+ let last = &observations[end];+ let mut span = Span::new(format!("{trace_id}:subgraph:{}", namespace.join("/")), first.run_id.as_str(), format!("subgraph {node}"), first.ts_ms)+ .with_root_run_id(first.root_run_id.as_str()).with_parent(run_span_id).with_event_id(last.event_id.as_str());+ if end != start { span = span.finish(last.ts_ms, SpanState::Ok); }+ add_observation_metadata(&mut span, last, flow_id);+ span+}++fn flow_otlp_requests(exporter: &SpanExporter, trace: LangfuseTraceConfig, flow_id: &str, observations: &[GraphObservation]) -> tinyagents_harness::error::Result<Vec<Value>> {+ exporter.build_otlp_requests(trace, &flow_spans(flow_id, observations), "openhuman", "openhuman.graph")}/// Exports one settled flow run to Langfuse as a single trace. Best-effort:@@ -201,7 +361,7 @@ pub async fn export_flow_run_trace(}};- let exporter = build_flow_exporter(client, flow_id);+ let exporter = SpanExporter::new(client);let trace = build_flow_trace_config(flow_name, flow_id, thread_id, status, trigger);let observation_count = observations.len();tracing::debug!(@@ -215,7 +375,7 @@ pub async fn export_flow_run_trace("[flows] pushing flow run trace to Langfuse");- let requests = match flow_otlp_requests(&exporter, trace, observations) {+ let requests = match flow_otlp_requests(&exporter, trace, flow_id, observations) {Ok(requests) => requests,Err(err) => {tracing::warn!(@@ -228,18 +388,22 @@ pub async fn export_flow_run_trace(return;}};- // The core observability owner performs the generic graph projection and- // authenticated sends; this adapter supplies flow-specific trace metadata.- let send =- crate::core::observability::progress_tracing::send_graph_otlp_requests(&exporter, requests);+ // The generic exporter owns OTLP conversion and the authenticated client;+ // this adapter supplies flow-specific spans and trace metadata.+ let send = async {+ for request in requests {+ exporter.client().send_otlp(request).await?;+ }+ Ok::<(), tinyagents_harness::error::TinyAgentsError>(())+ };match tokio::time::timeout(PUSH_TIMEOUT, send).await {- Ok(Ok(request_count)) => {+ Ok(Ok(())) => {tracing::debug!(target: LOG_TARGET,flow_id = %flow_id,thread_id = %thread_id,observation_count,- request_count,+ request_count = 1,"[flows] pushed flow run trace to Langfuse");}diff --git a/crates/openhuman-core/src/flows/ops/langfuse_export_tests.rs b/crates/openhuman-core/src/flows/ops/langfuse_export_tests.rsindex 929555d3e6..d73af295b7 100644--- a/crates/openhuman-core/src/flows/ops/langfuse_export_tests.rs+++ b/crates/openhuman-core/src/flows/ops/langfuse_export_tests.rs@@ -1,7 +1,8 @@use super::*;use serde_json::Value;-use tinyagents_graph::stream::GraphEvent;-use tinyagents_harness::ids::{EventId, GraphId, NodeId, RunId, ThreadId};+use tinyflows::engine::GraphObservation;+use tinyflows::graph::ids::{EventId, GraphId, NodeId, RunId, ThreadId};+use tinyflows::graph::stream::GraphEvent;use tinyflows_bus::runs::FlowRunTrigger;/// Builds a minimal observation stream for one node under run/thread ids@@ -129,11 +130,7 @@ fn otlp_flow_trace_puts_flow_attributes_on_every_span() {"completed",FlowRunTrigger::Rpc,);- let requests = flow_otlp_requests(- &build_flow_exporter(client, "flow-1"),- trace,- &sample_observations(thread_id),- )+ let requests = flow_otlp_requests(&SpanExporter::new(client), trace, "flow-1", &sample_observations(thread_id)).expect("otlp requests");let resource = &requests[0]["resourceSpans"][0];assert_eq!(@@ -209,7 +206,7 @@ fn batch_carries_flow_trace_and_langgraph_keys_on_node_spans() {},).expect("client");- let exporter = build_flow_exporter(client, "flow-1");+ let exporter = SpanExporter::new(client);let trace = build_flow_trace_config("Daily digest","flow-1",@@ -218,7 +215,7 @@ fn batch_carries_flow_trace_and_langgraph_keys_on_node_spans() {FlowRunTrigger::Rpc,);let payload = exporter- .build_ingestion_batch(trace, &observations)+ .build_ingestion_batch(trace, &flow_spans("flow-1", &observations)).expect("batch");let batch = payload["batch"].as_array().expect("batch array");diff --git a/crates/openhuman-core/src/flows/runs_adapter/projection.rs b/crates/openhuman-core/src/flows/runs_adapter/projection.rsindex aa347d0fc3..4a7c81ef2a 100644--- a/crates/openhuman-core/src/flows/runs_adapter/projection.rs+++ b/crates/openhuman-core/src/flows/runs_adapter/projection.rs@@ -6,6 +6,7 @@ use std::sync::{LazyLock, Mutex};use serde_json::Value;use tinyflows_bus::runs::FlowRunTrigger;use tinyflows_bus::runs::{self, RunEvent};+use tinyflows::engine::GraphObservation;use crate::core::events::DomainEvent;use crate::flows::runs_adapter::session::RunSession;@@ -44,7 +45,7 @@ pub(super) async fn project(session: &RunSession, event: &RunEvent) {}}"graph_observation" => {- match serde_json::from_value::<tinyagents_graph::GraphObservation>(event.data.clone()) {+ match serde_json::from_value::<GraphObservation>(event.data.clone()) {Ok(observation) => session.add_observation(observation),Err(_) => tracing::warn!(target: "flows",diff --git a/crates/openhuman-core/src/flows/runs_adapter/session.rs b/crates/openhuman-core/src/flows/runs_adapter/session.rsindex 493afee1bc..d9da366b7c 100644--- a/crates/openhuman-core/src/flows/runs_adapter/session.rs+++ b/crates/openhuman-core/src/flows/runs_adapter/session.rs@@ -7,6 +7,7 @@ use std::time::Duration;use tinyflows_bus::catalog::Workflow as Flow;use tinyflows_bus::runs::FlowRunTrigger;use tinyflows_bus::runs::{self, RunEvent};+use tinyflows::engine::GraphObservation;use super::{projection, RunBindings};use crate::config::Config;@@ -45,7 +46,7 @@ pub(crate) struct RunSession {started_event: std::sync::atomic::AtomicBool,finished_event: std::sync::atomic::AtomicBool,live_actor: std::sync::atomic::AtomicBool,- observations: Mutex<Vec<tinyagents_graph::GraphObservation>>,+ observations: Mutex<Vec<GraphObservation>>,}static SESSIONS: LazyLock<Mutex<HashMap<RunKey, Arc<RunSession>>>> =@@ -94,14 +95,14 @@ impl RunSession {.retain(|watcher| watcher.send(event.clone()).is_ok());}- pub(super) fn add_observation(&self, observation: tinyagents_graph::GraphObservation) {+ pub(super) fn add_observation(&self, observation: GraphObservation) {self.observations.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(observation);}- pub(super) fn take_observations(&self) -> Vec<tinyagents_graph::GraphObservation> {+ pub(super) fn take_observations(&self) -> Vec<GraphObservation> {std::mem::take(&mut *self.observationsdiff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.tomlindex f638dbb67b..cc323f73a4 100644--- a/crates/openhuman-embed/Cargo.toml+++ b/crates/openhuman-embed/Cargo.toml@@ -83,7 +83,6 @@ tinyagents-harness = { path = "../../vendor/tinyagents/crates/tinyagents-harnesstinyagents-definition = { path = "../../vendor/tinyagents/crates/tinyagents-definition" }tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session" }# Native persisted todo codec exposed by the existing session-store contract.-tinyagents-graph = { path = "../../vendor/tinyagents/crates/tinyagents-graph", default-features = false }# Native cancellation contract, exposed unchanged by the existing stream API.tinybus = { path = "../../vendor/tinybus/crates/tinybus", default-features = false }# The wire request/response types `complete` converts to; same path as the