Skip to content

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

refactor(agent): thread turn context through session and subagent hosts

Steven Enamakeld79098147624
diff --git a/crates/openhuman-core/src/agent/cost.rs b/crates/openhuman-core/src/agent/cost.rs
index 166b14143c..7efbe7ec07 100644
--- a/crates/openhuman-core/src/agent/cost.rs
+++ b/crates/openhuman-core/src/agent/cost.rs
@@ -17,6 +17,7 @@
//! $4.25 when the provider billed about $0.30.
use crate::inference::provider::BilledUsage;
+use tinyagents_harness::cost::{CallCost, CallUsage, CostTally};
/// Whether a model names an explicitly free OpenRouter variant.
pub(crate) fn is_free_model(model: &str) -> bool {
@@ -39,111 +40,26 @@ pub(crate) fn lookup_pricing(model: &str) -> Option<tinyagents_harness::cost::Mo
/// Estimate a call from product list prices when no provider charge was reported.
pub fn estimate_call_cost_usd(model: &str, usage: &BilledUsage) -> Option<f64> {
- let pricing = lookup_pricing(model)?;
- let usage = tinyinference_llm::usage::Usage {
- input_tokens: usage.input_tokens,
- output_tokens: usage.output_tokens,
- cache_read_tokens: usage.cached_input_tokens().min(usage.input_tokens),
- ..Default::default()
- };
- Some(tinyagents_harness::cost::estimate_cost(&pricing, &usage).total_cost)
+ tinyagents_harness::cost::estimate_call_cost_usd(
+ lookup_pricing(model).as_ref(),
+ &call_usage(usage),
+ )
}
-/// Where a cost figure came from. Ordered from most to least certain, so the
-/// cost of several calls takes the least certain of their sources.
-#[derive(
- Debug,
- Clone,
- Copy,
- PartialEq,
- Eq,
- PartialOrd,
- Ord,
- Default,
- serde::Serialize,
- serde::Deserialize,
-)]
-#[serde(rename_all = "snake_case")]
-pub enum CostSource {
- /// Every call reported the amount the provider billed.
- #[default]
- Charged,
- /// At least one call was priced from the catalog's list rates.
- Estimated,
- /// At least one call had neither a charge nor a catalogued price, so the
- /// total is not known.
- Unknown,
-}
-
-/// The cost of one provider call.
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum CallCost {
- /// Billed by the provider (may be zero).
- Charged(f64),
- /// Catalog list-price estimate.
- Estimated(f64),
- /// Neither available.
- Unknown,
-}
-
-impl CallCost {
- /// The USD figure, or `None` when unknown.
- pub fn usd(self) -> Option<f64> {
- match self {
- Self::Charged(usd) | Self::Estimated(usd) => Some(usd),
- Self::Unknown => None,
- }
- }
-
- /// The source this cost contributes to a total.
- pub fn source(self) -> CostSource {
- match self {
- Self::Charged(_) => CostSource::Charged,
- Self::Estimated(_) => CostSource::Estimated,
- Self::Unknown => CostSource::Unknown,
- }
+/// The harness accounting view of one billed call.
+pub(crate) fn call_usage(usage: &BilledUsage) -> CallUsage {
+ CallUsage {
+ usage: usage.usage,
+ charged_amount_usd: usage.charged_amount_usd,
+ cost_is_estimate: usage.cost_is_estimate,
+ charge_reported: usage.charge_reported,
}
}
/// The cost of one call: the provider's charge when it reported one, else
/// the catalog estimate, else unknown.
pub fn call_cost(model: &str, usage: &BilledUsage) -> CallCost {
- if usage.charge_reported && !usage.cost_is_estimate {
- return CallCost::Charged(usage.charged_amount_usd);
- }
- match estimate_call_cost_usd(model, usage) {
- Some(usd) => CallCost::Estimated(usd),
- None => CallCost::Unknown,
- }
-}
-
-/// A sum of call costs that remembers how certain it is.
-#[derive(Debug, Clone, Copy, PartialEq, Default)]
-pub struct CostTally {
- /// Sum of the known call costs. Meaningless on its own once `source` is
- /// [`CostSource::Unknown`]; read it through [`CostTally::usd`].
- pub known_usd: f64,
- /// The least certain source among the calls added.
- pub source: CostSource,
-}
-
-impl CostTally {
- /// Fold one call in.
- pub fn add(&mut self, cost: CallCost) {
- self.known_usd += cost.usd().unwrap_or(0.0);
- self.source = self.source.max(cost.source());
- }
-
- /// Fold another tally in (a sub-step's or a child's).
- pub fn merge(&mut self, other: CostTally) {
- self.known_usd += other.known_usd;
- self.source = self.source.max(other.source);
- }
-
- /// The total, or `None` when any call's cost was unknown.
- pub fn usd(&self) -> Option<f64> {
- (self.source != CostSource::Unknown).then_some(self.known_usd)
- }
+ tinyagents_harness::cost::call_cost(lookup_pricing(model).as_ref(), &call_usage(usage))
}
/// Running cost / token tally across every provider call inside a
diff --git a/crates/openhuman-core/src/agent/session_host/codec.rs b/crates/openhuman-core/src/agent/session_host/codec.rs
index 3a9dc6b6c7..b365445021 100644
--- a/crates/openhuman-core/src/agent/session_host/codec.rs
+++ b/crates/openhuman-core/src/agent/session_host/codec.rs
@@ -176,9 +176,9 @@ impl TranscriptCodec<OpenHumanRunContext> for OpenHumanTranscriptCodec {
context_window: sidecar.context_window,
cost_usd: sidecar.cost.known_usd,
cost_source: Some(match sidecar.cost.source {
- crate::agent::cost::CostSource::Charged => UsageCostSource::Charged,
- crate::agent::cost::CostSource::Estimated => UsageCostSource::Estimated,
- crate::agent::cost::CostSource::Unknown => UsageCostSource::Unknown,
+ tinyagents_harness::cost::CostSource::Charged => UsageCostSource::Charged,
+ tinyagents_harness::cost::CostSource::Estimated => UsageCostSource::Estimated,
+ tinyagents_harness::cost::CostSource::Unknown => UsageCostSource::Unknown,
}),
last_call_input: sidecar.last_call_input_tokens,
last_call_output: sidecar.last_call_output_tokens,
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 ea421b5538..b49b402d7a 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
@@ -34,7 +34,7 @@ pub(super) struct RepairUsage {
pub(super) output_tokens: u64,
pub(super) cached_input_tokens: u64,
/// Cost of these calls: reported charge, catalog estimate, or unknown.
- pub(super) cost: crate::agent::cost::CostTally,
+ pub(super) cost: tinyagents_harness::cost::CostTally,
/// Model the calls ran on, for pricing a call that reported no charge.
pub(super) pricing_model: String,
/// The newest repair call's own input/output: a repair runs after the
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 dd2cc65d4b..1b4c474420 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
@@ -20,7 +20,7 @@ fn classified_halt_returns_partial_work_without_provider_usage() {
input_tokens: 100,
output_tokens: 20,
cached_input_tokens: 0,
- cost: crate::agent::cost::CostTally::default(),
+ cost: tinyagents_harness::cost::CostTally::default(),
early_exit_tool: None,
hit_cap: false,
wrap_up_injected: false,
@@ -212,7 +212,7 @@ fn blank_outcome(truncated: bool) -> TinyagentsTurnOutcome {
input_tokens: 0,
output_tokens: 0,
cached_input_tokens: 0,
- cost: crate::agent::cost::CostTally::default(),
+ cost: tinyagents_harness::cost::CostTally::default(),
early_exit_tool: None,
hit_cap: false,
wrap_up_injected: false,
diff --git a/crates/openhuman-core/src/agent/session_host/driver_tests.rs b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
index 5e4468f003..a58fbcd641 100644
--- a/crates/openhuman-core/src/agent/session_host/driver_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
@@ -91,9 +91,9 @@ fn graph_failure_copies_snapshot_usage_and_failed_tool_outcome_to_sidecar() {
cached_input_tokens: 3,
last_call_input_tokens: 13,
last_call_output_tokens: 5,
- cost: crate::agent::cost::CostTally {
+ cost: tinyagents_harness::cost::CostTally {
known_usd: 0.004,
- source: crate::agent::cost::CostSource::Charged,
+ source: tinyagents_harness::cost::CostSource::Charged,
},
resolved_route: Some(tinyinference_llm::model::ResolvedModelRoute::new(
"openhuman",
@@ -142,7 +142,7 @@ fn graph_failure_copies_snapshot_usage_and_failed_tool_outcome_to_sidecar() {
assert!((observed.cost.known_usd - 0.004).abs() < f64::EPSILON);
assert_eq!(
observed.cost.source,
- crate::agent::cost::CostSource::Charged
+ tinyagents_harness::cost::CostSource::Charged
);
let route = observed
.resolved_route
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
index 5c58607ca8..791f3a015c 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
@@ -112,9 +112,9 @@ fn codec_attaches_only_this_agents_own_sidecar_usage_to_atomic_append() {
sidecar.input_tokens = 13;
sidecar.output_tokens = 8;
sidecar.cached_input_tokens = 3;
- sidecar.cost = crate::agent::cost::CostTally {
+ sidecar.cost = tinyagents_harness::cost::CostTally {
known_usd: 0.004,
- source: crate::agent::cost::CostSource::Charged,
+ source: tinyagents_harness::cost::CostSource::Charged,
};
sidecar.context_window = 128_000;
sidecar.last_call_input_tokens = 9;
@@ -138,7 +138,7 @@ fn codec_attaches_only_this_agents_own_sidecar_usage_to_atomic_append() {
output_tokens: 2,
cached_input_tokens: 1,
charged_amount_usd: 0.001,
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
},
});
// `OpenHumanRunContext` is `Clone` and its child ledger is an `Arc`, so this
@@ -203,9 +203,9 @@ fn last_turn_usage_reports_the_same_holistic_totals_as_transcript_billing() {
input_tokens: 13,
output_tokens: 8,
cached_input_tokens: 3,
- cost: crate::agent::cost::CostTally {
+ cost: tinyagents_harness::cost::CostTally {
known_usd: 0.004,
- source: crate::agent::cost::CostSource::Charged,
+ source: tinyagents_harness::cost::CostSource::Charged,
},
context_window: 128_000,
last_call_input_tokens: 9,
@@ -222,7 +222,7 @@ fn last_turn_usage_reports_the_same_holistic_totals_as_transcript_billing() {
output_tokens: 2,
cached_input_tokens: 1,
charged_amount_usd: 0.001,
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
},
});
diff --git a/crates/openhuman-core/src/agent/stop_hooks_tests.rs b/crates/openhuman-core/src/agent/stop_hooks_tests.rs
index 85f7787720..887a0c146e 100644
--- a/crates/openhuman-core/src/agent/stop_hooks_tests.rs
+++ b/crates/openhuman-core/src/agent/stop_hooks_tests.rs
@@ -77,9 +77,9 @@ async fn scoped_stop_hooks_are_visible_to_run_contexts() {
async fn budget_stop_hook_fails_closed_and_stops_at_cap() {
let hook = BudgetStopHook::new(1.0);
let cost = TurnCost {
- cost: crate::agent::cost::CostTally {
+ cost: tinyagents_harness::cost::CostTally {
known_usd: 1.0,
- source: crate::agent::cost::CostSource::Charged,
+ source: tinyagents_harness::cost::CostSource::Charged,
},
..TurnCost::default()
};
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 88280bb2b4..5f7f35ee42 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -1239,9 +1239,9 @@ fn map_lifecycle_error(error: SubagentError) -> SubagentRunError {
/// A child run's cost as it comes back across the orchestration boundary.
/// That `Usage` can only say whether a charge is present, so a present one is
/// read as charged and an absent one as unknown (it was sent as absent).
-fn cost_source_of(charged: Option<&ChargedAmount>) -> crate::agent::cost::CostSource {
+fn cost_source_of(charged: Option<&ChargedAmount>) -> tinyagents_harness::cost::CostSource {
match charged {
- Some(_) => crate::agent::cost::CostSource::Charged,
- None => crate::agent::cost::CostSource::Unknown,
+ Some(_) => tinyagents_harness::cost::CostSource::Charged,
+ None => tinyagents_harness::cost::CostSource::Unknown,
}
}
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.rs
index d6747957cb..04ffeffeaf 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
@@ -26,7 +26,7 @@ pub(in super::super) struct AggregatedUsage {
pub(in super::super) output_tokens: u64,
pub(in super::super) cached_input_tokens: u64,
/// Cost of the run's calls: reported charge, catalog estimate, or unknown.
- pub(in super::super) cost: crate::agent::cost::CostTally,
+ pub(in super::super) cost: tinyagents_harness::cost::CostTally,
}
/// Drive a sub-agent turn on the tinyagents harness. Returns
@@ -405,11 +405,11 @@ pub(in super::super) async fn run_subagent_via_graph(
.with_cache_creation_tokens(u.cache_creation_tokens)
.with_reasoning_tokens(u.reasoning_tokens);
let billed = match call_cost {
- crate::agent::cost::CallCost::Charged(usd) => billed.with_charged_usd(usd),
- crate::agent::cost::CallCost::Estimated(usd) => {
+ tinyagents_harness::cost::CallCost::Charged(usd) => billed.with_charged_usd(usd),
+ tinyagents_harness::cost::CallCost::Estimated(usd) => {
billed.with_estimated_usd(usd)
}
- crate::agent::cost::CallCost::Unknown => billed,
+ tinyagents_harness::cost::CallCost::Unknown => billed,
};
crate::platform::cost::record_provider_usage_scoped(
model,
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph/transcript.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph/transcript.rs
index 35c6163261..8906630776 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph/transcript.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph/transcript.rs
@@ -81,9 +81,9 @@ pub(super) fn persist_subagent_transcript(
context_window,
cost_usd: usage.cost.known_usd,
cost_source: Some(match usage.cost.source {
- crate::agent::cost::CostSource::Charged => transcript::UsageCostSource::Charged,
- crate::agent::cost::CostSource::Estimated => transcript::UsageCostSource::Estimated,
- crate::agent::cost::CostSource::Unknown => transcript::UsageCostSource::Unknown,
+ tinyagents_harness::cost::CostSource::Charged => transcript::UsageCostSource::Charged,
+ tinyagents_harness::cost::CostSource::Estimated => transcript::UsageCostSource::Estimated,
+ tinyagents_harness::cost::CostSource::Unknown => transcript::UsageCostSource::Unknown,
}),
// No per-call figure reaches here; readers fall back to the mean
// request size (`spend::context_tokens_of`).
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph_tests.rs
index 97d8be9305..4213c61da9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph_tests.rs
@@ -16,9 +16,9 @@ fn subagent_transcript_keeps_cumulative_spend_separate_from_unknown_last_call()
input_tokens: 120,
output_tokens: 30,
cached_input_tokens: 40,
- cost: crate::agent::cost::CostTally {
+ cost: tinyagents_harness::cost::CostTally {
known_usd: 0.01,
- source: crate::agent::cost::CostSource::Charged,
+ source: tinyagents_harness::cost::CostSource::Charged,
},
};
super::transcript::persist_subagent_transcript(
diff --git a/crates/openhuman-core/src/agent/subagent_host/types.rs b/crates/openhuman-core/src/agent/subagent_host/types.rs
index a05a3d00eb..62bb9d44ff 100644
--- a/crates/openhuman-core/src/agent/subagent_host/types.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/types.rs
@@ -203,21 +203,21 @@ pub struct SubagentUsage {
default = "unknown_cost_source",
skip_serializing_if = "is_unknown_cost_source"
)]
- pub cost_source: crate::agent::cost::CostSource,
+ pub cost_source: tinyagents_harness::cost::CostSource,
}
-fn unknown_cost_source() -> crate::agent::cost::CostSource {
- crate::agent::cost::CostSource::Unknown
+fn unknown_cost_source() -> tinyagents_harness::cost::CostSource {
+ tinyagents_harness::cost::CostSource::Unknown
}
-fn is_unknown_cost_source(source: &crate::agent::cost::CostSource) -> bool {
- *source == crate::agent::cost::CostSource::Unknown
+fn is_unknown_cost_source(source: &tinyagents_harness::cost::CostSource) -> bool {
+ *source == tinyagents_harness::cost::CostSource::Unknown
}
impl SubagentUsage {
/// The run's cost as a tally, for folding into a parent's.
- pub fn cost(&self) -> crate::agent::cost::CostTally {
- crate::agent::cost::CostTally {
+ pub fn cost(&self) -> tinyagents_harness::cost::CostTally {
+ tinyagents_harness::cost::CostTally {
known_usd: self.charged_amount_usd,
source: self.cost_source,
}
diff --git a/crates/openhuman-core/src/agent/subagent_host/types_tests.rs b/crates/openhuman-core/src/agent/subagent_host/types_tests.rs
index cfbf9538a2..4d1cbcd721 100644
--- a/crates/openhuman-core/src/agent/subagent_host/types_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/types_tests.rs
@@ -7,10 +7,10 @@ fn legacy_subagent_usage_keeps_its_wire_shape_and_does_not_claim_a_charge() {
"cached_input_tokens": 1, "charged_amount_usd": 0.5,
});
let mut usage: SubagentUsage = serde_json::from_value(raw.clone()).unwrap();
- assert_eq!(usage.cost_source, crate::agent::cost::CostSource::Unknown);
+ assert_eq!(usage.cost_source, tinyagents_harness::cost::CostSource::Unknown);
assert_eq!(usage.cost().usd(), None);
assert_eq!(serde_json::to_value(usage).unwrap(), raw);
- usage.cost_source = crate::agent::cost::CostSource::Charged;
+ usage.cost_source = tinyagents_harness::cost::CostSource::Charged;
let charged = serde_json::to_value(usage).unwrap();
assert_eq!(charged["cost_source"], "charged");
assert_eq!(
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 3b6106e630..a75c2a3db6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -92,7 +92,7 @@ pub struct LastTurnUsage {
pub cost_usd: Option<f64>,
/// Whether `cost_usd` is entirely provider-charged or includes a catalog
/// estimate (`Unknown` exactly when `cost_usd` is `None`).
- pub cost_source: crate::agent::cost::CostSource,
+ pub cost_source: tinyagents_harness::cost::CostSource,
pub context_window: u64,
/// Tokens the root agent's context held after the turn's final model call
/// (that call's input plus its reply): the numerator of the context-window
@@ -121,7 +121,7 @@ pub(crate) struct SessionTurnSidecar {
pub cached_input_tokens: u64,
/// The turn's own cost (sub-agents excluded): every call's reported
/// charge, else catalog estimate, else unknown.
- pub cost: crate::agent::cost::CostTally,
+ pub cost: tinyagents_harness::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.
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index f88d0312df..d7760d36bc 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -170,7 +170,7 @@ fn child_ledgers_are_isolated_and_parent_keeps_completed_child_totals() {
output_tokens: 2,
cached_input_tokens: 1,
charged_amount_usd: 0.01,
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
},
});
assert!(right.subagent_usage_entries().is_empty());
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
index a4a55b8d14..c29df051b0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -99,7 +99,7 @@ pub(crate) struct TranscriptSnapshot {
/// Cost of the model calls the provider answered: each call's reported
/// charge, else its catalog estimate, else unknown (see
/// [`crate::agent::cost::call_cost`]).
- pub(crate) cost: crate::agent::cost::CostTally,
+ pub(crate) cost: tinyagents_harness::cost::CostTally,
/// The last accepted model route. A failed follow-up has no response of
/// its own, so this remains the route that incurred the snapshot usage.
pub(crate) resolved_route: Option<ResolvedModelRoute>,
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
index 2b094e43a8..b41c7e68cc 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
@@ -22,7 +22,7 @@ pub(super) struct BridgeState {
pub(super) output_tokens: u64,
pub(super) cached_input_tokens: u64,
/// Every call's cost: reported charge, catalog estimate, or unknown.
- pub(super) cost: crate::agent::cost::CostTally,
+ pub(super) cost: tinyagents_harness::cost::CostTally,
/// Local response-cache hits observed on this turn (issue #4249, 03.2). A hit
/// means the harness served a model call from its [`ResponseCache`] without
/// invoking the provider. Additive counters — a follow-up (coordinated with
@@ -223,7 +223,7 @@ impl OpenhumanEventBridge {
/// Cumulative `(input_tokens, output_tokens, cached_input_tokens, cost)`
/// observed so far — the full accounting the turn persists (transcript cost /
/// session meters). `cost` says whether every call was priced.
- pub(crate) fn totals_with_cost(&self) -> (u64, u64, u64, crate::agent::cost::CostTally) {
+ pub(crate) fn totals_with_cost(&self) -> (u64, u64, u64, tinyagents_harness::cost::CostTally) {
let s = self.state.lock().unwrap();
(
s.input_tokens,
@@ -309,10 +309,10 @@ impl OpenhumanEventBridge {
.map(|u| u.charged_amount_usd)
.filter(|c| c.is_finite() && *c >= 0.0);
let cost = match provider_cost {
- Some(charged) => crate::agent::cost::CallCost::Charged(charged),
+ Some(charged) => tinyagents_harness::cost::CallCost::Charged(charged),
None => match Self::estimate_call_cost(&self.model, usage) {
- Some(estimate) => crate::agent::cost::CallCost::Estimated(estimate),
- None => crate::agent::cost::CallCost::Unknown,
+ Some(estimate) => tinyagents_harness::cost::CallCost::Estimated(estimate),
+ None => tinyagents_harness::cost::CallCost::Unknown,
},
};
let call_cost = cost.usd();
@@ -382,9 +382,9 @@ impl OpenhumanEventBridge {
.with_cache_creation_tokens(cache_creation_tokens)
.with_reasoning_tokens(reasoning_tokens);
let usage_info = match cost {
- crate::agent::cost::CallCost::Charged(usd) => usage_info.with_charged_usd(usd),
- crate::agent::cost::CallCost::Estimated(usd) => usage_info.with_estimated_usd(usd),
- crate::agent::cost::CallCost::Unknown => usage_info,
+ tinyagents_harness::cost::CallCost::Charged(usd) => usage_info.with_charged_usd(usd),
+ tinyagents_harness::cost::CallCost::Estimated(usd) => usage_info.with_estimated_usd(usd),
+ tinyagents_harness::cost::CallCost::Unknown => usage_info,
};
if reasoning_tokens > 0 || cache_creation_tokens > 0 {
log::debug!(
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
index e0909e8022..9e8a540bbf 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
@@ -35,7 +35,7 @@ pub(crate) struct TinyagentsTurnOutcome {
pub cached_input_tokens: u64,
/// 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,
+ pub cost: tinyagents_harness::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`.
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 fac9f90f72..074df2eaa0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -120,10 +120,10 @@ pub(super) async fn finalize_turn_outcome(
crate::agent::tinyagents::turn_outcome::record_unobserved_turn_usage(
model, input, output, cached, estimate,
);
- let mut cost = crate::agent::cost::CostTally::default();
+ let mut cost = tinyagents_harness::cost::CostTally::default();
cost.add(match estimate {
- Some(usd) => crate::agent::cost::CallCost::Estimated(usd),
- None => crate::agent::cost::CallCost::Unknown,
+ Some(usd) => tinyagents_harness::cost::CallCost::Estimated(usd),
+ None => tinyagents_harness::cost::CallCost::Unknown,
});
(input, output, cached, cost)
});
diff --git a/crates/openhuman-core/src/agent/turn_projection.rs b/crates/openhuman-core/src/agent/turn_projection.rs
index 61d96f0e7f..44c674079f 100644
--- a/crates/openhuman-core/src/agent/turn_projection.rs
+++ b/crates/openhuman-core/src/agent/turn_projection.rs
@@ -5,7 +5,7 @@
//! mapping of a stop note without a failure class to its stop-reason key
//! ([`StopReasonKind`](crate::agent::session_host::stop_summary::StopReasonKind)).
-use crate::agent::cost::CostSource;
+use tinyagents_harness::cost::CostSource;
use crate::agent::tinyagents::host::LastTurnUsage;
use tinyagents_harness::middleware::ResponseUsage;
use tinyagents_harness::turn_stop::TurnStop;
diff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model_stream_tests.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model_stream_tests.rs
index c93b5f04d6..e25340ea1a 100644
--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model_stream_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model_stream_tests.rs
@@ -269,7 +269,7 @@ async fn managed_stream_carries_the_backend_charge_to_the_cost_accounting() {
assert_eq!(billed.cached_input_tokens(), 800);
assert_eq!(
crate::agent::cost::call_cost("openrouter/z-ai/glm-5.3-flash", &billed),
- crate::agent::cost::CallCost::Charged(0.0000634)
+ tinyagents_harness::cost::CallCost::Charged(0.0000634)
);
}
@@ -286,7 +286,7 @@ async fn managed_stream_keeps_a_zero_charge_as_known() {
.expect("usage reported");
assert_eq!(
crate::agent::cost::call_cost("openrouter/z-ai/glm-5.3-flash", &billed),
- crate::agent::cost::CallCost::Charged(0.0)
+ tinyagents_harness::cost::CallCost::Charged(0.0)
);
}
@@ -304,6 +304,6 @@ async fn managed_stream_without_a_billing_frame_has_no_charge() {
assert!(!billed.charge_reported);
assert_eq!(
crate::agent::cost::call_cost("openrouter/z-ai/glm-5.3-flash", &billed),
- crate::agent::cost::CallCost::Unknown
+ tinyagents_harness::cost::CallCost::Unknown
);
}
diff --git a/crates/openhuman-core/src/threads/ops/usage.rs b/crates/openhuman-core/src/threads/ops/usage.rs
index 36876f1056..514dbaccec 100644
--- a/crates/openhuman-core/src/threads/ops/usage.rs
+++ b/crates/openhuman-core/src/threads/ops/usage.rs
@@ -24,7 +24,7 @@ pub struct ThreadTokenUsageResponse {
/// recorded charge and no catalogued price). Never a guessed rate.
pub cost_usd: Option<f64>,
/// `charged`, `estimated` (some turn priced from list rates) or `unknown`.
- pub cost_source: crate::agent::cost::CostSource,
+ pub cost_source: tinyagents_harness::cost::CostSource,
pub turn_count: usize,
/// Spend of the most recent turn, the orchestrator's own: every model call
/// of that turn summed, so a long tool loop reports many times its context.
@@ -162,7 +162,7 @@ fn empty_response(thread_id: &str) -> ThreadTokenUsageResponse {
output_tokens: 0,
cached_input_tokens: 0,
cost_usd: Some(0.0),
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
turn_count: 0,
last_turn_input_tokens: 0,
last_turn_output_tokens: 0,
@@ -185,8 +185,8 @@ fn empty_response(thread_id: &str) -> ThreadTokenUsageResponse {
fn recorded_cost(
split: &tinyagents_session::transcript::spend::CostSplit,
model: Option<&str>,
-) -> crate::agent::cost::CostTally {
- use crate::agent::cost::{CallCost, CostSource, CostTally};
+) -> tinyagents_harness::cost::CostTally {
+ use tinyagents_harness::cost::{CallCost, CostSource, CostTally};
use tinyagents_session::transcript::UsageCostSource;
let mut cost = CostTally {
diff --git a/crates/openhuman-core/src/threads/ops/usage_tests.rs b/crates/openhuman-core/src/threads/ops/usage_tests.rs
index db26a32d1f..1024ff8ce6 100644
--- a/crates/openhuman-core/src/threads/ops/usage_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/usage_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::agent::cost::CostSource;
+use tinyagents_harness::cost::CostSource;
use tinyagents_session::transcript::spend::CostSplit;
use tinyagents_session::transcript::UsageCostSource;
diff --git a/crates/openhuman-core/src/web_chat/channel_event.rs b/crates/openhuman-core/src/web_chat/channel_event.rs
index 7dc076bd54..fae67f1607 100644
--- a/crates/openhuman-core/src/web_chat/channel_event.rs
+++ b/crates/openhuman-core/src/web_chat/channel_event.rs
@@ -351,7 +351,7 @@ pub struct TurnUsagePayload {
/// `charged` (every call billed by the provider), `estimated` (some call
/// priced from list rates) or `unknown`.
#[serde(default)]
- pub cost_source: crate::agent::cost::CostSource,
+ pub cost_source: tinyagents_harness::cost::CostSource,
pub context_window: u64,
/// Tokens the parent's context held after the turn's final model call: the
/// context gauge's numerator. Unlike the totals above it is one request,
diff --git a/crates/openhuman-core/src/web_chat/presentation_tests.rs b/crates/openhuman-core/src/web_chat/presentation_tests.rs
index b6bb6172c8..4e25164218 100644
--- a/crates/openhuman-core/src/web_chat/presentation_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_tests.rs
@@ -47,7 +47,7 @@ async fn chat_done_carries_timing_when_a_snapshot_is_supplied() {
output_tokens: 40,
cached_input_tokens: 0,
cost_usd: Some(0.01),
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
context_window: 8000,
context_tokens: 60,
subagents: Vec::new(),
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index 811fefc7d5..27a5389b57 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -1141,7 +1141,7 @@ pub(crate) fn spawn_progress_bridge(
// the turn's final figure (or `null`)
// arrives on `chat_done`.
cost_usd: Some(total_usd),
- cost_source: crate::agent::cost::CostSource::Charged,
+ cost_source: tinyagents_harness::cost::CostSource::Charged,
context_window: 0,
context_tokens: 0,
subagents: Vec::new(),