pub trait BudgetGuard: Send + Sync {
// Provided methods
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 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 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 { ... }
}Expand description
Host-supplied budget / quota contract.
Implementations are typically wired up by a cluster control plane
to enforce cross-session, cross-tenant cost limits. The framework
itself ships only the no-op NoopBudgetGuard.
All trait methods default to Allow / no-op so impls only need to
override what they actually want to govern.
Provided Methods§
Sourcefn 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.
estimated_prompt_tokens is a best-effort framework estimate
from the message history at call time; impls that want precise
accounting should use record_after_llm
instead of trusting the estimate.
Sourcefn 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.
Failed LLM calls do not invoke this hook.
Sourcefn 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".