pub struct WorkflowBudget { /* private fields */ }Expand description
A shared, workflow-scoped token ledger that also acts as a BudgetGuard.
Implementations§
Source§impl WorkflowBudget
impl WorkflowBudget
Sourcepub fn new(limit_tokens: Option<u64>) -> Self
pub fn new(limit_tokens: Option<u64>) -> Self
A ledger with an optional hard token ceiling and no inner guard.
Sourcepub fn with_inner(self, inner: Arc<dyn BudgetGuard>) -> Self
pub fn with_inner(self, inner: Arc<dyn BudgetGuard>) -> Self
Delegate check/record to inner in addition to maintaining the
shared ledger — lets a host’s existing per-tenant guard keep working
while the workflow gets its aggregate cap.
Sourcepub fn consumed_tokens(&self) -> u64
pub fn consumed_tokens(&self) -> u64
Total tokens recorded so far.
Sourcepub fn snapshot(&self) -> BudgetSnapshot
pub fn snapshot(&self) -> BudgetSnapshot
A point-in-time view of the ledger.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether the configured cap has been reached.
Trait Implementations§
Source§impl BudgetGuard for WorkflowBudget
impl BudgetGuard for WorkflowBudget
Source§fn check_before_llm<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
estimated_prompt_tokens: usize,
) -> Pin<Box<dyn Future<Output = BudgetDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check_before_llm<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
estimated_prompt_tokens: usize,
) -> Pin<Box<dyn Future<Output = BudgetDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called immediately before an LLM API call. Read more
Source§fn record_after_llm<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
usage: &'life2 TokenUsage,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn record_after_llm<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
usage: &'life2 TokenUsage,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called after every successful LLM call with the actual usage
reported by the provider. Lets the impl keep its running spend
total in sync with reality. Read more
Source§fn check_before_tool<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
tool_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = BudgetDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn check_before_tool<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
tool_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = BudgetDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called immediately before a tool invocation. The framework does
not pass tool arguments — impls that need argument-aware caps
must wrap the executor via a custom
ToolExecutor.Auto Trait Implementations§
impl !Freeze for WorkflowBudget
impl !RefUnwindSafe for WorkflowBudget
impl !UnwindSafe for WorkflowBudget
impl Send for WorkflowBudget
impl Sync for WorkflowBudget
impl Unpin for WorkflowBudget
impl UnsafeUnpin for WorkflowBudget
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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