Skip to content

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

fix(session_host): use shared cost catalog for supplemental pricing

Steven Enamakel290902ab4d1b
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
index ea0d2306eb..13939d49b1 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
@@ -155,12 +155,15 @@ impl SupplementalTrace {
.map(|route| route.provider.as_str())
.filter(|provider| valid_provider_id(provider))
.map(str::to_owned);
- let pricing =
- tinyagents_registry::pricing::lookup(actual_model).map(|price| GenerationPricing {
- input_per_mtok_usd: Some(price.input_per_mtok_usd),
- cached_input_per_mtok_usd: Some(price.cached_input_per_mtok_usd),
- output_per_mtok_usd: Some(price.output_per_mtok_usd),
- });
+ let pricing = crate::agent::cost::lookup_pricing(actual_model).map(|price| {
+ GenerationPricing {
+ input_per_mtok_usd: price.input_per_token.map(|rate| rate * 1_000_000.0),
+ cached_input_per_mtok_usd: price
+ .cache_read_input_per_token
+ .map(|rate| rate * 1_000_000.0),
+ output_per_mtok_usd: price.output_per_token.map(|rate| rate * 1_000_000.0),
+ }
+ });
let billed = crate::inference::provider::model::usage_info_from_response(response);
let estimated_cost_usd = if response.served_from_cache
|| billed.is_some_and(|usage| usage.charge_reported && !usage.cost_is_estimate)
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
index 49110107b6..66f166add0 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
@@ -324,6 +324,47 @@ fn supplemental_cached_response_is_marked_before_usage_without_provider_charge()
&& enrichment.estimated_cost_usd.is_none()));
}
+#[test]
+fn supplemental_free_route_uses_zero_catalog_rates() {
+ use std::sync::{Arc, Mutex};
+ use tinyagents_harness::events::{AgentEvent, EventListener, EventSink};
+ use tinyagents_harness::ids::RunId;
+
+ #[derive(Default)]
+ struct Recorder(Mutex<Vec<AgentEvent>>);
+ impl EventListener for Recorder {
+ fn on_event(&self, record: &tinyagents_harness::events::EventRecord) {
+ self.0.lock().unwrap().push(record.event.clone());
+ }
+ }
+
+ let run_id = RunId::new("host-supplemental-free-fixture");
+ let sink = EventSink::with_stream_id(run_id.as_str());
+ let recorder = Arc::new(Recorder::default());
+ sink.subscribe(recorder.clone());
+ let trace = SupplementalTrace::new(sink, run_id);
+ let (call_id, started_at_ms) = trace.begin("openrouter/test-model:free");
+ let response = tinyinference_llm::model::ModelResponse::assistant("free answer");
+ trace.completed(
+ call_id,
+ "openrouter/test-model:free",
+ started_at_ms,
+ serde_json::json!(["free prompt"]),
+ &response,
+ );
+
+ let records = recorder.0.lock().unwrap();
+ let enrichment = records.iter().find_map(|event| match event {
+ AgentEvent::GenerationEnriched { enrichment, .. } => Some(enrichment),
+ _ => None,
+ }).expect("supplemental generation carries catalog enrichment");
+ let pricing = enrichment.pricing.as_ref().expect("free routes have known zero rates");
+ assert_eq!(pricing.input_per_mtok_usd, Some(0.0));
+ assert_eq!(pricing.cached_input_per_mtok_usd, Some(0.0));
+ assert_eq!(pricing.output_per_mtok_usd, Some(0.0));
+ assert_eq!(enrichment.estimated_cost_usd, None);
+}
+
/// #6951: a turn that ended because the model ran out of output tokens while
/// reasoning is closed with that cause named, not with "you have finished
/// using tools" — which told the model its unfinished work was done.
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs
index 5b90bf6fbb..eb90d61faf 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs
@@ -196,7 +196,7 @@ async fn prepared_child_run_is_exported_from_its_native_journal_lineage() {
.iter()
.find(|span| {
span.attributes
- .get("run_id")
+ .get("run.id")
.is_some_and(|id| id == child_run_id.as_str())
})
.expect("native collector projects the actual linked child");
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
index e57ac9ea67..e57481696c 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
@@ -117,13 +117,21 @@ async fn host_supplemental_generation_is_journaled_without_loop_progress_or_bill
call_id: supplemental.clone(),
model: "mock-model".into(),
});
+ let mut cached_usage = Usage::new(50, 12);
+ cached_usage.charged_amount = Some(tinyinference_llm::usage::ChargedAmount::usd_micros(8_000));
+ sink.emit(AgentEvent::ModelResponseCached {
+ call_id: supplemental.clone(),
+ });
sink.emit(AgentEvent::UsageRecorded {
- usage: Usage::new(50, 12),
+ usage: cached_usage,
});
sink.emit(AgentEvent::ModelCompleted {
call_id: supplemental,
started_at_ms: Some(1),
- usage: Some(Usage::new(50, 12)),
+ usage: Some(Usage {
+ charged_amount: Some(tinyinference_llm::usage::ChargedAmount::usd_micros(8_000)),
+ ..Usage::new(50, 12)
+ }),
input: Some(serde_json::json!(["private prompt"])),
output: Some(serde_json::json!("private response")),
});