fix(ai): omit empty Anthropic system blocks (#46289)

This commit is contained in:
Aiden Cline 2026-08-30 14:21:05 -05:00 committed by GitHub
parent 68c1207b52
commit 583a1a2b6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View file

@ -1019,10 +1019,11 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
)
// Anthropic rejects tool_choice when tools are absent; "none" is only meaningful with tools present.
const toolChoice = tools === undefined || !request.toolChoice ? undefined : yield* lowerToolChoice(request.toolChoice)
const systemParts = request.system.filter((part) => part.text.length > 0)
const system =
request.system.length === 0
systemParts.length === 0
? undefined
: request.system.map((part) => ({
: systemParts.map((part) => ({
type: "text" as const,
text: part.text,
cache_control: cacheControl(breakpoints, part.cache),

View file

@ -74,6 +74,16 @@ describe("Anthropic Messages route", () => {
}),
)
it.effect("omits empty system text while preserving whitespace", () =>
Effect.gen(function* () {
const empty = yield* compileRequest(LLMRequest.update(request, { system: [{ type: "text", text: "" }] }))
const whitespace = yield* compileRequest(LLMRequest.update(request, { system: [{ type: "text", text: " " }] }))
expect(empty.body.system).toBeUndefined()
expect(whitespace.body.system).toEqual([{ type: "text", text: " " }])
}),
)
it.effect("lowers adaptive thinking settings with effort", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(