Skip to content

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

chore: files changed crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs,crates/openhuman-cor

Steven Enamakel287c8be6951e
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
index 2cb01195df..50e7b95fab 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
@@ -32,10 +32,9 @@ pub(crate) struct TinyagentsTurnOutcome {
/// Accumulated cached (cache-read) input tokens. Carried so the turn persists
/// real cached usage instead of zero (issue #4249, Phase 5).
pub cached_input_tokens: u64,
- /// Estimated charged USD for the turn (from `cost::catalog::estimate_cost_usd`
- /// over the observed usage). Carried so the transcript / session meters record
- /// a real cost instead of `$0` on every non-cap turn.
- pub charged_amount_usd: f64,
+ /// The turn's cost: each call's reported charge, else its catalog
+ /// estimate, else unknown (see [`crate::agent::cost::call_cost`]).
+ pub cost: crate::agent::cost::CostTally,
/// Set when an early-exit tool (e.g. `ask_user_clarification`) fired: the
/// loop paused so the caller can checkpoint and surface the question. When
/// present, `text` holds the question. Mirrors the legacy `early_exit_tool`.
@@ -145,7 +144,7 @@ pub(crate) fn record_unobserved_turn_usage(
input_tokens: u64,
output_tokens: u64,
cached_input_tokens: u64,
- charged_amount_usd: f64,
+ estimated_usd: Option<f64>,
) -> bool {
if input_tokens == 0 && output_tokens == 0 {
return false;
@@ -154,15 +153,18 @@ pub(crate) fn record_unobserved_turn_usage(
model,
input_tokens,
output_tokens,
- charged_usd = charged_amount_usd,
+ ?estimated_usd,
"[tinyagents] recording unobserved-turn usage into the global cost tracker"
);
- crate::platform::cost::record_provider_usage(
- model,
- &crate::inference::provider::BilledUsage::from_counts(input_tokens, output_tokens)
- .with_cached_input_tokens(cached_input_tokens)
- .with_charged_usd(charged_amount_usd),
- );
+ let usage = crate::inference::provider::BilledUsage::from_counts(input_tokens, output_tokens)
+ .with_cached_input_tokens(cached_input_tokens);
+ // No per-call charge reached this path; record the catalog estimate when
+ // the model has one, else the record stays unpriced.
+ let usage = match estimated_usd {
+ Some(usd) => usage.with_estimated_usd(usd),
+ None => usage,
+ };
+ crate::platform::cost::record_provider_usage(model, &usage);
true
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
index 2ea07936cb..07252808df 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -166,17 +166,27 @@ pub(super) async fn finalize_turn_outcome(
// cached tokens and the estimated charged USD) when the observed path ran;
// otherwise fall back to the run's aggregate totals and estimate the cost from
// them so a fire-and-forget turn still reports a real (non-$0) cost.
- let (input_tokens, output_tokens, cached_input_tokens, charged_amount_usd) = bridge_totals
+ let (input_tokens, output_tokens, cached_input_tokens, cost) = bridge_totals
.unwrap_or_else(|| {
let input = run.usage.usage.input_tokens;
let output = run.usage.usage.output_tokens;
let cached = run.usage.usage.cache_read_tokens;
- let charged =
- crate::platform::cost::catalog::estimate_cost_usd(model, input, output, cached);
+ // No per-call charges on this path: the catalog estimate when the
+ // model has a list price, else the turn's cost is unknown.
+ let estimate = crate::agent::cost::estimate_call_cost_usd(
+ model,
+ &crate::inference::provider::BilledUsage::from_counts(input, output)
+ .with_cached_input_tokens(cached),
+ );
crate::agent::tinyagents::turn_outcome::record_unobserved_turn_usage(
- model, input, output, cached, charged,
+ model, input, output, cached, estimate,
);
- (input, output, cached, charged)
+ let mut cost = crate::agent::cost::CostTally::default();
+ cost.add(match estimate {
+ Some(usd) => crate::agent::cost::CallCost::Estimated(usd),
+ None => crate::agent::cost::CallCost::Unknown,
+ });
+ (input, output, cached, cost)
});
// An early-exit tool fired: the loop paused after its round. Surface the tool
@@ -308,7 +318,7 @@ pub(super) async fn finalize_turn_outcome(
input_tokens,
output_tokens,
cached_input_tokens,
- charged_amount_usd,
+ cost,
early_exit_tool,
hit_cap,
wrap_up_injected,