Skip to content

fix(aws): keep toolConfig when tool_choice="none" to prevent ValidationException#5595

Open
weiguangli-io wants to merge 1 commit intolivekit:mainfrom
weiguangli-io:fix/bedrock-tool-choice-none-5589
Open

fix(aws): keep toolConfig when tool_choice="none" to prevent ValidationException#5595
weiguangli-io wants to merge 1 commit intolivekit:mainfrom
weiguangli-io:fix/bedrock-tool-choice-none-5589

Conversation

@weiguangli-io
Copy link
Copy Markdown
Contributor

Summary

Fixes #5589.

When tool_choice="none" is passed to the AWS Bedrock LLM plugin (e.g. during agent handoff when draining=True), _get_tool_config() was hitting the else: return None branch, causing toolConfig to be omitted entirely from the ConverseStream request. AWS raises ValidationException when toolUse/toolResult content blocks exist in the message history but toolConfig is absent.

Root cause: The else: return None branch handled any unrecognized tool_choice value by removing tool config entirely. The string "none" is a valid ToolChoice value meaning "don't force tool use", but AWS has no equivalent toolChoice field value — the correct behavior is to include toolConfig (with the tools list) but omit the toolChoice constraint, which lets Bedrock default to its auto behavior.

Fix: Remove the else: return None branch so tool_choice="none" falls through without setting toolConfig["toolChoice"], keeping the tools config intact.

Changes

  • livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/llm.py: removed else: return None in _get_tool_config(), replaced with a comment explaining the intent for tool_choice="none"

Test plan

  • Trigger an agent handoff where a tool returns both an agent object and a string result — the old agent should successfully generate its reply without ValidationException
  • Call session.generate_reply(tool_choice=None) when the chat context contains tool call/result messages — should succeed
  • Verify existing behavior: tool_choice="auto", tool_choice="required", and named tool choice still work correctly
  • Verify no-tools scenario still returns None from _get_tool_config() correctly

🤖 Generated with Claude Code

…onException

When tool_choice="none" is passed (e.g. during agent handoff draining),
_get_tool_config() was returning None, causing toolConfig to be omitted
from the Bedrock ConverseStream request. AWS raises ValidationException
when toolUse/toolResult content blocks are present but toolConfig is absent.

Fix by removing the else-return-None branch so that tool_choice="none"
falls through without setting toolChoice, keeping the toolConfig with
the tools list intact.

Fixes livekit#5589

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS Bedrock LLM Plugin raises ValidationException when tool_choice=None

1 participant