Skip to content

Commit e6be85c

Browse files
committed
test(bedrock): prove inferenceConfig.maxTokens reaches SDK for adaptive and Fable 5 via streamSimpleBedrock
1 parent 563c924 commit e6be85c

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

‎extensions/amazon-bedrock/stream.runtime.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,31 @@ describe("Bedrock Fable contract", () => {
512512

513513
expect(activityCount).toBeGreaterThan(0);
514514
});
515+
516+
it("sends model.maxTokens via streamSimpleBedrock for Fable 5", async () => {
517+
const send = vi.spyOn(BedrockRuntimeClient.prototype, "send").mockResolvedValue({
518+
$metadata: { httpStatusCode: 200 },
519+
stream: streamEvents([
520+
{ messageStart: { role: ConversationRole.ASSISTANT } },
521+
{ messageStop: { stopReason: "end_turn" } },
522+
]),
523+
} as never);
524+
const model = fableModel(); // maxTokens: 128000
525+
526+
await streamSimpleBedrock(model, context(), {
527+
reasoning: "high",
528+
temperature: 0.2,
529+
}).result();
530+
531+
const command = send.mock.calls[0]?.[0] as { input?: Record<string, unknown> };
532+
const maxTokens = (command.input?.inferenceConfig as Record<string, unknown>)
533+
?.maxTokens as number;
534+
535+
// Before fix: 4096 (options.maxTokens default, model.maxTokens ignored).
536+
// After fix: 128000 from model.maxTokens via adjustMaxTokensForThinking.
537+
expect(maxTokens).toBe(128_000);
538+
expect(maxTokens).toBeGreaterThan(4096);
539+
});
515540
});
516541

517542
describe("Bedrock canonical Claude aliases", () => {
@@ -570,6 +595,44 @@ describe("Bedrock canonical Claude aliases", () => {
570595
output_config: { effort: expectedEffort },
571596
},
572597
});
598+
// Adaptive-thinking path must populate inferenceConfig.maxTokens
599+
// from model.maxTokens (via adjustMaxTokensForThinking) instead of
600+
// leaving the legacy 4096 default.
601+
const maxTokens = (command.input?.inferenceConfig as Record<string, unknown>)
602+
?.maxTokens as number;
603+
expect(maxTokens).toBeGreaterThan(0);
573604
},
574605
);
606+
607+
it("sends model.maxTokens in inferenceConfig for high-context adaptive models", async () => {
608+
const send = vi.spyOn(BedrockRuntimeClient.prototype, "send").mockResolvedValue({
609+
$metadata: { httpStatusCode: 200 },
610+
stream: streamEvents([
611+
{ messageStart: { role: ConversationRole.ASSISTANT } },
612+
{ messageStop: { stopReason: "end_turn" } },
613+
]),
614+
} as never);
615+
const model = bedrockModel({
616+
id: "us.anthropic.claude-opus-4-8",
617+
name: "Claude Opus 4.8",
618+
maxTokens: 200_000,
619+
contextWindow: 1_000_000,
620+
});
621+
622+
await streamSimpleBedrock(
623+
model,
624+
{ messages: [{ role: "user", content: "Reply briefly.", timestamp: 0 }] } as never,
625+
{ reasoning: "high", temperature: 0.2 },
626+
).result();
627+
628+
const command = send.mock.calls[0]?.[0] as { input?: Record<string, unknown> };
629+
const maxTokens = (command.input?.inferenceConfig as Record<string, unknown>)
630+
?.maxTokens as number;
631+
632+
// Before fix: this was 4096 (options.maxTokens default).
633+
// After fix: adjustMaxTokensForThinking uses model.maxTokens (200000)
634+
// when no explicit caller cap is set.
635+
expect(maxTokens).toBe(200_000);
636+
expect(maxTokens).toBeGreaterThan(4096);
637+
});
575638
});

0 commit comments

Comments
 (0)