Skip to content

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

fix(observability): correct event projection to use session host runtime

Steven Enamakel5d5ba85522a2
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 38ff9b69e1..2e549258b6 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1723,8 +1723,7 @@ impl OpenHumanSessionHost {
.count()
.max(1) as u32;
let output = receipt.outcome.output.clone().unwrap_or_default();
- // Skips compaction checkpoints: user-role, not the
- // user's words.
+ // Skips compaction checkpoints (user-role, not the user's words).
let input =
crate::agent::tinyagents::last_user_message(&receipt.outcome.history)
.map(user_text_with_markers)
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability.rs b/crates/openhuman-core/src/agent/tinyagents/observability.rs
index 0b02f0c62f..2314baa5bc 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability.rs
@@ -9,6 +9,7 @@
//! tinyagents path — and feeds per-call usage into the global cost tracker.
mod cap_pauser;
+mod compaction_log;
mod event_bridge;
mod event_projection;
mod graph_tracing;
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/compaction_log.rs b/crates/openhuman-core/src/agent/tinyagents/observability/compaction_log.rs
new file mode 100644
index 0000000000..939c83f00d
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/compaction_log.rs
@@ -0,0 +1,33 @@
+//! Journal projection of `AgentEvent::Compacted`.
+
+use tinyagents_harness::events::AgentEvent;
+
+/// Logs a context compaction at info with its token savings and the
+/// summarizer call's latency and usage (grep `context compacted`).
+///
+/// A compaction rewrites what the model sees and spends a summarizer call
+/// outside the turn's own model calls, so it is worth seeing at the default
+/// log level, with that call's cost.
+pub(super) fn log_compacted(event: &AgentEvent) {
+ let AgentEvent::Compacted {
+ reason,
+ tokens_before,
+ tokens_after,
+ usage,
+ latency_ms,
+ } = event
+ else {
+ return;
+ };
+ tracing::info!(
+ reason = reason.as_str(),
+ tokens_before,
+ tokens_after,
+ saved_tokens = tokens_before.saturating_sub(*tokens_after),
+ latency_ms = ?latency_ms,
+ summarizer_input_tokens = ?usage.map(|u| u.input_tokens),
+ summarizer_output_tokens = ?usage.map(|u| u.output_tokens),
+ summarizer_cached_tokens = ?usage.map(|u| u.cache_read_tokens),
+ "[tinyagents] context compacted"
+ );
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
index 30c86adc37..6019ac55b0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
@@ -286,28 +286,7 @@ impl EventListener for OpenhumanEventBridge {
"[tinyagents] context compressed before model call"
);
}
- AgentEvent::Compacted {
- reason,
- tokens_before,
- tokens_after,
- usage,
- latency_ms,
- } => {
- // A compaction rewrites what the model sees and spends a
- // summarizer call outside the turn's own model calls, so it is
- // logged at info with that call's cost (grep `context compacted`).
- tracing::info!(
- reason = reason.as_str(),
- tokens_before,
- tokens_after,
- saved_tokens = tokens_before.saturating_sub(*tokens_after),
- latency_ms = ?latency_ms,
- summarizer_input_tokens = ?usage.map(|u| u.input_tokens),
- summarizer_output_tokens = ?usage.map(|u| u.output_tokens),
- summarizer_cached_tokens = ?usage.map(|u| u.cache_read_tokens),
- "[tinyagents] context compacted"
- );
- }
+ AgentEvent::Compacted { .. } => super::compaction_log::log_compacted(event),
AgentEvent::UnknownToolCall {
call_id,
requested_name,