Skip to content

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

feat(subagent): trace cap-summary model calls

Steven Enamakel47a6f7753b74
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs b/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs
index fc7c333447..f210afbb6d 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs
@@ -4,6 +4,7 @@ use crate::inference::provider::BilledUsage;
use std::sync::{Arc, Mutex};
use tinyagents_harness::summarization::CapToolResult;
use tinyagents_orchestration::subagent::{summarize_at_cap, CapSummaryModel};
+use tinyagents_harness::ids::CallId;
use tinyinference_llm::message::Message;
use tinyinference_llm::model::{ChatModel, ModelRequest};
@@ -19,7 +20,9 @@ pub(super) struct SubagentCheckpointOutcome {
pub(super) struct SubagentCheckpoint {
pub(super) chat_model: Arc<dyn ChatModel<()>>,
pub(super) agent_id: String,
+ pub(super) model: String,
pub(super) max_output_tokens: u32,
+ pub(super) trace: Option<Arc<crate::agent::tinyagents::SupplementalTrace>>,
}
impl SubagentCheckpoint {
@@ -60,8 +63,23 @@ impl CapSummaryModel for HostCapSummaryModel<'_> {
))];
let request =
ModelRequest::new(summary_input).with_max_tokens(self.checkpoint.max_output_tokens);
+ let trace_input = serde_json::to_value(&request.messages).unwrap_or(serde_json::Value::Null);
+ let trace_call = self
+ .checkpoint
+ .trace
+ .as_ref()
+ .map(|trace| (trace.clone(), trace.begin(&self.checkpoint.model)));
match self.checkpoint.chat_model.invoke(&(), request).await {
Ok(response) => {
+ if let Some((trace, (call_id, started_at_ms))) = trace_call {
+ trace.completed(
+ call_id,
+ &self.checkpoint.model,
+ started_at_ms,
+ trace_input,
+ &response,
+ );
+ }
let usage = crate::inference::provider::model::usage_info_from_response(&response);
*self
.usage
@@ -71,6 +89,9 @@ impl CapSummaryModel for HostCapSummaryModel<'_> {
Ok(prose)
}
Err(error) => {
+ if let Some((trace, (call_id, started_at_ms))) = trace_call {
+ trace.failed(call_id, &self.checkpoint.model, started_at_ms);
+ }
tracing::warn!(
agent_id = %self.checkpoint.agent_id,
max_calls,
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
index cf4db85aae..54d6b5aa6f 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
@@ -377,6 +377,7 @@ pub(in super::super) async fn run_subagent_via_graph(
let strategy = checkpoint::SubagentCheckpoint {
chat_model: summary_model.clone(),
agent_id: agent_id.to_string(),
+ model: model.to_string(),
// The checkpoint summary call's output cap. #4469 item 5: honour this
// sub-agent definition's own per-call output budget (the same
// `max_output_tokens` bounding every task model call above) instead of
@@ -384,6 +385,19 @@ pub(in super::super) async fn run_subagent_via_graph(
// definition that raised or lowered its output cap is respected by the
// cap-summary call too.
max_output_tokens,
+ trace: native_subagent.as_ref().and_then(|native| {
+ native
+ .child_events
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .clone()
+ .map(|events| {
+ crate::agent::tinyagents::SupplementalTrace::new(
+ events,
+ native.config.run_id.clone(),
+ )
+ })
+ }),
};
match strategy.summarize_cap_hit(&results, max_iterations).await {
Ok(co) => {