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
refactor(agent): track session cost with CostTally instead of raw usd
Steven Enamakelae9d5b00ebf9
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rsindex 02c9bdd325..aefd8aa03b 100644--- a/crates/openhuman-core/src/agent/session_host/driver.rs+++ b/crates/openhuman-core/src/agent/session_host/driver.rs@@ -387,14 +387,14 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {+ repair_usage.map(|usage| usage.cached_input_tokens).unwrap_or_default();- observed.cost_usd = outcome.charged_amount_usd- + close- .as_ref()- .map(|close| close.usage.charged_amount_usd)- .unwrap_or_default()- + repair_usage- .map(|usage| usage.charged_amount_usd)- .unwrap_or_default();+ let mut cost = outcome.cost;+ if let Some(close) = close.as_ref() {+ cost.merge(close.usage.cost);+ }+ if let Some(repair) = repair_usage {+ cost.merge(repair.cost);+ }+ observed.cost = cost;let loop_last_call = snapshot.lock().ok()@@ -560,24 +560,9 @@ fn driver_error_with_snapshot(observed.cached_input_tokens = guard.cached_input_tokens;observed.last_call_input_tokens = guard.last_call_input_tokens;observed.last_call_output_tokens = guard.last_call_output_tokens;- observed.cost_usd = if guard.charged_amount_usd > 0.0 {- guard.charged_amount_usd- } else {- let pricing_model = guard- .resolved_route- .as_ref()- .map(|route| route.route.as_str())- .filter(|route| !route.trim().is_empty())- .unwrap_or(fallback_model);- crate::agent::cost::estimate_call_cost_usd(- pricing_model,- &crate::inference::provider::BilledUsage::from_counts(- guard.input_tokens,- guard.output_tokens,- )- .with_cached_input_tokens(guard.cached_input_tokens),- )- };+ // Each answered call was priced as it arrived (reported charge, else+ // catalog estimate, else unknown); nothing is re-estimated here.+ observed.cost = guard.cost;observed.duration = Some(elapsed);observed.tool_outcomes = guard.tool_outcomes.clone();observed.resolved_route = guard.resolved_route.clone();diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex 7c53b64800..e8760c03fc 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -114,7 +114,9 @@ pub(crate) struct SessionTurnSidecar {pub input_tokens: u64,pub output_tokens: u64,pub cached_input_tokens: u64,- pub cost_usd: f64,+ /// The turn's own cost (sub-agents excluded): every call's reported+ /// charge, else catalog estimate, else unknown.+ pub cost: crate::agent::cost::CostTally,/// Input and output tokens of the turn's final model call. The totals/// above sum every call of the turn (its spend); these are the context the/// model last held, the numerator of the context-window gauge.