Skip to content

Commit

Permalink
fix: Crash in argument parsing when using Openrouter (#5667)
Browse files Browse the repository at this point in the history
## Why are these changes needed?
See issue for a bug description.
The problem was that a lot of openrouter models return `""` as
`tool_call.arguments`, which caused `json.loads` to fail
## Related issue number
#5666
---------

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
  • Loading branch information
philippHorn and ekzhu authored Feb 24, 2025
1 parent 170b8cc commit 95585b4
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ async def _execute_tool_call(
tool = next((t for t in self._tools + self._handoff_tools if t.name == tool_call.name), None)
if tool is None:
raise ValueError(f"The tool '{tool_call.name}' is not available.")
arguments = json.loads(tool_call.arguments)
arguments: Dict[str, Any] = json.loads(tool_call.arguments) if tool_call.arguments else {}
result = await tool.run_json(arguments, cancellation_token)
result_as_str = tool.return_value_as_string(result)
return (tool_call, FunctionExecutionResult(content=result_as_str, call_id=tool_call.id, is_error=False))
Expand Down

0 comments on commit 95585b4

Please sign in to comment.