ContextWindowEstimator
AgentPrism.Core.dllEstimates a prompt’s token count and whether it would be rejected by the pre-flight context-window check, without calling a model provider.
public sealed class ContextWindowEstimatorInheritance
Section titled “Inheritance”object ← ContextWindowEstimator
Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The estimate is approximate: counting is done with a single
fixed OpenAI encoding
(o200k_base, via Tokenizers.TiktokenTokenizer) regardless of the
bound provider — Anthropic and Google publish no equivalent offline
tokenizer package. The count is close enough to size a prompt against a
context window; it is not the exact count any specific provider would bill.
The tokenizer is built ONCE and reused: constructing one loads the vocab data package’s contents, and doing that per call would make even a cheap estimate expensive.
Constructors
Section titled “Constructors”ContextWindowEstimator(IModelProviderRegistry, IOptionsMonitor<AgentPrismOptions>)
Section titled “ ContextWindowEstimator(IModelProviderRegistry, IOptionsMonitor<AgentPrismOptions>)”Creates a new estimator.
public ContextWindowEstimator(IModelProviderRegistry registry, IOptionsMonitor<AgentPrismOptions> optionsMonitor)Parameters
Section titled “Parameters”registry IModelProviderRegistry
The registry used to look up the model’s context window.
optionsMonitor IOptionsMonitor<AgentPrismOptions>
The runtime settings, for AgentPrismPreflightOptions.ReserveRatio.
Exceptions
Section titled “Exceptions”A dependency is null.
Methods
Section titled “Methods”Estimate(ModelBinding, string?)
Section titled “ Estimate(ModelBinding, string?)”Estimates prompt against binding’s context window.
public ContextWindowEstimate Estimate(ModelBinding binding, string? prompt)Parameters
Section titled “Parameters”binding ModelBinding
The model binding whose context window applies.
prompt string?
The prompt text to count. Empty when null.
Returns
Section titled “Returns”The estimate.
Exceptions
Section titled “Exceptions”binding is null.