fix: correct Bedrock tool call argument extraction field name#4855
fix: correct Bedrock tool call argument extraction field name#4855alvinttang wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
The default value '"{}"' in func_info.get('arguments', '{}') is a truthy
string, preventing the 'or' operator from falling through to Bedrock's
'input' field. This causes all Bedrock tool calls to receive empty arguments.
Fix by using None as the default (no second arg to .get()), matching the
existing correct pattern in agent_utils.py.
Fixes crewAIInc#4748
alvinttang
left a comment
There was a problem hiding this comment.
Review
This is a one-line fix changing func_info.get("arguments", "{}") or tool_call.get("input", {}) to func_info.get("arguments") or tool_call.get("input") or {}.
Analysis:
-
The bug: With the old code, if
func_info["arguments"]is""(empty string) orNone, theget("arguments", "{}")returns that falsy value, thenorfalls through totool_call.get("input", {}). But crucially, iffunc_infohas"arguments": ""the get returns""which is falsy, so it falls through correctly. The real issue is likely with Bedrock's response format — looking at the field name in the title: "correct Bedrock tool call argument extraction field name".Actually, re-reading: the old default
"{}"(a string) vs{}(a dict) is the real problem. Iffunc_infohas no"arguments"key ANDtool_callhas no"input"key, the old code returns"{}"(a JSON string), not{}(a dict). Downstream code that tries to dofunc_args.get(...)or iterate overfunc_argsas a dict would crash on the string"{}". -
The fix: By removing the defaults from
get()and using a chainedor {}, the fallback is always a proper dict{}. This is correct. -
However — missing
json.loads: Iffunc_info.get("arguments")returns a JSON string (which is common — many LLM APIs return tool arguments as a JSON string, not a parsed dict), thenfunc_argswill be a string. The code downstream presumably needs a dict. Is there ajson.loadscall somewhere downstream, or does this function's caller handle string-to-dict conversion? If not, this fix solves one case (missing arguments) but may still fail when arguments are present as a string. Worth verifying the downstream handling. -
No test: A test case with Bedrock-style tool call responses (both with and without arguments) would help.
The fix is directionally correct. Small concern about whether string arguments are handled downstream.
Summary
Fixes #4748
crew_agent_executor.pyline 850,func_info.get("arguments", "{}")returns the truthy string"{}"when the key is absent, preventing theoroperator from ever falling through to Bedrock'sinputfield. This causes all AWS Bedrock tool calls to receive empty arguments{}.func_info.get("arguments")(returningNonewhen absent) so theorcorrectly falls through totool_call.get("input"). This matches the already-correct pattern inagent_utils.pyline 1157.Change
Why this works
tool_callis an OpenAI-format dict withfunction.arguments,func_info.get("arguments")returns the arguments (truthy), so it is used directly.tool_callis a Bedrock-format dict withinput,func_info.get("arguments")returnsNone(falsy), so theorfalls through totool_call.get("input")which returns the Bedrock arguments.or {}provides a safe empty-dict default if neither field is present.Test plan
function.arguments)inputfieldpytest lib/crewai/tests/agents/test_native_tool_calling.pyNote
Low Risk
Low risk, one-line change in native tool-call parsing to fix argument extraction for Bedrock-formatted tool calls; limited to how tool call payloads are interpreted.
Overview
Fixes native tool-call argument extraction in
CrewAgentExecutor._parse_native_tool_callby removing the default"{}"fallback forfunction.arguments, allowing the logic to correctly fall through to Bedrock’sinputfield (and finally{}) whenargumentsis missing.Written by Cursor Bugbot for commit 1348672. This will update automatically on new commits. Configure here.