pub enum BudgetSpec {
Absolute(usize),
Percent {
percent: f64,
min: Option<usize>,
max: Option<usize>,
},
}Expand description
How a region’s token ceiling is expressed before it is resolved against a concrete model context window.
Blueprint authors think in proportions (budget = "35%") so their intent
stays correct regardless of the model’s context size, while power users can
still pin an exact count. The percentage denominator - the model’s context
window - is not known at parse time, so the spec is stored unresolved here and
turned into a concrete token count at window-build time (see
BudgetSpec::resolve and ContextLayout::resolved).
Variants§
Absolute(usize)
A fixed token ceiling, independent of the model. Resolving is a no-op.
Percent
A ceiling expressed as a fraction of the model’s context window, with
optional absolute guard-rails. percent is a fraction (0.35 for
"35%"). max caps the resolved value (so e.g. 2% of a 1M window can’t
balloon a task region to 20K tokens); min floors it (so a small-context
model doesn’t starve the region below a usable size).
Implementations§
Source§impl BudgetSpec
impl BudgetSpec
Sourcepub fn parse_budget(s: &str) -> Result<f64, String>
pub fn parse_budget(s: &str) -> Result<f64, String>
Parse a percentage string like "35%" into its fraction (0.35).
Surrounding whitespace is trimmed and decimals are allowed ("0.6%").
Rejects a missing %, a non-numeric value, and anything outside the
(0, 100] range - a single region can’t sensibly claim ≤0% or more than
the whole window (region budgets may sum past 100%, but each is a
fraction of one window). Returns the human-readable reason on failure so
the caller can surface it at load time.
Sourcepub fn resolve(&self, window: usize) -> usize
pub fn resolve(&self, window: usize) -> usize
Resolve this spec to a concrete token count against a model context
window.
Absolute ignores the window (idempotent - a
fully-absolute layout resolves to itself). Percent
rounds window * percent, then applies the max cap, then the min
floor. The floor is applied last so that when min > max the floor
wins: a region starved below a usable size is worse than one slightly over
its cap.
Sourcepub fn is_percent(&self) -> bool
pub fn is_percent(&self) -> bool
Whether this is a percentage budget (needs a model window to resolve).
Trait Implementations§
Source§impl Clone for BudgetSpec
impl Clone for BudgetSpec
Source§fn clone(&self) -> BudgetSpec
fn clone(&self) -> BudgetSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BudgetSpec
impl Debug for BudgetSpec
Source§impl Default for BudgetSpec
impl Default for BudgetSpec
Source§fn default() -> Self
fn default() -> Self
Only a serde-deserialize fallback for older persisted blueprints; live
code always sets the budget explicitly via RegionDefinition::new.