pub struct Budget {
pub max_steps: Option<u32>,
pub max_usd: Option<f64>,
pub max_tokens: Option<u64>,
pub min_output_tokens: Option<u32>,
}Expand description
Hard limits enforced by the runtime before every model call.
Fields§
§max_steps: Option<u32>Maximum number of model calls.
max_usd: Option<f64>Maximum spend in USD. Every model the agent may call must have
pricing, otherwise crate::AgentBuilder::build refuses the agent.
max_tokens: Option<u64>Maximum input + output tokens.
min_output_tokens: Option<u32>Stop instead of calling the model when the remaining budget allows fewer output tokens than this. Defaults to 1.
Implementations§
Source§impl Budget
impl Budget
pub fn max_steps(self, n: u32) -> Self
pub fn max_usd(self, usd: f64) -> Self
pub fn max_tokens(self, n: u64) -> Self
pub fn min_output_tokens(self, n: u32) -> Self
Sourcepub fn output_cap(
&self,
configured: u32,
used_tokens: u64,
spent_usd: f64,
est_input_tokens: u64,
call_cost: impl Fn(u64, u64) -> Option<f64>,
) -> Result<u32, String>
pub fn output_cap( &self, configured: u32, used_tokens: u64, spent_usd: f64, est_input_tokens: u64, call_cost: impl Fn(u64, u64) -> Option<f64>, ) -> Result<u32, String>
Largest output-token limit for the next call that keeps the run within budget, given an estimate of the call’s input tokens.
call_cost(input, output) is the model’s worst-case USD for a call
(see crate::Model::max_call_cost). Returns Err(reason) when the
remaining budget cannot pay for min_output_tokens.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Budget
impl<'de> Deserialize<'de> for Budget
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
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
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