refactor(flags): migrate output token max to runtime flags (#27680)

This commit is contained in:
Shoubhit Dash
2026-05-15 13:07:35 +05:30
committed by GitHub
parent 2080390ca6
commit 2d6bedecd4
7 changed files with 52 additions and 18 deletions

View File

@@ -228,7 +228,12 @@ export const layer = Layer.effect(
tokens: MessageV2.Assistant["tokens"]
model: Provider.Model
}) {
return overflow({ cfg: yield* config.get(), tokens: input.tokens, model: input.model })
return overflow({
cfg: yield* config.get(),
tokens: input.tokens,
model: input.model,
outputTokenMax: flags.outputTokenMax,
})
})
const estimate = Effect.fn("SessionCompaction.estimate")(function* (input: {

View File

@@ -173,7 +173,7 @@ const live: Layer.Layer<
: undefined,
topP: input.agent.topP ?? ProviderTransform.topP(input.model),
topK: ProviderTransform.topK(input.model),
maxOutputTokens: ProviderTransform.maxOutputTokens(input.model),
maxOutputTokens: ProviderTransform.maxOutputTokens(input.model, flags.outputTokenMax),
options,
},
)

View File

@@ -5,18 +5,24 @@ import type { MessageV2 } from "./message-v2"
const COMPACTION_BUFFER = 20_000
export function usable(input: { cfg: Config.Info; model: Provider.Model }) {
export function usable(input: { cfg: Config.Info; model: Provider.Model; outputTokenMax?: number }) {
const context = input.model.limit.context
if (context === 0) return 0
const reserved =
input.cfg.compaction?.reserved ?? Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
input.cfg.compaction?.reserved ??
Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
return input.model.limit.input
? Math.max(0, input.model.limit.input - reserved)
: Math.max(0, context - ProviderTransform.maxOutputTokens(input.model))
: Math.max(0, context - ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
}
export function isOverflow(input: { cfg: Config.Info; tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
export function isOverflow(input: {
cfg: Config.Info
tokens: MessageV2.Assistant["tokens"]
model: Provider.Model
outputTokenMax?: number
}) {
if (input.cfg.compaction?.auto === false) return false
if (input.model.limit.context === 0) return false