Skip to content

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

fix(web_chat): make turn cost optional and report its source

Steven Enamakel7b8a75831c57
diff --git a/crates/openhuman-core/src/agent/session_host/codec.rs b/crates/openhuman-core/src/agent/session_host/codec.rs
index 80f9cca607..4ee4f276af 100644
--- a/crates/openhuman-core/src/agent/session_host/codec.rs
+++ b/crates/openhuman-core/src/agent/session_host/codec.rs
@@ -9,6 +9,7 @@ use tinyagents_runtime::{RuntimeError, TranscriptCodec, TranscriptTurnOptions};
use tinyagents_session::transcript::view::TOOL_RESULT_FAILURES_METADATA_KEY;
use tinyagents_session::transcript::{
MessageUsage, SessionTranscript, ToolFailure, TranscriptMessage, TranscriptToolCall, TurnUsage,
+ UsageCostSource,
};
use tinyinference_llm::message::Message;
use tinytools_agent::dialect::parse_replayed_results;
diff --git a/crates/openhuman-core/src/web_chat/channel_event.rs b/crates/openhuman-core/src/web_chat/channel_event.rs
index be1c5a7c14..dce3129f5f 100644
--- a/crates/openhuman-core/src/web_chat/channel_event.rs
+++ b/crates/openhuman-core/src/web_chat/channel_event.rs
@@ -339,7 +339,13 @@ pub struct TurnUsagePayload {
pub input_tokens: u64,
pub output_tokens: u64,
pub cached_input_tokens: u64,
- pub cost_usd: f64,
+ /// The turn's cost, or `null` when it is not known (some call had no
+ /// reported charge and no catalogued price). The UI shows no price then.
+ pub cost_usd: Option<f64>,
+ /// `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 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,
@@ -360,7 +366,8 @@ pub struct SubagentUsagePayload {
pub agent_id: String,
pub input_tokens: u64,
pub output_tokens: u64,
- pub cost_usd: f64,
+ /// `null` when the child's cost is not known.
+ pub cost_usd: Option<f64>,
}
/// Per-event subagent progress detail attached to `WebChannelEvent`.