Skip to main content

Module tokens

Module tokens 

Source
Expand description

Token estimates. agentd never counts provider tokens itself — the provider’s usage is the truth once a call returns — but the governor’s reservation and the compaction trigger need a number before the call. The heuristic is the usual chars / 4 (English prose ≈ 4 chars a token; JSON and code run denser, which errs on the safe side for a reservation) plus a small per-message overhead. Deliberately simple and dependency-free; the estimate is only ever compared against generous thresholds.

Constants§

DEFAULT_MODEL_WINDOW
The default context window when the model is unknown (a conservative modern default; intelligence.model_window overrides).
MESSAGE_OVERHEAD
Per-message framing overhead (role, delimiters).

Functions§

estimate
Estimate the tokens of a text.
estimate_value
Estimate the tokens of a JSON value (its compact serialization).
window_for_model
A best-effort window from the model name (kept tiny and obviously approximate; unknown models get the default).