fix(aws): flatten tool blocks when toolConfig is omitted#5850
Open
u9g wants to merge 3 commits into
Open
Conversation
AWS Bedrock's Converse API rejects requests with ValidationException when messages contain toolUse/toolResult blocks but toolConfig is missing. Previously, tool_choice="none" caused _get_tool_config() to return None entirely, breaking any draining agent handoff that returned (NewAgent, str) (issue #5589). Bedrock has no native "none" choice (only auto/any/tool), so emit toolConfig.tools and let toolChoice default to auto. Upstream filter in voice/generation.py:545 already discards any tool calls the model emits when tool_choice="none".
`if self._tool_call_id is None` was nested inside `if self._tool_call_id:`, so the inner branch could never run.
f13e395 to
b163c02
Compare
theomonnom
approved these changes
May 26, 2026
When tool_choice="none" (or tools is empty) but chat history contains toolUse/toolResult blocks, Bedrock Converse rejects the request because toolConfig is required whenever tool blocks appear in messages. Switch to the langchain-aws approach (PR #595): drop toolConfig entirely and rewrite tool blocks as plain text. The model genuinely cannot call a tool (no tools list is sent) but still sees what happened on prior turns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValidationExceptionwhentool_choice=\"none\"is requested while the chat context containstoolUse/toolResultblocks.if self._tool_call_id is Nonebranch in_parse_chunk.Root cause
Bedrock Converse's
ToolChoiceunion only acceptsauto/any/tool— there is nonone. Two facts collide:To request "no tools this turn," we'd want to omit
toolConfigentirely.Bedrock rejects any request whose
messagescontaintoolUseortoolResultblocks unlesstoolConfigis also present:This bites every agent handoff that returns
(NewAgent(), \"string\"): the draining old agent is forced to generate the string reply withtool_choice=\"none\"while the just-completed tool call/result blocks are still in chat history.Fix
Follow the approach landed in langchain-ai/langchain-aws#595: when
toolConfigis going to be omitted (either becausetool_choice=\"none\"or because no tools are provided), rewrite anytoolUse/toolResultcontent blocks in the outgoing messages as plain text ([Called <name> with <args>],[Tool output: ...]). Bedrock no longer sees structured tool blocks, so the validation error disappears, and because notoolslist is sent the model genuinely cannot call a tool — no reliance on downstream filtering to suppress unwanted tool calls.Test plan
basic_agentexample with an(Agent, str)handoff tool againstus.anthropic.claude-sonnet-4-6; pre-fix request fails withValidationException, post-fix the handoff completes cleanly._flatten_tool_blocksconfirmstoolUseandtoolResultblocks are rewritten totextblocks while plain-text content passes through unchanged.