symfonic.capabilities.prompting.budget¶
budget ¶
Deterministic, offline token budgeting and admission.
Two properties matter more than accuracy here. Offline: the default estimator is arithmetic over the string, so a cold container with no network and no tokenizer cache compiles the same prompt as a warm one โ a downloaded tokenizer would make prompt assembly fail on the machine least able to debug it. Deterministic: admission is a total order over the rows, so the same request always drops the same contributions, and a golden prompt corpus is possible at all.
Dropping runs most-volatile-first: a per-turn block is the cheapest thing to lose and the one most likely to be re-derivable next turn. Pinned rows are never dropped; when they alone exceed the budget the compile fails, because a prompt missing its boundaries is worse than a prompt that refused to build.
BudgetRow ¶
Bases: NamedTuple
One admission candidate: identity, position, cost, and pinned-ness.
HeuristicTokenEstimator
dataclass
¶
Characters-per-token arithmetic โ the offline default.
Deliberately an estimate with a name that says so. A provider-exact counter is a legitimate substitution (T3.2.2 owns that seam), but it must arrive as a bound port rather than as a network call this module makes, which is why the estimator is a protocol and this is only its default.
PromptBudget
dataclass
¶
The ceiling one compiled prompt runs under.
None means unbounded, which is the honest default: inventing a ceiling
the adopter did not ask for would silently truncate prompts that fit.
narrows ¶
True when this budget is the parent's or a strictly tighter one.
Source code in src/symfonic/capabilities/prompting/budget.py
TokenEstimator ¶
Bases: Protocol
Estimates the token cost of a rendered string.
admit_within_budget ¶
admit_within_budget(rows: Sequence[BudgetRow], budget: PromptBudget) -> tuple[tuple[BudgetRow, ...], BudgetReport]
Admit as much as the budget allows, dropping in a fixed, total order.
The returned rows keep their original (compiled) order; only membership is decided here. Reordering the prompt to fit would change what the model reads for reasons the adopter never declared.