fix(core): cap session output tokens
This commit is contained in:
parent
9976269ab1
commit
0ca670e6dc
2 changed files with 26 additions and 0 deletions
|
|
@ -40,6 +40,8 @@ import { Snapshot } from "../../snapshot"
|
|||
import { makeLocationNode } from "../../effect/app-node"
|
||||
import { llmClient } from "../../effect/app-node-platform"
|
||||
|
||||
const MAX_OUTPUT_TOKENS = 32_000
|
||||
|
||||
/**
|
||||
* Runs one durable coding-agent Session until it settles.
|
||||
*
|
||||
|
|
@ -210,6 +212,9 @@ const layer = Layer.effect(
|
|||
.map(SystemPart.make),
|
||||
messages: [...toLLMMessages(context, model), ...(isLastStep ? [Message.assistant(MAX_STEPS_PROMPT)] : [])],
|
||||
tools: toolMaterialization?.definitions ?? [],
|
||||
generation: {
|
||||
maxTokens: Math.min(model.route.defaults.limits?.output ?? 0, MAX_OUTPUT_TOKENS) || MAX_OUTPUT_TOKENS,
|
||||
},
|
||||
toolChoice: isLastStep ? "none" : undefined,
|
||||
})
|
||||
if (yield* compaction.compactIfNeeded({ sessionID: session.id, entries, model, request }))
|
||||
|
|
|
|||
|
|
@ -108,6 +108,11 @@ const recoveryModel = Model.make({
|
|||
provider: "fake",
|
||||
route: OpenAIChat.route.with({ limits: { context: 20_000, output: 1_000 } }),
|
||||
})
|
||||
const fullContextOutputModel = Model.make({
|
||||
id: "full-context-output",
|
||||
provider: "fake",
|
||||
route: OpenAIChat.route.with({ limits: { context: 500_000, output: 500_000 } }),
|
||||
})
|
||||
const authorizations: Tool.Context[] = []
|
||||
const executions: string[] = []
|
||||
const permission = Layer.succeed(
|
||||
|
|
@ -655,6 +660,22 @@ describe("SessionRunnerLLM", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("caps output when the catalog output limit consumes the full context window", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* setup
|
||||
const session = yield* SessionV2.Service
|
||||
currentModel = fullContextOutputModel
|
||||
yield* session.prompt({ sessionID, prompt: Prompt.make({ text: "hi" }), resume: false })
|
||||
requests.length = 0
|
||||
response = []
|
||||
|
||||
yield* session.resume(sessionID)
|
||||
|
||||
expect(requests).toHaveLength(1)
|
||||
expect(requests[0]?.generation).toEqual({ maxTokens: 32_000 })
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("retries the first provider turn after system context becomes available", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* setup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue