/** * Reducing what the model WRITES, not what it reads. * * Every other engine in this package attacks the prompt. Output is the token * class nobody here has touched, and on Opus-class models it bills at about * five times input -- so a modest reduction there is worth more than a large * one on the cheap side of the ledger. Much of that output is ceremony: * "Great, let me...", code printed straight back at you, and full reasoning * effort spent resuming after a file read that answered nothing. * * TWO LEVERS, BOTH DELIBERATELY TIMID. * * 1. VERBOSITY STEERING appends a short instruction to the END of the system * prompt. The end matters: a provider prompt cache keys on a prefix, so * anything prepended or inserted invalidates every cached token behind it. * This package has already measured that mistake costing 1.77x when a * reordered tool array moved bytes at the front of the prefix, so the * placement here is not stylistic. * * 2. EFFORT ROUTING lowers the thinking budget when a turn is only the model * resuming after a tool result -- a file read, a passing test. A new * question or an error keeps whatever the client asked for. * * CLAMP-ONLY, IN ONE DIRECTION. Neither lever ever raises a setting the client * chose, adds a field the client omitted, or changes a request it marked as * needing full effort. A proxy that increases spend while advertising a saving * is worse than a proxy that does nothing, so every branch here can only * reduce or pass through. * * MEASURED, NOT ESTIMATED. Output savings are counterfactual: we never see what * the model would have written. So a holdout fraction of conversations is left * unshaped, which turns the figure from an estimate into a measurement with a * band. `TOKEN_OPTIMIZER_OUTPUT_HOLDOUT=0.1` leaves one in ten alone. */ export type WireFormat = 'messages' | 'chat-completions' | 'responses'; export interface ShaperOptions { readonly wireFormat: WireFormat; /** Off unless the operator turned it on. */ readonly enabled?: boolean; /** Fraction of conversations left unshaped, so the saving can be measured. */ readonly holdout?: number; /** Stable per-conversation key, so a conversation stays in or out of the holdout. */ readonly conversationKey?: string; } export interface ShaperResult { /** The request to forward. Identical object when nothing applied. */ readonly body: Record; /** Labels for the accounting ledger, e.g. `output_shaper:verbosity`. */ readonly labels: readonly string[]; /** Why nothing was done, when nothing was done. */ readonly skipped?: string; } /** Reads the switch. Absent means off: this changes what the model writes. */ export declare function shaperEnabled(env?: NodeJS.ProcessEnv): boolean; /** The unshaped fraction. Invalid or absent means none. */ export declare function holdoutFraction(env?: NodeJS.ProcessEnv): number; /** * Whether this conversation is in the unshaped control arm. * * Hashed rather than random, so a conversation does not flip arms mid-flight. * A conversation shaped on turn 3 and unshaped on turn 4 would pollute both * arms and measure nothing. */ export declare function inHoldout(key: string | undefined, fraction: number): boolean; /** Is this turn only the model resuming after a tool result? */ export declare function isResumption(body: Record, wireFormat: WireFormat): boolean; /** * Applies both levers, or explains why it did not. * * The body is never mutated in place: a caller that decides not to forward the * shaped version must still hold the original bytes. */ export declare function shapeOutput(body: Record, opts: ShaperOptions): ShaperResult; //# sourceMappingURL=output-shaper.d.ts.map