pub struct TransformContext<'a> {
pub signal: &'a CancellationToken,
pub model_id: &'a str,
pub iteration: usize,
pub last_provider_usage: Option<&'a Usage>,
pub estimator: &'a dyn TokenEstimator,
}Expand description
Read-only context handed to a ContextTransform hook.
Carries the cancellation signal plus a few cheap observables that transforms key on (model identity, iteration index, last-turn token usage, the loop’s configured token estimator). Gathering these on the hook context — rather than widening the trait one parameter at a time — keeps the trait stable as later compaction layers (per-tool-result cap, cache-aware microcompact, auto-compact) come online.
New fields are additive: transforms that don’t care can ignore them.
Fields§
§signal: &'a CancellationTokenCancellation signal for the current run.
model_id: &'a strModel identifier the run is targeting (e.g. provider/model). May be empty when the host runtime doesn’t surface one — tests, fixture-replay transports, etc. Plugins that key per-model behavior should treat empty as “unknown”.
iteration: usizeZero-indexed iteration within the current run. Same semantics as
ToolGateContext::iteration: the very first LLM call of the
run is 0.
last_provider_usage: Option<&'a Usage>Token usage reported by the provider on the most recent assistant
turn that surfaced a Usage block. None on the very first turn
or when the provider didn’t surface usage. Useful for
cache-aware decisions (read cache_read_input_tokens to see if
the prompt prefix actually hit cache last turn).
estimator: &'a dyn TokenEstimatorEstimator the loop is configured with. Plugins use this to count tokens for budgeting and compaction without duplicating the loop’s tokenizer choice.
Implementations§
Source§impl<'a> TransformContext<'a>
impl<'a> TransformContext<'a>
Sourcepub fn for_test(signal: &'a CancellationToken) -> Self
pub fn for_test(signal: &'a CancellationToken) -> Self
Convenience constructor for tests and ad-hoc callers that don’t have a model id, iteration counter, or usage data. Picks the default char-heuristic estimator.