diff --git a/src/google/adk/tools/function_tool.py b/src/google/adk/tools/function_tool.py index 30c1a11..3a168fb 100644 --- a/src/google/adk/tools/function_tool.py +++ b/src/google/adk/tools/function_tool.py @@ -107,9 +107,9 @@ You could retry calling this tool, but it is IMPORTANT for you to provide all th or hasattr(self.func, '__call__') and inspect.iscoroutinefunction(self.func.__call__) ): - return await self.func(**args_to_call) or {} + return await self.func(**args_to_call) else: - return self.func(**args_to_call) or {} + return self.func(**args_to_call) # TODO(hangfei): fix call live for function stream. async def _call_live( diff --git a/tests/unittests/tools/test_function_tool.py b/tests/unittests/tools/test_function_tool.py index 26f37e6..7f04b27 100644 --- a/tests/unittests/tools/test_function_tool.py +++ b/tests/unittests/tools/test_function_tool.py @@ -86,6 +86,16 @@ def function_for_testing_with_4_arg_and_no_tool_context(arg1, arg2, arg3, arg4): pass +def function_returning_none() -> None: + """Function for testing with no return value.""" + return None + + +def function_returning_empty_dict() -> dict[str, str]: + """Function for testing with empty dict return value.""" + return {} + + def test_init(): """Test that the FunctionTool is initialized correctly.""" tool = FunctionTool(function_for_testing_with_no_args) @@ -94,6 +104,20 @@ def test_init(): assert tool.func == function_for_testing_with_no_args +def test_function_returning_none(): + """Test that the function returns with None actually returning None.""" + tool = FunctionTool(function_returning_none) + result = await tool.run_async(args={}, tool_context=MagicMock()) + assert result is None + + +def test_function_returning_empty_dict(): + """Test that the function returns with empty dict actually returning empty dict.""" + tool = FunctionTool(function_returning_empty_dict) + result = await tool.run_async(args={}, tool_context=MagicMock()) + assert isinstance(result, dict) + + @pytest.mark.asyncio async def test_run_async_with_tool_context_async_func(): """Test that run_async calls the function with tool_context when tool_context is in signature (async function)."""