Skip to content

fix: Bedrock Converse API tool arguments silently dropped (#4972)#4978

Open
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
guoyangzhen:fix-bedrock-tool-arguments
Open

fix: Bedrock Converse API tool arguments silently dropped (#4972)#4978
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
guoyangzhen:fix-bedrock-tool-arguments

Conversation

@guoyangzhen
Copy link

Problem

When using AWS Bedrock with native function calling, all tool arguments are silently dropped. Every tool call receives an empty dict {} instead of the actual arguments, causing pydantic validation failures on any tool with required parameters.

This affects ALL Bedrock models using native function calling (Claude, Llama, etc.) via the native tool loop code path.

Root Cause

In _parse_native_tool_call (crew_agent_executor.py), the dict-format branch has a truthy default:

func_args = func_info.get("arguments", "{}") or tool_call.get("input", {})

Bedrock Converse API returns {name, input, toolUseId}no "function" key.

So func_info is {}, and func_info.get("arguments", "{}") returns the default "{}" — a truthy string. The or short-circuits and tool_call.get("input", {}) is never evaluated.

Fix

Remove the default so get() returns None (falsy), allowing the or to fall through:

func_args = func_info.get("arguments") or tool_call.get("input") or "{}"

Verification

Bedrock format: {"name": "search_tool", "input": {"search_query": "hello"}, "toolUseId": "abc"}
OLD: func_info.get("arguments", "{}") → "{}" (truthy!) → short-circuits → broken
NEW: func_info.get("arguments") → None (falsy) → falls through to tool_call["input"] ✓

OpenAI format: {"function": {"name": "t", "arguments": "{"x": 1}"}}
NEW: func_info.get("arguments") → "{"x": 1}" (truthy) → same as before ✓

Tests Added

  • test_parse_native_tool_call_bedrock_format — verifies Bedrock input dict is correctly extracted
  • test_parse_native_tool_call_openai_dict_format — verifies OpenAI format still works

Fixes #4972

…4972)

When using AWS Bedrock with native function calling, all tool arguments
were silently dropped because of a truthy default in dict.get().

The bug: func_info.get('arguments', '{}') returns '{}' (truthy string)
when the 'function' key is absent (Bedrock format), so the fallback
or tool_call.get('input', {}) is never evaluated.

The fix: remove the default so get() returns None (falsy), allowing
the 'or' to correctly fall through to tool_call.get('input').

    # Before (broken):
    func_args = func_info.get('arguments', '{}') or tool_call.get('input', {})
    # After (fixed):
    func_args = func_info.get('arguments') or tool_call.get('input') or '{}'

Bedrock Converse API returns: {name, input, toolUseId} (no 'function' key).
OpenAI returns: {function: {name, arguments}} (has 'function' key).

Both formats are now correctly handled.

Fixes crewAIInc#4972
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.

[BUG] _parse_native_tool_call drops Bedrock Converse API tool arguments — always passes empty dict

1 participant