Struct ToolLoopCostTrackingContext
pub struct ToolLoopCostTrackingContext {
pub tracker: Option<Arc<CostTracker>>,
pub model_provider_pricing: Arc<ModelProviderPricing>,
pub turn_usage: Arc<Mutex<TurnUsage>>,
pub agent_alias: Option<String>,
}Expand description
Context for cost tracking within the tool call loop.
Scoped via tokio::task_local! at call sites (channels, gateway).
Fields§
§tracker: Option<Arc<CostTracker>>Shared cost tracker. None for usage-only contexts that accumulate
per-turn token totals without persisting cost records or enforcing
budgets (see Self::usage_only).
model_provider_pricing: Arc<ModelProviderPricing>§turn_usage: Arc<Mutex<TurnUsage>>Per-scope usage accumulator so wrapping code can read token/cost totals after the scoped future exits (without racing concurrent traffic sharing the same tracker).
agent_alias: Option<String>Alias of the agent driving this turn. Stamped onto persisted
CostRecords so /api/cost?agent=<alias> can attribute spend.
Implementations§
Source§impl ToolLoopCostTrackingContext
impl ToolLoopCostTrackingContext
pub fn new( tracker: Arc<CostTracker>, model_provider_pricing: Arc<ModelProviderPricing>, ) -> Self
pub fn usage_only() -> Self
Sourcepub fn with_agent_alias(self, agent_alias: impl Into<String>) -> Self
pub fn with_agent_alias(self, agent_alias: impl Into<String>) -> Self
Attach an agent alias to this context so subsequent
record_tool_loop_cost_usage calls stamp records with it.
pub fn snapshot_turn_usage(&self) -> TurnUsage
Trait Implementations§
Source§impl Clone for ToolLoopCostTrackingContext
impl Clone for ToolLoopCostTrackingContext
Source§fn clone(&self) -> ToolLoopCostTrackingContext
fn clone(&self) -> ToolLoopCostTrackingContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · §fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ToolLoopCostTrackingContext
impl !RefUnwindSafe for ToolLoopCostTrackingContext
impl Send for ToolLoopCostTrackingContext
impl Sync for ToolLoopCostTrackingContext
impl Unpin for ToolLoopCostTrackingContext
impl UnsafeUnpin for ToolLoopCostTrackingContext
impl !UnwindSafe for ToolLoopCostTrackingContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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