pub struct TokenBudgetConfig {
pub work_budget: usize,
pub reminder_threshold: usize,
pub reminder_template: String,
pub fallback_prompt: String,
pub fallback_buffer: usize,
pub guidance_message: String,
pub seed_message: String,
pub min_work_multiple: f64,
pub min_absolute_work_room: usize,
pub user_trail_max_tokens: usize,
}Expand description
Configuration for the token-budget window strategy.
Work-room semantics: work_budget is the conversation space ABOVE
the window’s fixed base (system prompt + per-window boilerplate), not the
total window size. The reset point is base + work_budget + buffer, so
any positive budget produces a window that fits — the “budget below
system-prompt overhead” failure class is structurally impossible. Use
TokenBudgetConfig::with_work_budget to keep the reminder/buffer
thresholds proportional when overriding the default.
Fields§
§work_budget: usizeWork-room budget: tokens of conversation space above the fixed window base. Corresponds to “how much room the model has to work with” — the base is added by the framework.
reminder_threshold: usizeReminder threshold: inject the reminder when remaining work room ≤ this value.
reminder_template: StringReminder message template. {n_remaining} is replaced with estimated
remaining work-room tokens.
fallback_prompt: StringFallback prompt injected when the work budget is exhausted (window about to reset).
fallback_buffer: usizeExtra work-room overshoot tolerated past work_budget before the
reset fires. Allows the model one more turn to save state after
the fallback.
guidance_message: StringGuidance message injected once per window start (explains the private context-management tools).
seed_message: StringUser seed message injected as the LAST message of every new window.
Satisfies the engine’s compaction-output contract (at least one
non-System message — System maps to the top-level system parameter,
and an all-System window is an HTTP 400) and gives the model a turn
to reconstruct state.
min_work_multiple: f64Minimum viable work budget as a multiple of the base overhead.
Below this no single turn of work fits in the room (one tool result
overflows it) and the session thrashes. Construction clamps the
work budget up to max(min_work_multiple × base, min_absolute_work_room) and scales the reminder/buffer bands to
match.
min_absolute_work_room: usizeAbsolute floor for the work room, independent of base size. Tool results don’t shrink with the system prompt — an app with a tiny prompt still needs room for real tool output, so the viability floor is whichever is larger: the proportional bound or this constant.
user_trail_max_tokens: usizeToken cap for the mechanical user-message trail carried into a fresh
window. User messages are the task trail — facts, not model output —
so they are re-injected verbatim (newest-first under this cap, oldest
truncated) instead of asking the model to recover them from history
(cf. codex build_compacted_history).
Implementations§
Source§impl TokenBudgetConfig
impl TokenBudgetConfig
Sourcepub fn with_work_budget(work_budget: usize) -> TokenBudgetConfig
pub fn with_work_budget(work_budget: usize) -> TokenBudgetConfig
Config with proportional reminder/buffer thresholds for a custom
work budget (reminder = 20%, buffer = 10% of work_budget).
Sourcepub fn hard_limit(&self, base_overhead: usize) -> usize
pub fn hard_limit(&self, base_overhead: usize) -> usize
Hard reset threshold in absolute estimated tokens:
base_overhead + work_budget + fallback_buffer.
Trait Implementations§
Source§impl Clone for TokenBudgetConfig
impl Clone for TokenBudgetConfig
Source§fn clone(&self) -> TokenBudgetConfig
fn clone(&self) -> TokenBudgetConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more