/** * Is deferring a tool's schema actually worth it? * * §6.3 said the threshold should be measurable rather than asserted, and until * now it was neither. The question turns out not to be "how many tokens do the * schemas cost" — `--print-token-surface` already answered that — but a * trade-off with a term nobody had priced: * * Deferring withholds D tokens of schema from every request. But those tokens * would have sat in the *cached* prefix, so what deferral saves per request is * D at the cache-read rate, not at full price — an order of magnitude less * than it looks. And the moment the model resolves a deferred tool, the * harness adds it to `tools`, which renders at position 0 and invalidates the * whole prefix P — so the next request pays P at the cache-*write* rate * instead of the cache-read rate it would otherwise have paid. * * Break-even is therefore the number of requests before the first resolve: * * N = P × (cacheWrite − cacheRead) / (D × cacheRead) * * The counterintuitive consequence is worth stating plainly: **P grows with the * conversation, D does not.** Deferral gets *worse* the longer a session runs, * which is the opposite of the intuition that motivated it. * * See docs/plugin-system-architecture.md §6.3 and §8.6 item 6. */ /** Per-million-token prices, as carried on a model. */ export interface TokenPrices { input: number; cacheRead: number; cacheWrite: number; } export interface DeferralInput { /** Tokens of schema that would be withheld (the deferrable tools). */ deferredTokens: number; /** * Tokens in the cached prefix a resolve would invalidate: system prompt plus * every tool schema, and in a live session the conversation too. Callers that * only know the startup surface are supplying a floor — see `prefixIsFloor`. */ prefixTokens: number; prices: TokenPrices; } export type DeferralVerdict = { kind: "no-cache"; reason: string; } | { kind: "nothing-deferred"; reason: string; } | { kind: "unpriced"; reason: string; } | { kind: "break-even"; requestsBeforeResolve: number; savingPerRequest: number; resolvePenalty: number; }; /** * Price the deferral trade-off for one model. * * Deliberately returns a discriminated verdict rather than a bare number: three * of the four outcomes mean "the break-even question does not apply here", and * collapsing them into a number would invite reading 0 or Infinity as an answer. */ export declare function analyzeDeferral(input: DeferralInput): DeferralVerdict; /** * Render the verdict for `--print-token-surface`. * * `prefixIsFloor` marks the common case where the caller measured the startup * surface only. The number is then a lower bound in the direction that matters: * the real prefix is larger, so the real break-even is higher and deferral looks * worse than printed, never better. */ export declare function formatDeferral(verdict: DeferralVerdict, options?: { prefixIsFloor?: boolean; }): string; //# sourceMappingURL=deferral.d.ts.map