pub struct ContextTracker { /* private fields */ }Expand description
The size series for one conversation. In memory only; nothing is stored.
Implementations§
Source§impl ContextTracker
impl ContextTracker
pub fn new() -> ContextTracker
Sourcepub fn carry_into(&mut self, surface: u64)
pub fn carry_into(&mut self, surface: u64)
Carry the series into a new run, or start clean if the request shape changed underneath it.
The series lives on the Conversation rather than on the run, for the
reason taint does: it is a fact about the messages, and bundling it with
them makes the right thing the default. It matters because in mecha chat and the TUI one submission is one run — so a per-run tracker
started empty on every user turn, and the first request of each turn
went out unpredicted however heavy the transcript was.
The reset is the other half. An anchor is a measurement under one
model, one system prompt and one tool surface; /model replaces all
three and would leave the next prediction extrapolating from a
tokenizer that is no longer answering. Discarding is the only safe
response — there is nothing to convert it to — and it costs one
unpredicted turn, which is exactly what every run cost before.
Not fixed by this: a session resumed from disk starts unanchored, because a transcript records what runs cost in total and never what the last request weighed. It predicts from its second turn on.
Sourcepub fn observe(&mut self, tokens: u64, bytes: usize)
pub fn observe(&mut self, tokens: u64, bytes: usize)
Record what the provider charged for a list of a known size.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
The transcript was rewritten under the last reading, so it is no longer a reading of it. See the module docs — this is the one thing here that can move a decision later, and it does so by discarding a number about a message list that no longer exists rather than by overriding a live one.
Sourcepub fn reported(&self) -> Option<u64>
pub fn reported(&self) -> Option<u64>
The last measured prompt size, or None when there is not one that
describes the current transcript.
Sourcepub fn peak_tokens(&self) -> u64
pub fn peak_tokens(&self) -> u64
The largest prompt this run ever actually sent. A measurement throughout — never a prediction — because it is recorded, and a recorded estimate is indistinguishable from a recorded fact later.
Sourcepub fn predict(&self, bytes: usize) -> Option<u64>
pub fn predict(&self, bytes: usize) -> Option<u64>
What a request carrying bytes of messages would cost.
None before the first response: with no anchor there is no
measurement to extrapolate from, and a guess made entirely of constants
would be a tuned parameter wearing a prediction’s clothes.
Sourcepub fn over(&self, limit: u64, bytes: usize) -> bool
pub fn over(&self, limit: u64, bytes: usize) -> bool
Is a transcript of this size due a compaction?
reported || predicted, in that order and never the prediction alone.
That spelling is the monotonicity guarantee in one line: whatever this
type believes, it can only ever add a reason to compact.
Sourcepub fn affordable_output_bytes(
&self,
limit: u64,
current_bytes: usize,
) -> Option<usize>
pub fn affordable_output_bytes( &self, limit: u64, current_bytes: usize, ) -> Option<usize>
How many bytes of tool output the next turn can take before the
transcript crosses limit.
The other half of §4.4’s cliff-to-gradient: the compaction threshold
decides when to summarise, and this decides how much a single turn is
allowed to add in the first place. They serve one constraint —
resolved_output_budget’s docstring already states it — that “one
turn’s results must not leap the gap between the threshold and the
window itself”. That budget sizes the gap from the window, once, at
startup. This sizes it from where the transcript actually is.
Converted at the measured rate rather than the floor, which is the conservative direction: a higher rate buys fewer bytes.
None before the first response, where there is no anchor and so no
claim worth making.
Sourcepub fn forecast(&self, limit: u64, current_bytes: usize) -> Option<Forecast>
pub fn forecast(&self, limit: u64, current_bytes: usize) -> Option<Forecast>
What the model is shown when it looks at its plan.
None before the first response — with no anchor there is no reading,
and inventing one would put a guess where the whole point is that every
number is measured.
The pace is the mean growth across the recent window, not the last turn’s: a run alternates cheap turns and expensive ones, and the model is deciding between plan steps, which is exactly where one turn is least representative of the next.
Trait Implementations§
Source§impl Clone for ContextTracker
impl Clone for ContextTracker
Source§fn clone(&self) -> ContextTracker
fn clone(&self) -> ContextTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more