pub struct TurnBudgetMeter { /* private fields */ }Expand description
One turn’s running budget meter. NOT thread-shared: owned by the
stream loop; the only cross-task input is the UsageCounters cell.
Implementations§
Source§impl TurnBudgetMeter
impl TurnBudgetMeter
pub fn new(budget: TurnBudget) -> TurnBudgetMeter
pub fn budget(&self) -> &TurnBudget
Sourcepub fn begin_round(&mut self) -> Result<(), BudgetDimension>
pub fn begin_round(&mut self) -> Result<(), BudgetDimension>
Charge one provider round. Checked BEFORE the provider call: wall-clock first (a stale turn must not spend another request), then the exact round cap.
Sourcepub fn try_renew_rounds(&mut self) -> Option<u32>
pub fn try_renew_rounds(&mut self) -> Option<u32>
Attempt a bounded graceful extension after the provider-round cap is
hit. Resets the round counter and returns the number of renewals still
remaining, or None when the renewal budget is exhausted. Wall-clock
is deliberately untouched — Self::begin_round re-checks it, so a
stale turn cannot extend past max_elapsed. Only meaningful right
after begin_round returned BudgetDimension::ProviderRounds.
Sourcepub fn round_renewals_used(&self) -> u32
pub fn round_renewals_used(&self) -> u32
Number of graceful round renewals already consumed this turn.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Wall-clock consumed by this turn so far. Diagnostics only — the
enforcement path uses Self::wall_clock_exceeded.
Sourcepub fn exhaustion_error(&self, dimension: BudgetDimension) -> TurnError
pub fn exhaustion_error(&self, dimension: BudgetDimension) -> TurnError
Metadata-only diagnostic; preserve the typed outcome for every frontend and autonomous driver. Exhaustion is a local stop, not provider fallback.
Sourcepub fn rounds_used(&self) -> u32
pub fn rounds_used(&self) -> u32
Provider rounds charged since the last renewal (reset by
Self::try_renew_rounds). Diagnostics only.
Sourcepub fn tool_calls_used(&self) -> u32
pub fn tool_calls_used(&self) -> u32
Tool calls charged this turn. Diagnostics only.
Sourcepub fn tool_result_bytes_used(&self) -> usize
pub fn tool_result_bytes_used(&self) -> usize
Accumulated tool-result bytes charged this turn. Diagnostics only.
Sourcepub fn remaining_tool_calls(&self) -> u32
pub fn remaining_tool_calls(&self) -> u32
Remaining tool-call allowance (for exact-cap batch splitting).
Sourcepub fn charge_tool_calls(&mut self, n: u32)
pub fn charge_tool_calls(&mut self, n: u32)
Charge n executed tool calls (the caller split the batch against
Self::remaining_tool_calls, so this never over-charges).
Sourcepub fn charge_tool_result_bytes(
&mut self,
bytes: usize,
) -> Result<(), BudgetDimension>
pub fn charge_tool_result_bytes( &mut self, bytes: usize, ) -> Result<(), BudgetDimension>
Charge the bytes of one round’s tool results; exceeding the accumulated cap exhausts the ToolResultBytes dimension.
Sourcepub fn check_usage(&self, usage: &UsageCounters) -> Result<(), BudgetDimension>
pub fn check_usage(&self, usage: &UsageCounters) -> Result<(), BudgetDimension>
Optional dimensions, consulted after each provider round from the shared usage counters. Costs are summed per request, never repriced from token totals; both checks are no-ops when unconfigured.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TurnBudgetMeter
impl RefUnwindSafe for TurnBudgetMeter
impl Send for TurnBudgetMeter
impl Sync for TurnBudgetMeter
impl Unpin for TurnBudgetMeter
impl UnsafeUnpin for TurnBudgetMeter
impl UnwindSafe for TurnBudgetMeter
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> ⓘ
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> ⓘ
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