pub struct ContextBudget { /* private fields */ }Expand description
Token budget for a single agent session.
Tracks the maximum token window and divides it across context slots.
Call ContextBudget::allocate or ContextBudget::allocate_with_opts to get a
BudgetAllocation that can be fed to crate::assembler::ContextAssembler.
Implementations§
Source§impl ContextBudget
impl ContextBudget
Sourcepub fn new(max_tokens: usize, reserve_ratio: f32) -> ContextBudget
pub fn new(max_tokens: usize, reserve_ratio: f32) -> ContextBudget
Create a new budget with max_tokens capacity and reserve_ratio fraction reserved
for the model response.
§Examples
use zeph_context::budget::ContextBudget;
let budget = ContextBudget::new(128_000, 0.15);
assert_eq!(budget.max_tokens(), 128_000);Sourcepub fn with_graph_enabled(self, enabled: bool) -> ContextBudget
pub fn with_graph_enabled(self, enabled: bool) -> ContextBudget
Enable or disable graph fact allocation in the budget split.
When enabled, 4% of available tokens are routed to the graph_facts slot, and the
summaries/semantic_recall slices are each reduced by 1%.
Sourcepub fn max_tokens(&self) -> usize
pub fn max_tokens(&self) -> usize
Maximum token capacity for this session.
Sourcepub fn allocate(
&self,
system_prompt: &str,
skills_prompt: &str,
tc: &TokenCounter,
graph_enabled: bool,
) -> BudgetAllocation
pub fn allocate( &self, system_prompt: &str, skills_prompt: &str, tc: &TokenCounter, graph_enabled: bool, ) -> BudgetAllocation
Allocate the budget across context slots for one turn.
Equivalent to allocate_with_opts(…, 0, false).
§Examples
use zeph_context::budget::ContextBudget;
use zeph_memory::TokenCounter;
let budget = ContextBudget::new(128_000, 0.15);
let tc = TokenCounter::new();
let alloc = budget.allocate("system prompt", "skills prompt", &tc, false);
assert!(alloc.recent_history > 0);Sourcepub fn allocate_with_opts(
&self,
system_prompt: &str,
skills_prompt: &str,
tc: &TokenCounter,
graph_enabled: bool,
digest_tokens: usize,
memory_first: bool,
) -> BudgetAllocation
pub fn allocate_with_opts( &self, system_prompt: &str, skills_prompt: &str, tc: &TokenCounter, graph_enabled: bool, digest_tokens: usize, memory_first: bool, ) -> BudgetAllocation
Allocate context budget with optional digest pre-reservation and MemoryFirst mode.
digest_tokens — pre-counted tokens for the session digest block; deducted from
available tokens BEFORE percentage splits so it does not silently crowd out other slots.
memory_first — when true, sets recent_history to 0 and redistributes those
tokens across summaries, semantic_recall, and cross_session.
Trait Implementations§
Source§impl Clone for ContextBudget
impl Clone for ContextBudget
Source§fn clone(&self) -> ContextBudget
fn clone(&self) -> ContextBudget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ContextBudget
impl RefUnwindSafe for ContextBudget
impl Send for ContextBudget
impl Sync for ContextBudget
impl Unpin for ContextBudget
impl UnsafeUnpin for ContextBudget
impl UnwindSafe for ContextBudget
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request