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: reformat chained method calls for readability
Steven Enamakela8c883564e21
diff --git a/crates/openhuman-core/src/agent/cost_tests.rs b/crates/openhuman-core/src/agent/cost_tests.rsindex 1578fdd208..5d5695d21d 100644--- a/crates/openhuman-core/src/agent/cost_tests.rs+++ b/crates/openhuman-core/src/agent/cost_tests.rs@@ -1,7 +1,9 @@use super::*;fn usage(input: u64, output: u64, cached: u64, charged: f64) -> BilledUsage {- BilledUsage::from_counts(input, output).with_cached_input_tokens(cached).with_charged_usd(charged)+ 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 fca59292f7..e9caea2b65 100644--- a/crates/openhuman-core/src/agent/goals/runtime_tests.rs+++ b/crates/openhuman-core/src/agent/goals/runtime_tests.rs@@ -4,10 +4,7 @@ use crate::inference::provider::BilledUsage;fn cost_with_tokens(input: u64, output: u64) -> TurnCost {let mut tc = TurnCost::new();- tc.add_call(- "agentic-v1",- &BilledUsage::from_counts(input, output),- );+ tc.add_call("agentic-v1", &BilledUsage::from_counts(input, output));tc}diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rsindex 847bf83f80..9efec83f97 100644--- a/crates/openhuman-core/src/agent/session_host/driver.rs+++ b/crates/openhuman-core/src/agent/session_host/driver.rs@@ -517,7 +517,11 @@ fn driver_error_with_snapshot(.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),+ &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/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rsindex 4eefb42b23..a8c2573c89 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@@ -21,7 +21,7 @@ use crate::agent::{},tinyagents::{TinyagentsTurnOutcome, TurnModelSource},};-use crate::inference::provider::{ChatResponse, BilledUsage, AGENT_TURN_MAX_OUTPUT_TOKENS};+use crate::inference::provider::{BilledUsage, ChatResponse, AGENT_TURN_MAX_OUTPUT_TOKENS};/// Accounting from model calls performed after the harness loop has ended.#[derive(Default)]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 978c45bce2..872e5f9e21 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,7 +411,15 @@ 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::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),+ &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 9a9c89361e..5a50e21651 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs@@ -285,10 +285,16 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>guard.input_tokens += usage.input_tokens;guard.output_tokens += usage.output_tokens;guard.cached_input_tokens += usage.cache_read_tokens;- let host_usage = crate::agent::tinyagents::model::usage_info_from_response(- response,- )- .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));+ let host_usage =+ crate::agent::tinyagents::model::usage_info_from_response(response).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 3a8c41626b..3c18c60fa7 100644--- a/crates/openhuman-core/src/agent/tinyagents/model.rs+++ b/crates/openhuman-core/src/agent/tinyagents/model.rs@@ -10,7 +10,7 @@ use tinyinference_llm::model::{use tinyinference_llm::tool::ToolCall as TaToolCall;use tinyinference_llm::usage::Usage;-use crate::inference::provider::{ChatResponse, BilledUsage};+use crate::inference::provider::{BilledUsage, ChatResponse};pub(super) type TurnChatModel = Arc<dyn ChatModel<()>>;pub(super) type TierRoutes = Vec<(String, TurnChatModel)>;@@ -303,7 +303,14 @@ pub(crate) fn usage_info_from_response(response: &ModelResponse) -> Option<Bille.and_then(serde_json::Value::as_f64).unwrap_or_default();}- 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))+ 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 bccd2b4eb2..7aa4a49667 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,7 +13,14 @@ 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::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)),+ 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);diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rsindex e518c12251..dd14734295 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs@@ -437,7 +437,12 @@ 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::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);+ 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={}",@@ -476,7 +481,10 @@ impl OpenhumanEventBridge {pub(super) fn estimate_call_cost(model: &str, usage: &Usage) -> f64 {crate::agent::cost::estimate_call_cost_usd(model,- &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),+ &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 84faf47898..bddd06d45f 100644--- a/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rs+++ b/crates/openhuman-core/src/agent/tinyagents/stop_hooks.rs@@ -101,7 +101,10 @@ whereif let Some(usage) = &response.usage {cost.add_call(&self.model,- &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),+ &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 9835ed0c1e..40fcd80937 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs@@ -134,7 +134,9 @@ pub(crate) fn record_unobserved_turn_usage();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),+ &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/flows/tinyflows/caps/prompt.rs b/crates/openhuman-core/src/flows/tinyflows/caps/prompt.rsindex 9bfcba50f8..2aaf89420e 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/prompt.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/prompt.rs@@ -94,3 +94,7 @@ pub(crate) fn resolve_completion_model(node_model: Option<&str>, resolved_model:_ => resolved_model,}}++#[cfg(test)]+#[path = "prompt_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/prompt_tests.rs b/crates/openhuman-core/src/flows/tinyflows/caps/prompt_tests.rsnew file mode 100644index 0000000000..7f6be13640--- /dev/null+++ b/crates/openhuman-core/src/flows/tinyflows/caps/prompt_tests.rs@@ -0,0 +1,26 @@+use super::*;++/// The flow `agent`/`llm` node result exposes usage under these exact keys;+/// they are a contract with saved flows, so pin the literal JSON.+#[test]+fn usage_to_json_wire_shape_is_stable() {+ assert_eq!(usage_to_json(&None), serde_json::Value::Null);+ let usage = 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);+ assert_eq!(+ usage_to_json(&Some(usage)),+ serde_json::json!({+ "input_tokens": 100,+ "output_tokens": 20,+ "context_window": 128000,+ "cached_input_tokens": 40,+ "cache_creation_tokens": 10,+ "reasoning_tokens": 7,+ "charged_amount_usd": 0.0123+ })+ );+}diff --git a/crates/openhuman-core/src/memory/ops/fallback.rs b/crates/openhuman-core/src/memory/ops/fallback.rsindex d02477c3d8..9bf36fe540 100644--- a/crates/openhuman-core/src/memory/ops/fallback.rs+++ b/crates/openhuman-core/src/memory/ops/fallback.rs@@ -65,7 +65,9 @@ pub(crate) fn classify_for_engine(external: bool, message: String) -> String {pub(crate) fn classify_rpc_error(message: String) -> String {let external = crate::core::runtime::context::CoreContext::current().and_then(|ctx| ctx.memory().ok())- .is_none_or(|guard| guard.policy().class() == crate::core::subsystem::DriverClass::External);+ .is_none_or(|guard| {+ guard.policy().class() == crate::core::subsystem::DriverClass::External+ });classify_for_engine(external, message)}diff --git a/crates/openhuman-core/src/threads/ops/usage.rs b/crates/openhuman-core/src/threads/ops/usage.rsindex cfb6a97dee..82ebd6da5c 100644--- a/crates/openhuman-core/src/threads/ops/usage.rs+++ b/crates/openhuman-core/src/threads/ops/usage.rs@@ -68,7 +68,8 @@ 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::from_counts(input, output).with_cached_input_tokens(cached),+ &crate::inference::provider::BilledUsage::from_counts(input, output)+ .with_cached_input_tokens(cached),),None => fallback,};