Skip to content

fix(ai): merge Bedrock tool result messages - #41780

Merged
kitlangton merged 2 commits into
v2from
bedrock-tool-results
Aug 11, 2026
Merged

kitlangton merged 2 commits into
v2from
bedrock-tool-results

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Merge adjacent canonical user and tool-result content when lowering requests for Bedrock Converse. This keeps every result for a parallel assistant tool-use response in the single immediately following Bedrock user message required by the provider.

Closes #41445

Before / After

Before: One assistant response with two parallel tool calls lowered as assistant(toolUse x2), user(toolResult 1), user(toolResult 2). A live request against Amazon Nova Micro returned HTTP 400: Expected toolResult blocks at messages.2.content for the following Ids: weather_london.

After: The same canonical history lowers as assistant(toolUse x2), user(toolResult 1, toolResult 2). The recorded live request returned HTTP 200 and the model continued with the requested answer, Paris is sunny; London is rainy.

How

  • packages/ai/src/protocols/bedrock-converse.ts appends lowered canonical user and tool content to an immediately preceding Bedrock user message.
  • packages/ai/test/provider/bedrock-converse.test.ts covers the lowered wire shape and replays a real Bedrock continuation after two parallel tool results.
  • packages/ai/test/fixtures/recordings/bedrock-converse/continues-after-parallel-tool-results.json contains the redacted HTTP 200 Bedrock exchange.

Scope

This only changes Bedrock Converse message lowering. It does not change canonical message construction or lowering for other providers.

Testing

  • Live before-fix reproduction at parent commit 964f7f4254: Bedrock HTTP 400 identifying the missing second tool result in messages.2.content.
  • Live after-fix recording with RECORD=true RECORDED_TEST="continues after parallel tool results" bun run test test/provider/bedrock-converse.test.ts: Bedrock HTTP 200 and exact final answer.
  • Replay with bun run test test/provider/bedrock-converse.test.ts: 44 pass, 0 fail.
  • bun typecheck from packages/ai: passes.
  • Prettier and git diff --check: pass.
  • Push hook bun turbo typecheck --concurrency=3: 33 tasks pass.

@kitlangton
kitlangton marked this pull request as ready for review August 11, 2026 17:03
@kitlangton
kitlangton merged commit 37a8c6c into v2 Aug 11, 2026
10 checks passed
@kitlangton
kitlangton deleted the bedrock-tool-results branch August 11, 2026 17:03
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant