Expand description
Token estimates (RFC 0026 §5.2, §7). 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_windowoverrides). - 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).