pub struct BudgetState {
pub total_input_tokens: u64,
pub total_output_tokens: u64,
pub total_cost_usd: f64,
pub iteration_count: u32,
pub tool_call_count: u32,
pub consecutive_error_count: u32,
pub circuit_breaker_tripped: bool,
}Expand description
Accumulated runtime budget for a single workflow execution.
Embedded in Snapshot.state under "__budget". Updated after every
NodeCompleted event that carries token / cost telemetry.
Fields§
§total_input_tokens: u64§total_output_tokens: u64§total_cost_usd: f64§iteration_count: u32Number of agent reasoning iterations across all agent nodes.
tool_call_count: u32Number of tool calls across all nodes.
consecutive_error_count: u32Consecutive error count for circuit-breaker logic.
circuit_breaker_tripped: boolTrue once the circuit breaker has fired for this execution.
Implementations§
Source§impl BudgetState
impl BudgetState
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Total tokens (input + output).
Sourcepub fn from_snapshot_state(state: &Value) -> Self
pub fn from_snapshot_state(state: &Value) -> Self
Load BudgetState from the __budget key of a snapshot state value.
Sourcepub fn patch_into_snapshot_state(&self, state: &mut Value)
pub fn patch_into_snapshot_state(&self, state: &mut Value)
Merge this BudgetState back into the snapshot state JSON as __budget.
Sourcepub fn accumulate(
&mut self,
input_tokens: Option<u64>,
output_tokens: Option<u64>,
cost_usd: Option<f64>,
)
pub fn accumulate( &mut self, input_tokens: Option<u64>, output_tokens: Option<u64>, cost_usd: Option<f64>, )
Accumulate token / cost values from a completed model node.
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Record a successful node — resets the consecutive error counter.
Sourcepub fn record_error(&mut self)
pub fn record_error(&mut self)
Record a failed node — increments the consecutive error counter.
Trait Implementations§
Source§impl Clone for BudgetState
impl Clone for BudgetState
Source§fn clone(&self) -> BudgetState
fn clone(&self) -> BudgetState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BudgetState
impl Debug for BudgetState
Source§impl Default for BudgetState
impl Default for BudgetState
Source§fn default() -> BudgetState
fn default() -> BudgetState
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for BudgetState
impl<'de> Deserialize<'de> for BudgetState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for BudgetState
impl RefUnwindSafe for BudgetState
impl Send for BudgetState
impl Sync for BudgetState
impl Unpin for BudgetState
impl UnsafeUnpin for BudgetState
impl UnwindSafe for BudgetState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more