Skip to main content

context_pcts

Function context_pcts 

Source
pub fn context_pcts(
    tokens: usize,
    context_window: usize,
) -> (Option<u8>, Option<u8>)
Expand description

Derive (working_context_pct, overhead_pct) from a raw token measurement against a model’s context window, mirroring cadence::CadenceOutcome::working_context_pct/overhead_pct’s own saturating arithmetic (never a divide-by-zero, never > 100).

Why: shared by both AgentLoop::maybe_compact_transcript (which has no CadenceOutcome to read these from) and callers that already have one, so the two call sites’ percentages can never drift apart from cadence’s own formula. What: (None, None) for a zero context_window (percentages are meaningless without a real window); otherwise overhead_pct = (tokens * 100 / context_window).min(100), working_context_pct = 100 - overhead_pct. Test: tests::context_pcts_zero_window_is_none, tests::context_pcts_matches_saturating_formula.