Skip to content

fix(ai-amazon-bedrock): strip thinking from additionalModelRequestFields when using generateObject#6206

Open
Zelys-DFKH wants to merge 1 commit intoEffect-TS:mainfrom
Zelys-DFKH:fix/bedrock-strip-thinking-on-generate-object
Open

fix(ai-amazon-bedrock): strip thinking from additionalModelRequestFields when using generateObject#6206
Zelys-DFKH wants to merge 1 commit intoEffect-TS:mainfrom
Zelys-DFKH:fix/bedrock-strip-thinking-on-generate-object

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Type

  • Bug Fix

Description

generateObject fails with "Thinking may not be enabled when tool_choice forces tool use" when extended thinking is configured via withConfigOverride. This affects both direct generateObject calls and the common case where a parent generateText propagates the Config service (via Effect.provideService) into a tool handler that internally calls generateObject.

Root cause

makeRequest builds the Bedrock request by spreading ...config first, which puts additionalModelRequestFields.thinking into the request object. The additionalModelRequestFields override at the end of the request object only fires when additionalTools is present. When additionalTools is undefined (the usual case), nothing overwrites the thinking key that ...config already placed, and the request is rejected.

Fix

Pre-compute requestAdditionalFields before the request object. In the json path (generateObject), merge config.additionalModelRequestFields with additionalTools and strip thinking. Return an explicit object even when empty so the final spread overwrites whatever ...config put in the request. When no additional fields are configured at all, return undefined to avoid injecting an empty object.

Tests

Adds packages/ai/amazon-bedrock/test/AmazonBedrockLanguageModel.test.ts with four cases:

  • thinking is stripped for generateObject (forced toolChoice) and toolChoice.tool is set correctly
  • thinking is preserved for generateText (no forced toolChoice)
  • No additionalModelRequestFields is set when none was configured and generateObject is used
  • Non-thinking fields survive alongside thinking being stripped from a mixed additionalModelRequestFields

Note: PR #6160 is also open and adds AmazonBedrockLanguageModel.test.ts (token usage in streaming). If that merges first, the two files can be merged with no conflicts - the describe blocks cover unrelated behavior.

Related

@Zelys-DFKH Zelys-DFKH requested a review from IMax153 as a code owner May 2, 2026 19:40
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog May 2, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 2, 2026

🦋 Changeset detected

Latest commit: 763ad9b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/ai-amazon-bedrock Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

@effect/ai-amazon-bedrock: withConfigOverride thinking config leaks into tool call handlers, breaking generateObject

1 participant