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
chore: files changed crates/openhuman-core/src/agent/context/manager_tests.rs,crates/openhuman-core/
Steven Enamakelb046a9fdd452
diff --git a/crates/openhuman-core/src/agent/context/manager_tests.rs b/crates/openhuman-core/src/agent/context/manager_tests.rsindex cb724eff30..be5731bcfa 100644--- a/crates/openhuman-core/src/agent/context/manager_tests.rs+++ b/crates/openhuman-core/src/agent/context/manager_tests.rs@@ -21,12 +21,7 @@ fn default_manager() -> ContextManager {#[test]fn stats_reports_snapshot() {let mut manager = default_manager();- manager.record_usage(&BilledUsage {- input_tokens: 10_000,- output_tokens: 2_000,- context_window: 100_000,- ..Default::default()- });+ manager.record_usage(&BilledUsage::from_counts(10_000, 2_000).with_context_window(100_000));manager.tick_turn();manager.record_tool_calls(3);@@ -82,12 +77,7 @@ fn autocompact_enabled_requires_both_master_and_autocompact_flags() {#[test]fn session_memory_lifecycle_changes_should_extract_state() {let mut manager = default_manager();- manager.record_usage(&BilledUsage {- input_tokens: 20_000,- output_tokens: 0,- context_window: 100_000,- ..Default::default()- });+ manager.record_usage(&BilledUsage::from_counts(20_000, 0).with_context_window(100_000));for _ in 0..5 {manager.tick_turn();}diff --git a/crates/openhuman-core/src/agent/cost_tests.rs b/crates/openhuman-core/src/agent/cost_tests.rsindex 5ccc059ec2..1578fdd208 100644--- a/crates/openhuman-core/src/agent/cost_tests.rs+++ b/crates/openhuman-core/src/agent/cost_tests.rs@@ -1,13 +1,7 @@use super::*;fn usage(input: u64, output: u64, cached: u64, charged: f64) -> BilledUsage {- BilledUsage {- input_tokens: input,- output_tokens: output,- cached_input_tokens: cached,- charged_amount_usd: charged,- ..Default::default()- }+ BilledUsage::from_counts(input, output).with_cached_input_tokens(cached).with_charged_usd(charged)}const FLASH: &str = crate::config::MODEL_MANAGED_DEFAULT;diff --git a/crates/openhuman-core/src/agent/goals/runtime_tests.rs b/crates/openhuman-core/src/agent/goals/runtime_tests.rsindex b984857259..fca59292f7 100644--- a/crates/openhuman-core/src/agent/goals/runtime_tests.rs+++ b/crates/openhuman-core/src/agent/goals/runtime_tests.rs@@ -6,11 +6,7 @@ fn cost_with_tokens(input: u64, output: u64) -> TurnCost {let mut tc = TurnCost::new();tc.add_call("agentic-v1",- &BilledUsage {- input_tokens: input,- output_tokens: output,- ..Default::default()- },+ &BilledUsage::from_counts(input, output),);tc}diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rsindex 5139844fe7..7286485c12 100644--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs@@ -492,15 +492,7 @@ fn observation_to_progress(obs: &AgentObservation, state: &mut ReplayState) -> V// The token counts are exact; `cost_usd` is an estimate.state.cost_usd += crate::agent::cost::estimate_call_cost_usd(&state.model,- &crate::inference::provider::BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window: 0,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens: usage.cache_creation_tokens,- reasoning_tokens: usage.reasoning_tokens,- charged_amount_usd: 0.0,- },+ &crate::inference::provider::BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens),);state.input_tokens += usage.input_tokens;state.output_tokens += usage.output_tokens;diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rsindex 27f52a66ec..847bf83f80 100644--- a/crates/openhuman-core/src/agent/session_host/driver.rs+++ b/crates/openhuman-core/src/agent/session_host/driver.rs@@ -517,15 +517,7 @@ fn driver_error_with_snapshot(.unwrap_or(fallback_model);crate::agent::cost::estimate_call_cost_usd(pricing_model,- &crate::inference::provider::BilledUsage {- input_tokens: guard.input_tokens,- output_tokens: guard.output_tokens,- context_window: 0,- cached_input_tokens: guard.cached_input_tokens,- cache_creation_tokens: 0,- reasoning_tokens: 0,- charged_amount_usd: 0.0,- },+ &crate::inference::provider::BilledUsage::from_counts(guard.input_tokens, guard.output_tokens).with_cached_input_tokens(guard.cached_input_tokens),)};observed.duration = Some(elapsed);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.rsindex 75ab409c87..d64bcdeccb 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@@ -411,15 +411,7 @@ pub(in super::super) async fn run_subagent_via_graph(usage.charged_amount_usd += call_cost;crate::platform::cost::record_provider_usage(model,- &crate::inference::provider::BilledUsage {- input_tokens: u.input_tokens,- output_tokens: u.output_tokens,- context_window: u.context_window,- cached_input_tokens: u.cached_input_tokens,- cache_creation_tokens: u.cache_creation_tokens,- reasoning_tokens: u.reasoning_tokens,- charged_amount_usd: call_cost,- },+ &crate::inference::provider::BilledUsage::from_counts(u.input_tokens, u.output_tokens).with_context_window(u.context_window).with_cached_input_tokens(u.cached_input_tokens).with_cache_creation_tokens(u.cache_creation_tokens).with_reasoning_tokens(u.reasoning_tokens).with_charged_usd(call_cost),);tracing::debug!(agent_id,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rsindex 84536d701a..9a9c89361e 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs@@ -288,15 +288,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>let host_usage = crate::agent::tinyagents::model::usage_info_from_response(response,)- .unwrap_or(crate::inference::provider::BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window: 0,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens: usage.cache_creation_tokens,- reasoning_tokens: usage.reasoning_tokens,- charged_amount_usd: 0.0,- });+ .unwrap_or(crate::inference::provider::BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens));// Use the host's per-call pricing helper whenever the provider// omitted an authoritative amount. `route` is preferred over a// construction-time model because it preserves fallback pricing.diff --git a/crates/openhuman-core/src/agent/tinyagents/model.rs b/crates/openhuman-core/src/agent/tinyagents/model.rsindex 849c7507e5..0e599cbb5d 100644--- a/crates/openhuman-core/src/agent/tinyagents/model.rs+++ b/crates/openhuman-core/src/agent/tinyagents/model.rs@@ -303,15 +303,7 @@ pub(crate) fn usage_info_from_response(response: &ModelResponse) -> Option<Bille.and_then(serde_json::Value::as_f64).unwrap_or_default();}- Some(BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window: meta.context_window,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens: usage.cache_creation_tokens,- reasoning_tokens: usage.reasoning_tokens,- charged_amount_usd: meta.charged_amount_usd,- })+ Some(BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_context_window(meta.context_window).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens).with_charged_usd(meta.charged_amount_usd))}/// Shared slot that preserves the most recent original provider error.diff --git a/crates/openhuman-core/src/agent/tinyagents/model_g1_usage_tests_tests.rs b/crates/openhuman-core/src/agent/tinyagents/model_g1_usage_tests_tests.rsindex dfcac0b931..df15252719 100644--- a/crates/openhuman-core/src/agent/tinyagents/model_g1_usage_tests_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/model_g1_usage_tests_tests.rs@@ -13,15 +13,7 @@ fn usage_round_trips_charged_usd_and_all_token_breakdowns() {let chat = ChatResponse {text: Some("hi".to_string()),tool_calls: Vec::new(),- usage: Some(BilledUsage {- input_tokens: 100,- output_tokens: 20,- context_window: 128_000,- cached_input_tokens: 40,- cache_creation_tokens: 10,- reasoning_tokens: 7,- charged_amount_usd: 0.0123,- }),+ usage: Some(BilledUsage::from_counts(100, 20).with_context_window(128_000).with_cached_input_tokens(40).with_cache_creation_tokens(10).with_reasoning_tokens(7).with_charged_usd(0.0123)),reasoning_content: None,};let model_response = response_to_model_response(&chat, &empty_registry(), false);@@ -55,11 +47,7 @@ fn no_billing_metadata_leaves_raw_clean() {let chat = ChatResponse {text: Some("hi".to_string()),tool_calls: Vec::new(),- usage: Some(BilledUsage {- input_tokens: 5,- output_tokens: 3,- ..Default::default()- }),+ usage: Some(BilledUsage::from_counts(5, 3)),reasoning_content: None,};let model_response = response_to_model_response(&chat, &empty_registry(), false);diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rsindex 65057adf98..e009f2a423 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs@@ -437,15 +437,7 @@ impl OpenhumanEventBridge {// Feed the authoritative global cost tracker (same call the legacy// observer made), so the wallet/cost surfaces stay accurate.- let usage_info = BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens,- reasoning_tokens,- charged_amount_usd: call_cost,- };+ let usage_info = BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_context_window(context_window).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(cache_creation_tokens).with_reasoning_tokens(reasoning_tokens).with_charged_usd(call_cost);if reasoning_tokens > 0 || cache_creation_tokens > 0 {log::debug!("[cost] recording reasoning/cache-creation tokens model={} reasoning_tokens={} cache_creation_tokens={}",@@ -484,15 +476,7 @@ impl OpenhumanEventBridge {pub(super) fn estimate_call_cost(model: &str, usage: &Usage) -> f64 {crate::agent::cost::estimate_call_cost_usd(model,- &BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window: 0,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens: usage.cache_creation_tokens,- reasoning_tokens: usage.reasoning_tokens,- charged_amount_usd: 0.0,- },+ &BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens),)}}diff --git a/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rs b/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rsindex 51e126a246..84faf47898 100644--- a/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rs+++ b/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rs@@ -101,15 +101,7 @@ whereif let Some(usage) = &response.usage {cost.add_call(&self.model,- &BilledUsage {- input_tokens: usage.input_tokens,- output_tokens: usage.output_tokens,- context_window: 0,- cached_input_tokens: usage.cache_read_tokens,- cache_creation_tokens: usage.cache_creation_tokens,- reasoning_tokens: usage.reasoning_tokens,- charged_amount_usd: 0.0,- },+ &BilledUsage::from_counts(usage.input_tokens, usage.output_tokens).with_cached_input_tokens(usage.cache_read_tokens).with_cache_creation_tokens(usage.cache_creation_tokens).with_reasoning_tokens(usage.reasoning_tokens),);}cost.clone()diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rsindex 184a76aa16..9835ed0c1e 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs@@ -134,15 +134,7 @@ pub(crate) fn record_unobserved_turn_usage();crate::platform::cost::record_provider_usage(model,- &crate::inference::provider::BilledUsage {- input_tokens,- output_tokens,- context_window: 0,- cached_input_tokens,- cache_creation_tokens: 0,- reasoning_tokens: 0,- charged_amount_usd,- },+ &crate::inference::provider::BilledUsage::from_counts(input_tokens, output_tokens).with_cached_input_tokens(cached_input_tokens).with_charged_usd(charged_amount_usd),);true}diff --git a/crates/openhuman-core/src/inference/provider/types.rs b/crates/openhuman-core/src/inference/provider/types.rsindex 1770d887c8..211f6458ea 100644--- a/crates/openhuman-core/src/inference/provider/types.rs+++ b/crates/openhuman-core/src/inference/provider/types.rs@@ -53,6 +53,18 @@ impl BilledUsage {self}+ /// Sets the cache-creation (write) token count.+ pub fn with_cache_creation_tokens(mut self, tokens: u64) -> Self {+ self.usage.cache_creation_tokens = tokens;+ self+ }++ /// Sets the reasoning/thinking token count.+ pub fn with_reasoning_tokens(mut self, tokens: u64) -> Self {+ self.usage.reasoning_tokens = tokens;+ self+ }+/// Sets the provider-charged USD amount.pub fn with_charged_usd(mut self, usd: f64) -> Self {self.charged_amount_usd = usd;diff --git a/crates/openhuman-core/src/platform/cost/global_tests.rs b/crates/openhuman-core/src/platform/cost/global_tests.rsindex 5e0b74de52..c0dd151f8c 100644--- a/crates/openhuman-core/src/platform/cost/global_tests.rs+++ b/crates/openhuman-core/src/platform/cost/global_tests.rs@@ -4,15 +4,7 @@ use crate::platform::cost::types::CostRecord;use tempfile::TempDir;fn make_usage(input: u64, output: u64, charged: f64) -> BilledUsage {- BilledUsage {- input_tokens: input,- output_tokens: output,- context_window: 0,- cached_input_tokens: 0,- cache_creation_tokens: 0,- reasoning_tokens: 0,- charged_amount_usd: charged,- }+ BilledUsage::from_counts(input, output).with_charged_usd(charged)}#[test]diff --git a/crates/openhuman-core/src/threads/ops/usage.rs b/crates/openhuman-core/src/threads/ops/usage.rsindex 90b7bedc5f..cfb6a97dee 100644--- a/crates/openhuman-core/src/threads/ops/usage.rs+++ b/crates/openhuman-core/src/threads/ops/usage.rs@@ -68,12 +68,7 @@ pub async fn token_usage(|model: Option<&str>, input: u64, output: u64, cached: u64, fallback: f64| match model {Some(m) => crate::agent::cost::estimate_call_cost_usd(m,- &crate::inference::provider::BilledUsage {- input_tokens: input,- output_tokens: output,- cached_input_tokens: cached,- ..Default::default()- },+ &crate::inference::provider::BilledUsage::from_counts(input, output).with_cached_input_tokens(cached),),None => fallback,};